Using CommandManager.DoSelect on place constraint window doesn't move selection

Using CommandManager.DoSelect on place constraint window doesn't move selection

jdasilvaS39UQ
Advocate Advocate
338 Views
1 Reply
Message 1 of 2

Using CommandManager.DoSelect on place constraint window doesn't move selection

jdasilvaS39UQ
Advocate
Advocate

I'd like to launch the place constraint window and make contraint selections from an additional vba userform to select the first and second contraint selections.

I tried to use commandmanager.doselect(entity) to make my selection and it works fine for the first one but doesn't automatically move to #2 like it normally would when you are using the form. Does anyone know a way to activate the second selection button? Or is there another way to pass entities to the place constraint dialog?

0 Likes
339 Views
1 Reply
Reply (1)
Message 2 of 2

A.Acheson
Mentor
Mentor

It might be best to use the built in API methods for constraints. Using the command manager for constraints is a workaround method best reservered for when no API methods exist. Here is how to select a single object. You can adjust the SelectionFilterEnum to give a specific filter like "SelectionFilterEnum.kAssemblyLeafOccurrenceFilter"

 

Public Sub GetSingleSelection()
    ' Get a feature selection from the user
    Dim oObject As Object
    Set oObject = ThisApplication.CommandManager.Pick(kPartFeatureFilter, "Pick a feature")

    MsgBox "Picked: " & oObject.Name
End Sub

Here is a sample for mate constraints from the API help. Note selectset is a preselect method and is different than using command manager and pick. 

 

Public Sub MateConstraint()
    ' Set a reference to the assembly component definintion.
    Dim oAsmCompDef As AssemblyComponentDefinition
    Set oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

    ' Set a reference to the select set.
    Dim oSelectSet As SelectSet
    Set oSelectSet = ThisApplication.ActiveDocument.SelectSet

    ' Validate the correct data is in the select set.
    If oSelectSet.Count <> 2 Then
        MsgBox "You must select the two entities valid for mate."
        Exit Sub
    End If

    ' Get the two entities from the select set.
    Dim oBrepEnt1 As Object
    Dim oBrepEnt2 As Object
    Set oBrepEnt1 = oSelectSet.Item(1)
    Set oBrepEnt2 = oSelectSet.Item(2)

    ' Create the insert constraint between the parts.
    Dim oMate As MateConstraint
    Set oMate = oAsmCompDef.Constraints.AddMateConstraint(oBrepEnt1, oBrepEnt2, 0)
End Sub

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes