neshom
Mechanical
- Feb 7, 2016
- 43
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):
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?
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?