Select EdgeProxy from Subassembly

Select EdgeProxy from Subassembly

Hubert_Los
Advocate Advocate
365 Views
2 Replies
Message 1 of 3

Select EdgeProxy from Subassembly

Hubert_Los
Advocate
Advocate

Hello,

 

I can' select edgeproxy from subassmelby. I need it to make constraint. Anyone know why I can't do it?

 

 

 

Public Sub SelectEdgeFromSub()


    Dim oAsmCompDef As AssemblyComponentDefinition
    Set oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
    
    Dim oComponentOccurrence As ComponentOccurrence
    Set oComponentOccurrence = ThisApplication.CommandManager.Pick(kAssemblyOccurrenceFilter, "Wybierz element, który chcesz zwiazac")
    Dim oSubAssembly As ComponentOccurrence
    Set oSubAssembly = oComponentOccurrence.Definition.Occurrences.Item(1)
    
    Dim oSurfaceBody As SurfaceBody
    Set oSurfaceBody = oSubAssembly.Definition.SurfaceBodies.Item(1)
    
    Dim oEdge As Edge
    Set oEdge = oSurfaceBody.Edges.Item(1)

    Dim oEdgeProxy1 As EdgeProxy
    Call oSubAssembly.CreateGeometryProxy(oEdge, oEdgeProxy1)

    Dim oSelectSet As SelectSet
    Set oSelectSet = ThisApplication.ActiveDocument.SelectSet
    Call oSelectSet.Select(oEdgeProxy1) 'error


End Sub

 

0 Likes
Accepted solutions (1)
366 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor

Hi @Hubert_Los.  You need to go another step with your code.  You are getting the EdgeProxy in the context of the 'Picked' component, not in the context of the top level assembly.  Proxy's work on a per level basis.  Each time you get 'create' a proxy, the proxy that is created is at its 'parent' level, not necessarily at top level.  So, when the edge is multiple levels deep, you will need to get the proxy multiple times, using each parent component as the basis to get the proxy in its parent context.  So, you need to now use the Picked component's CreateGeometryProxy to get the proxy at its parent level context.  If that Picked component was not a top level component, then you will need to get the component that represents its parent sub assembly, and use that again.

Edit:  And by the way...if you were to 'Pick' the edge directly, that Picked edge would already be the top level EdgeProxy, so you would not have to go through that process.  Just one advantage of the Pick function, but using Pick includes 'manual' user interaction, which we are usually trying to avoid in our automations.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 3

WCrihfield
Mentor
Mentor
Accepted solution

Give this version of your code a try:

Public Sub SelectEdgeFromSub()
    If ThisApplication.ActiveDocumentType <> kAssemblyDocumentObject Then Exit Sub
    Dim oAsmDoc As AssemblyDocument
    Set oAsmDoc = ThisApplication.ActiveDocument
    
    Dim oComponentOccurrence As ComponentOccurrence
    Set oComponentOccurrence = ThisApplication.CommandManager.Pick(kAssemblyOccurrenceFilter, "Wybierz element, który chcesz zwiazac")
    Dim oSubAssembly As ComponentOccurrence
    Set oSubAssembly = oComponentOccurrence.Definition.Occurrences.Item(1)
    
    Dim oSurfaceBody As SurfaceBody
    Set oSurfaceBody = oSubAssembly.Definition.SurfaceBodies.Item(1)
    
    Dim oEdge As Edge
    Set oEdge = oSurfaceBody.Edges.Item(1)

    Dim oEdgeProxy1 As EdgeProxy
    Call oSubAssembly.CreateGeometryProxy(oEdge, oEdgeProxy1)
    
    Dim oEdgeProxy2 As EdgeProxy
    Call oComponentOccurrence.CreateGeometryProxy(oEdgeProxy1, oEdgeProxy2)

    Dim oSelectSet As SelectSet
    Set oSelectSet = oAsmDoc.SelectSet
    Call oSelectSet.Select(oEdgeProxy2)
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes