Put a constraint in a deleted state API

Hello

Already nice improvement of the forum, I see that it's evolving in the right direction here!

I have a request from a colleague who wants me to improve my macro that allows me to insert a component, the ' released ' put an origin/point coincidence and fix it.

Problem in some cases we have repositioning to do, so to make our life easier and gain a few ' clicks ' he asks me to put in state remove the constraint before fixing my part.

I did a lot of research and auto recording of macro but nothing came out. I can't select my constraint, nor put a constraint in a deleted state

'suppression du "Fixe" sur la première pièce
boolstatus = swModel.Extension.SelectByID2(CompInsert, "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)
swModel.UnfixComponent

'Selection du composant et ajout contrainte coincident origine/origine
swModel.ClearSelection2 True
boolstatus = swModel.Extension.SelectByID2(FirstSelection, "EXTSKETCHPOINT", 0, 0, 0, False, 1, Nothing, 0)
boolstatus = swModel.Extension.SelectByID2(SecondSelection, "COORDSYS", 0, 0, 0, True, 1, Nothing, 0)
Set swMate = swModel.AddMate5(20, -1, False, 0, 0.001, 0.001, 0.001, 0.001, 0.5235987755983, 0.5235987755983, 0.5235987755983, False, False, 0, longstatus)

'Remettre la pièce "Fixe"
boolstatus = swModel.Extension.SelectByID2(CompInsert, "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)
swModel.FixComponent
swModel.ClearSelection2 True

While waiting for your answers, I wish you all happy holidays.

Hello @mandragore
I think I'll have to go through the tree and get the corresponding Feature

Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim swAssembly As AssemblyDoc
Dim swswSelmgr As SelectionMgr
Dim swFeature As Feature
Dim swMate As Mate2
Sub main()

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swAssembly = swModel
Set swSelmgr = swModel.SelectionManager
Dim swError As Long
Set swMate = swAssembly.AddMate5(swMateType_e.swMateCOINCIDENT, swMateAlign_e.swAlignNONE, False, 0, 0, 0, 0, 0, 0, 0, 0, False, False, 0, swError)
swModel.ForceRebuild3 True
Set swFeature = GET_MATE_FEATURE()
swFeature.SetSuppression2 swFeatureSuppressionAction_e.swSuppressFeature, swInConfigurationOpts_e.swThisConfiguration, Nothing
End Sub

Function GET_MATE_FEATURE() As Feature
    Dim curentFeature As Feature
    Set curentFeature = swModel.FirstFeature
    Dim lastFeature As Feature
    Do While Not curentFeature Is Nothing
    If curentFeature.GetTypeName2() = "MateGroup" Then
        Dim subFeature As Feature
        Set subFeature = curentFeature.GetFirstSubFeature
        Set lastFeature = subFeature
        Do While Not subFeature Is Nothing
            Set lastFeature = subFeature
            Set subFeature = subFeature.GetNextSubFeature
        Loop
        Exit Do
    End If
    Set curentFeature = curentFeature.GetNextFeature()
    Loop
    Set GET_MATE_FEATURE = lastFeature
End Function

2 Likes

From the 2019 version, the Createmate function also allows you to make the standard constraints and returns the feature directly,

2 Likes