AnsweredAssumed Answered

Retrieve PartDoc from selected entity in drawing

Question asked by Alexandre Gragnano on May 13, 2020
Latest reply on Jun 9, 2020 by Alexandre Gragnano

Hello,

In a drawing context, I would like to select a temporary axis of a weldment cutlist body and draw some entities over using some custom properties as parameters.

So, to retrieve the body from the selected temporary axis, I use:

 

Sub main()
   
    Dim app As SldWorks.SldWorks
    Dim doc As SldWorks.ModelDoc2
    Dim selmgr As SldWorks.SelectionMgr
    Dim selcount As Integer
    Dim i As Integer
    Dim seltype As Long
    Dim feat As SldWorks.Feature
    Dim axis As SldWorks.RefAxis
    Dim face As SldWorks.Face2
    Dim body As SldWorks.Body2
   
    Set app = Application.SldWorks
    If app Is Nothing Then Exit Sub
    Set doc = app.ActiveDoc
    If doc Is Nothing Then Exit Sub
    Set selmgr = doc.SelectionManager
    If selmgr Is Nothing Then Exit Sub
    selcount = selmgr.GetSelectedObjectCount2(-1)
    If selcount = 0 Then Exit Sub
   
    For i = 1 To selcount
        seltype = selmgr.GetSelectedObjectType3(i, -1)
        If seltype <> SwConst.swSelectType_e.swSelDATUMAXES Then GoTo Next_i
        Set feat = selmgr.GetSelectedObject6(i, -1)
        If feat Is Nothing Then GoTo Next_i
        Set axis = feat.GetSpecificFeature2
        If axis Is Nothing Then GoTo Next_i
        If axis.IsTempAxis = False Then GoTo Next_i
        Set face = axis.GetTempAxisReferenceFace
        If face Is Nothing Then GoTo Next_i
        Set body = face.GetBody
        If body Is Nothing Then GoTo Next_i
        Debug.Print body.name
Next_i:
    Next i
   
End Sub

 

After this, I know how to find CutList folder containing this body.

But between, I need to know from which part/config this body come from.

Some advice will be welcome.

Outcomes