SeanF
Mechanical
- Nov 26, 2002
- 26
I would like to check to see if an object selected is a component or a sub-asm via the API. I am having no luck. Things I think should work don't seem to. The following is really annoying:
retval = Component2.GetChildren ()
If this assembly component is a part document, SolidWorks returns NULL. If this assembly component is the root component or a subassembly, then this method returns the child components that belong to the assembly document.
' Get the selection manager class
Set SelMgr = Part.SelectionManager()
' Get the first item in the selection list
Set selObj = SelMgr.GetSelectedObject(1)
RetVal = selObj.GetChildren()
MyBool = IsNull(RetVal)
If MyBool = True Then
PrA2 = "A"
Else
PrA2 = "P"
End If
Sadly, the ret is NOT null if a component is selected. I have been trying to use this to determine if asm or component is selected. RetVal is declared as Variant(btw) at any rate, I don't get a NULL ret if a component is selected. I DO however, get a var array of the children if selected is asm.
I am stumped. Is the ret from SldWks not correct? Or am I not testing the value properly?
I am writing a macro to mate the def 3 planes. However, my planes are named different for asm's and parts. A_TOP and P_TOP respectivly. So, I need to determine if I have selected a part or asm when I run this macro as I have to use different names depending on the selection.
*sigh*
And it's only Monday....
TIA!
Sean F
Mechanical Engineer
seanf@newing-halll.com
1 2 many l's in e-mail
retval = Component2.GetChildren ()
If this assembly component is a part document, SolidWorks returns NULL. If this assembly component is the root component or a subassembly, then this method returns the child components that belong to the assembly document.
' Get the selection manager class
Set SelMgr = Part.SelectionManager()
' Get the first item in the selection list
Set selObj = SelMgr.GetSelectedObject(1)
RetVal = selObj.GetChildren()
MyBool = IsNull(RetVal)
If MyBool = True Then
PrA2 = "A"
Else
PrA2 = "P"
End If
Sadly, the ret is NOT null if a component is selected. I have been trying to use this to determine if asm or component is selected. RetVal is declared as Variant(btw) at any rate, I don't get a NULL ret if a component is selected. I DO however, get a var array of the children if selected is asm.
I am stumped. Is the ret from SldWks not correct? Or am I not testing the value properly?
I am writing a macro to mate the def 3 planes. However, my planes are named different for asm's and parts. A_TOP and P_TOP respectivly. So, I need to determine if I have selected a part or asm when I run this macro as I have to use different names depending on the selection.
*sigh*
And it's only Monday....
TIA!
Sean F
Mechanical Engineer
seanf@newing-halll.com
1 2 many l's in e-mail