The structure of my Document is as follows:
Part1
--- Annotations
--- Planes
--- Extrude1
I have used SelectionManager.GetSelectedObject6() method.
When I select the main Part/Assembly (Part1 in the above example) the Selection Manager returns an empty object.
How do I retrieve the main Part/Assembly?
The code I use is as below:
Sub GetSelectedObject( )
Dim swApplication As SldWorks.SldWorks
Dim swDoc As SldWorks.ModelDoc2
Dim swCurrSelMgr As SldWorks.SelectionMgr
Dim SelectedObject As Object
Dim seltype As Long
Set swApplication = GetObject(, "SldWorks.Application")
If swApplication Is Nothing Then
Exit Sub
End If
Set swDoc = swApplication.ActiveDoc
Set swCurrSelMgr = swDoc.SelectionManager
SelectedObjCount = swCurrSelMgr.GetSelectedObjectCount2(-1)
seltype = swCurrSelMgr.GetSelectedObjectType3(iterator, -1)
Set SelectedObject = swCurrSelMgr.GetSelectedObject6(1, -1)
If SelectedObject Is Nothing Then
MsgBox "Cannot select the Root Object.", vbExclamation
Exit Sub
End If
End Sub
This works fine if I select a feature/face in Part Document and a Part/Assembly in an Assembly Document.
The problem occurs when I select the Main Part/Assembly.
The "SelectedObject" is not valuated in this case. ie., the API "GetSelectedObject6" returns nothing.
Can you help me out?