Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change transparency of selected part that is loaded as lightweight

Status
Not open for further replies.

neshom

Mechanical
Feb 7, 2016
43
0
0
AU
Using Solidworks API (C#), I'd like to change the transparency of a lightweight part that is selected in an assembly. Here is the code that I am using up to where I get an error (last line):

Code:
	                 ModelDoc2 swModel = (ModelDoc2)swApp.ActiveDoc;

            SelectionMgr swSelectionMgr = (SelectionMgr)swModel.SelectionManager;
            int intSelectedObjectCount = swSelectionMgr.GetSelectedObjectCount2(-1);

            Component2 swComponent = (Component2)swSelectionMgr.GetSelectedObjectsComponent4(1, -1);

            ModelDoc2 swModelDoc2 = (ModelDoc2)swComponent.GetModelDoc();

If the part is not lightweight, all is good! But when the part is lightweight, the variable swModelDoc2 is null and the code does not continue after the last line above!

Do you know how I can solve this?
 
Replies continue below

Recommended for you

Are you trying to change transparency at the part level (all instances of the part change, and the part is transparent when you open in a window) or component level (just this one instance in the assembly changes)? If you want to change at the part level, I believe you'll have to set that component to resolved before you can get its ModelDoc2.

-handleman, CSWP (The new, easy test)
 
Status
Not open for further replies.
Back
Top