Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Coincidence Sub-Assy CATVba

Status
Not open for further replies.

Jegsaran

Automotive
Dec 16, 2020
41
0
0
IN
Hello everyone,
I'm trying to coincidence 2 different sub-assy axially. I'm facing issue in converting the user selected input into reference as CreateReferenceFromName.
Please suggest me any methods,

Set oDoc = CATIA.ActiveDocument
Set oProd = oDoc.Product
Set constraints1 = oProd.Connections("CATIAConstraints")
Set Sel = oDoc.Selection
inputObjectType(0) = "Edge"
Filter1 = Sel.SelectElement2(inputObjectType, "Select the Line", True)
Filter2 = Sel.SelectElement2(inputObjectType, "Select the Axis", True)
'Reference 1 will be a line in a dummy part
'Reference 2 would be an Axis in a different product
'I want the user selected inputs in the following format
Set reference1 = oProd.CreateReferenceFromName("AssySection1/PartSection1.1/!Geometrical Set.1/X-Axis")
Set reference2 = oProd.CreateReferenceFromName("AssySection1/Sub-Product1.1/Sub-Product2.2/Sub-Product3.1/Part1.1/!Axis:(Selection_RSur:(Face:(Brp:(Pad.1;0:(Brp:(Sketch.1;1)));None:();Cf11:());Pad.1_ResultOUT;Z0;G4702))")
Set constraint1 = constraints1.AddBiEltCst(catCstTypeOn, reference1, reference2)
 
Replies continue below

Recommended for you

Since you're using Selection, why not to try SelectedElement.Reference property?

Code:
If "Normal" <> Sel.SelectElement2... then
  Exit sub
End if
Set reference1 = Sel.Item(1).Reference

Same for reference2.
 
Tried it but it is giving Method of Object err.

Set oDoc = CATIA.ActiveDocument
Set oProd = oDoc.Product
Set Sel = oDoc.Selection
inputObjectType(0) = "Edge"
Filter1 = Sel.SelectElement2(inputObjectType, "Select the Line", True)
Set reference1 = Sel.Item(1).Reference
Sel.Clear
Set Sel2 = oDoc.Selection
inputObjectType(0) = "Face"
Filter2 = Sel2.SelectElement2(inputObjectType, "Select the Face", True)
Set reference2 = Sel2.Item(1).Reference
Sel.Clear
Set constraints1 = oProd.Connections("CATIAConstraints")
Set constraint1 = constraints1.AddBiEltCst(catCstTypeOn, reference1, reference2)
 
Tried to recreate the record macro then also getting the same err.
Is it because that I'm selecting Face for reference2 or any other ?
Not sure where I am missing something!


Set oDoc = CATIA.ActiveDocument
Set oProd = oDoc.Product
Set Sel = oDoc.Selection
inputObjectType(0) = "Edge"
Filter1 = Sel.SelectElement2(inputObjectType, "Select the Line", True)
Set reference1 = Sel.Item(1).Reference
StrPrtCnstrNme = oTopAssy.Name & "/" & oTempltPrt1.Name & "/!" & oTempltPrtHybBody.Name & "/" & reference1.Name
Sel.Clear
Set Sel2 = oDoc.Selection
inputObjectType(0) = "Face"
Filter2 = Sel2.SelectElement2(inputObjectType, "Select the Face", True)
Set reference2 = Sel2.Item(1).Reference
StrDispName = "/!Axis:(" & ref2.DisplayName & ")"
Set objPrd = SelRigid.Item(1).LeafProduct
fullpath = objPrd.Name

While Not reachroot

Set objPrd = objPrd.Parent
If objPrd.Name <> "Products" Then
fullpath = objPrd.Name & "/" & fullpath
End If

checkParent = ""
checkParent = objPrd.Parent.Name

If checkParent = oTemplateDocProd.Name Then reachroot = True
Wend
StrConstr2 = fullpath & StrDispName
Sel.Clear

Set constraints1 = oProd.Connections("CATIAConstraints")
Set Ref1 = oTopAssy.CreateReferenceFromName(StrPrtCnstrNme)
Set Ref2 = oTopAssy.CreateReferenceFromName(StrConstr2)
Set constraint1 = constraints1.AddBiEltCst(catCstTypeOn, Ref1, Ref2)
 
Yes, it's because of face. And recorded macros barely work in real-world tasks, so don't count on them.

Don't use multiple "sel" variables, they all essentially point to the same object. And use code tag to format code samples and make them way more readable.

Now try:
Code:
Dim sel: set sel = oDoc.Selection

dim fc as Face
set fc = sel.Item(1).Value

set reference2 = oTopAssy.CreateReferenceFromName(fullpath).ComposeWith(fc)
 
