Assembly Browser selected constraint refers to feature

Assembly Browser selected constraint refers to feature

markus.schrepfer
Advocate Advocate
630 Views
4 Replies
Message 1 of 5

Assembly Browser selected constraint refers to feature

markus.schrepfer
Advocate
Advocate
Hi, I´m looking for a code snippet which will show the referenced Features (workfeature also partfeature) from a selected constraint in the assembly browser. Anyone an idea? I´ve searched serveral autodesk Blogs and wasn´t able to find any suitable solultion.
Markus Schrepfer
0 Likes
Accepted solutions (1)
631 Views
4 Replies
Replies (4)
Message 2 of 5

YuhanZhang
Autodesk
Autodesk

In assembly select an assembly constraint and run below VBA code to get the info:

 

Sub GetConstraintRefFeatureInfo()
    Dim oDoc As AssemblyDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    Dim oConstraint As AssemblyConstraint
    Set oConstraint = oDoc.SelectSet(1)
    
    Debug.Print "The constraint: " & oConstraint.Name
    Debug.Print "The 1st referenced feature is: " & oConstraint.OccurrenceOne.Name & "->" & GetRefFeatureName(oConstraint.EntityOne)
    Debug.Print "The 2nd referenced feature is: " & oConstraint.OccurrenceTwo.Name & "->" & GetRefFeatureName(oConstraint.EntityTwo)
End Sub

Function GetRefFeatureName(oEntityProxy As Object) As String
    Dim oNativeFeature As PartFeature
    If oEntityProxy.Type = kFaceProxyObject Or _
        oEntityProxy.Type = kEdgeProxyObject Then
        Set oNativeFeature = oEntityProxy.NativeObject.CreatedByFeature
        GetRefFeatureName = oNativeFeature.Name
    End If
End Function


If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

Message 3 of 5

markus.schrepfer
Advocate
Advocate
Hi, the code works! Unfortunately the referenced feature name will not be displayed. By Debugging the code I´ll get the name (oNativeFeature.Name) by hover the mouse. Here is my result form Immedaite Window: The constraint: Fluchtend:11 The 1st referenced feature is: TEST-Umlenkrolle-Ø106/95x710-25h6-MB500mm-*-ENG-0001625-:1-> The 2nd referenced feature is: TEST-Umlenkrolle_SKL-MB 500 mm-*-ENG-0000828-:1-> Is there the possibiltiy to select and highlight the two referenced features in the browser? This would be the best solution for the engineers.
Markus Schrepfer
0 Likes
Message 4 of 5

YuhanZhang
Autodesk
Autodesk
Accepted solution

The Debug.Print will print the result to the Immediate window(use Ctrl+G to show the window). Below is updated VBA code to highlight the features in top assembly for the assembly constraint:

 

Sub GetConstraintRefFeatureInfo()
    Dim oDoc As AssemblyDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    Dim oConstraint As AssemblyConstraint
    Set oConstraint = oDoc.SelectSet(1)
    oDoc.SelectSet.Clear
    
    Debug.Print "The constraint: " & oConstraint.Name
    Debug.Print "The 1st referenced feature is: " & oConstraint.OccurrenceOne.Name & "->" & GetRefFeatureName(oConstraint.EntityOne, oDoc)
    Debug.Print "The 2nd referenced feature is: " & oConstraint.OccurrenceTwo.Name & "->" & GetRefFeatureName(oConstraint.EntityTwo, oDoc)
End Sub

Function GetRefFeatureName(oEntityProxy As Object, oTopDoc As AssemblyDocument) As String
    Dim oNativeFeature As PartFeature
    Dim oOccu As ComponentOccurrence
    
    If oEntityProxy.Type = kFaceProxyObject Or _
        oEntityProxy.Type = kEdgeProxyObject Then
        Set oOccu = oEntityProxy.ContainingOccurrence
        Set oNativeFeature = oEntityProxy.NativeObject.CreatedByFeature
        
        Call HighlightFeatureInTopDoc(oNativeFeature, oTopDoc, oOccu)
        
        GetRefFeatureName = oNativeFeature.Name
    End If
End Function

Sub HighlightFeatureInTopDoc(oFeature As PartFeature, oDoc As AssemblyDocument, oOccu As ComponentOccurrence)
    Dim oFeaProxy As PartFeature
    
    
    Dim bStop As Boolean
    bStop = False
    
    Do
        oOccu.CreateGeometryProxy oFeature, oFeaProxy
        Set oFeature = oFeaProxy
        If oOccu.ParentOccurrence Is Nothing Then
            bStop = True
        Else
            Set oOccu = oOccu.ParentOccurrence
        End If
    Loop Until bStop
    
    oDoc.SelectSet.Select oFeaProxy
End Sub

Hope it helps.

 



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 5 of 5

markus.schrepfer
Advocate
Advocate
Hi, for the moment, it looks good. I will test and Review with our key users. Thank you for supporting this issue!!! may be, I´ll come back when the tests are done.
Markus Schrepfer
0 Likes