Catia V5 Macro - Delete all Constraints and Fix Components

Catia V5 Macro - Delete all Constraints and Fix Components

Please read Liability Disclaimer and License Agreement CAREFULLY

Looking for a quick and efficient way to simplify your CATIA V5 product design process?

Look no further than my Catia V5 Macro!

With just a few clicks, this macro will delete all of the constrains on your CATProduct and then add a Fix constrain on each component, giving you a clean slate to work with.

Say goodbye to manual constrain management and hello to increased productivity and accuracy.

Download this Catia V5 Macro today and streamline your design process like never before!

Fix All Components Constrains

Fix All Components Fix

Start By creating a new VBA project and then copy and paste the code below in it.

Sub CATMain()
    Dim Warning As Integer
    Warning = MsgBox("Notice!!!" & VBA.Chr(13) & "Copyright © 2004 Grozea Ion" & VBA.Chr(13) & "All constrains will be deleted and then Fix will be applied." & VBA.Chr(13) & "Do you wish to continue?", vbYesNo, "Fix All Components")
    If Warning = 6 Then
        If TypeName(CATIA.ActiveDocument) <> "ProductDocument" Then
            MsgBox "CATIA active document is not valid!" & VBA.Chr(13) & "This macro runs only on CATProduct.", vbExclamation, "Product2Part!!!"
            Exit Sub
        Else
            FixAll
        End If
    Else
        Exit Sub
    End If
End Sub
Sub FixAll()
    Dim crtDoc As ProductDocument
    Set crtDoc = CATIA.ActiveDocument
    Dim mySel 'As Selection
    Set mySel = CATIA.ActiveDocument.Selection
    mySel.Clear
    'On Error Resume Next
    Dim crtProd As Product
    Set crtProd = crtDoc.Product
   
    Dim prods As Products
    Set prods = crtProd.Products
    
    Dim crtProdConsts As Constraints
    Set crtProdConsts = crtProd.Connections("CATIAConstraints")
    Dim crtConstr As Constraint

    mySel.Clear
    For i = 1 To crtProd.Connections("CATIAConstraints").Count
        Set crtConstr = crtProd.Connections("CATIAConstraints").Item(i)
        mySel.Add crtProd.Connections("CATIAConstraints").Item(i)
    Next

    If mySel.Count > 0 Then
        mySel.Delete
        mySel.Clear
    End If

    For Each prod In crtProd.Products
        Dim myRef As Reference
        Dim strForRef As String
        strForRef = crtProd.PartNumber & "/" & prod.Name & "/!" & crtProd.PartNumber & "/" & prod.Name & "/"
        Set myRef = crtProd.CreateReferenceFromName(strForRef)
        Dim fixConstr As Constraint
        Set fixConstr = crtProdConsts.AddMonoEltCst(catCstTypeReference, myRef)
        fixConstr.Name = prod.Name
    Next
    Call MsgBox("Finished!", vbInformation, "Fix All Components")
End Sub

 

Comments powered by CComment