1

I have a issue regarding constraining in assembly. below is the code.

Sub catmain()
Dim CAT_documents As Documents
Set CAT_documents = CATIA.Documents

Dim prod_doc As ProductDocument
Set prod_doc = CATIA.ActiveDocument

Dim prod As Product
Set prod = prod_doc.Product

Call constraint_everything(prod)
End Sub

Sub constraint_everything(cProd As Product)

Dim constraints1 As Constraints
Set constraints1 = cProd.Connections("CATIAConstraints")

Dim temp As Product
If cProd.Products.Count > 0 Then
    For i = 1 To cProd.Products.Count
        Set temp = cProd.Products.Item(i)
        
        Dim osel 'as Selection
        Set osel = CATIA.ActiveDocument.Selection
        On Error Resume Next
        osel.Clear
        osel.Add temp
        
        Dim dispname As String
        dispname = osel.Item(1).Reference.DisplayName & "!" & osel.Item(1).Reference.DisplayName
        
        
        Dim ref As Reference
        Set ref = cProd.Products.CreateReferenceFromName(dispname)
        Dim constraint1 As Constraint
        Set constraint1 = constraints1.AddMonoEltCst(catCstTypeReference, ref)
        If (temp.Products.Count > 0) Then
            Call constraint_everything(temp)
        Else
            
        End If
    Next
Else
End If

End Sub

here the line

Set constraint1 = constraints1.AddMonoEltCst(catCstTypeReference, ref)

should create constraint with respect to the reference "ref"

but it is not creating it.

This represents the structure which i have to constrain: enter image description here

Thanks.

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
tls
  • 11
  • 2
  • What does "it is not creating it" mean? Is it throwing an error? Object equals nothing? How does it fail? – StayOnTarget Feb 03 '23 at 12:39
  • 1
    Please remove _on error resume next_ for testing. You can try to delete _Products_ in line where you create the reference (_Set ref = cProd.CreateReferenceFromName(dispname)_) – Shrotter Feb 03 '23 at 13:05
  • hello @StayOnTarget yes it is showing as "Object equals nothing" here: "Set constraint1 = constraints1.AddMonoEltCst(catCstTypeReference, ref)" the object constraint1 remains Nothing. – tls Feb 03 '23 at 14:49

0 Answers0