ok I'll try this method. Is it ok if select the face(I need axis only but Axis filter is not working) for second reference?
 
No idea. If it works manually then it should work programmatically.

If you notice that manual process createa reference2 with "axis:" word while automatic doesn't then you may have edit reference string and use Part.CreateReferenceFromName.
 
Finally I got it! Made some workaround to make it work.
I created an axis for my second reference and now it works fine.
Below is the working code

Code:
    Set oDoc = CATIA.ActiveDocument
    Set oTopAssy = oDoc.Product
    Set oTempltAssy = oTopAssy.Products.Item(1)
    Set oPartDoc = oTempltAssy.ReferenceProduct.Parent
    Set oTempltPrt1 = oPartDoc.Part

    Set constraints1 = oTopAssy.Connections("CATIAConstraints")
    Set reference1 = oTopAssy.CreateReferenceFromName(oTopAssy.Name & "/" & oTempltAssy.Name & "/!" & oTopAssy.Name & "/" & oTempltAssy.Name & "/")
    Set constraint1 = constraints1.AddMonoEltCst(catCstTypeReference, reference1)   'Fixing Part 1

    Set Sel = oDoc.Selection
    inputObjectType(0) = "Line"
    Sel.Clear
    StrPtCreation = Sel.SelectElement2(inputObjectType, "Select the line", True)
    If (StrPtCreation = "Cancel") Then GoTo NxtLvl:
    Set ref134 = Sel.Item(1).Value
    StrPrtPathNme = oTopAssy.Name & "/" & oTempltPrt1.Name & "/!" & oTempltPrtHybBody.Name & "/" & ref134.Name
    Set ref1 = Sel.Item(1).Reference
    If ref1.Name = "X-Axis" Then          'The User will select either of the 2 lines(
        Set RefCstCoin1 = oTopAssy.CreateReferenceFromName(oTopAssy.Name & "/" & oTemplatePartAssy.Name & "/!Geometrical Set.1/X-Axis")
    ElseIf ref1.Name = "Y-Axis" Then
        Set RefCstCoin1 = oTopAssy.CreateReferenceFromName(oTopAssy.Name & "/" & oTemplatePartAssy.Name & "/!Geometrical Set.1/Y-Axis")
    End If
    Sel.Clear

    Filter(0) = "Face"
    Status = Sel.SelectElement2(Filter, "Select the cylindrical face to coincide", True)
    If (Status = "Cancel") Then GoTo NxtLvl:
    Set ref2 = Sel.Item(1).Reference
    SpltDispName = Split(ref2.DisplayName, "Selection_")
    StrSpltDispName = Split(SpltDispName(1), ":());")
    StrDispName = StrSpltDispName(0)
    Set SelPart1 = Sel.Item(1).LeafProduct
    Set SelPart = ref2.Parent.Parent.Parent.Parent.Parent
    Set SelPartHybBodies = SelPart.HybridBodies
    Set SelPartHybBody = SelPartHybBodies.Add()
    Set SelPartHSFact = SelPart.HybridShapeFactory
    Set reference1 = SelPart.CreateReferenceFromBRepName(StrDispName & ":());WithPermanentBody;WithoutBuildError;WithSelectingFeatureSupport;MFBRepVersion_CXR29)", ref2.Parent)
    Dim hybridShapeAxisLine1 As HybridShapeAxisLine
    Set hybridShapeAxisLine1 = SelPartHSFact.AddNewAxisLine(reference1)
    hybridShapeAxisLine1.AxisLineType = 1
    SelPartHybBody.AppendHybridShape hybridShapeAxisLine1
    SelPart.InWorkObject = hybridShapeAxisLine1
    SelPart.Update
    fullpath = SelPart1.Name
    
     While Not reachroot
  
        Set SelPart1 = SelPart1.Parent
        If SelPart1.Name <> "Products" Then
            fullpath = SelPart1.Name & "/" & fullpath
        End If
        checkParent = ""
        checkParent = SelPart1.Parent.Name
        If checkParent = oTopAssy.Name Then reachroot = True
    Wend
    Sel.Clear


'I have one more level of assembly at the top So I redim the below productDocument2 & product2 

Set productDocument2 = oDoc.Item(oTopAssy.PartNumber & ".CATProduct")
Set product2 = productDocument2.Product
Set constraints1 = product2.Connections("CATIAConstraints")
Set RefCstCoin2 = product2.CreateReferenceFromName(oTopAssy.PartNumber & "/" & fullpath & "/!" & SelPartHybBody.Name & "/" & hybridShapeAxisLine1.Name)
Set constraint1 = constraints1.AddBiEltCst(catCstTypeOn, RefCstCoin1, RefCstCoin2)
 
Status
Not open for further replies.
Back
Top