Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Fix a Part using CATIAConstraints in VBA

Status
Not open for further replies.

Jegsaran

Automotive
Dec 16, 2020
41
IN
Hello Everyone,
I'm trying to fix a Part in an assembly using constraints but I'm getting (method "AddMonoEltCst") Error.
Below is my code,

Set oDOC = CATIA.Documents
Set oTemplateDoc = oDOC.Add("Product")
Set oTemplateDocProd = oTemplateDoc.Product
Set oTemplateDocProds = oTemplateDocProd.Products
Set oTopAssy = oTemplateDocProds.AddNewComponent("Product", "")
oTopAssy.Name = "Assy - Section.1"
Set oTopAssys = oTopAssy.Products
Set oTempltAssy = oTopAssys.AddNewComponent("Part", "")
Set opartDoc = oTempltAssy.ReferenceProduct.Parent
Set oTempltPrt = opartDoc.Part
Set constraints1 = oTopAssy.Connections("CATIAConstraints")
sItemName = oTempltAssy.Name
Set reference1 = oTopAssy.CreateReferenceFromName(sItemName & "/!" & "/")
Set constraint1 = constraints1.AddMonoEltCst(catCstTypeReference, reference1)
 
 https://files.engineering.com/getfile.aspx?folder=c86b3c6c-43b8-4b7e-8690-decd66521f3b&file=Constrain.PNG
Replies continue below

Recommended for you

Most likely an input string in CreateReferenceFromName is invalid.

Here's what you can do:
1. Create document structure and fix part manually
2. Select created constraint in the tree and access it in VBA with CATIA.ActiveDocument.Selection.Item(1).Value in debug mode.
3. Use APIs to retrieve Reference to constrained part and check it's DisplayName property. What you're going to see is the correct reference string.

 
Thanks found the issue. Here is my code,

Set oDoc = CATIA.Documents
Set NewDoc = oDoc.Add("Product")
Set NewDocProd = NewDoc.Product
Set CollNewDocProd = NewDocProd.Products
Set NewProd = CollNewDocProd.AddNewComponent("Product", "")
Set NewProdDoc2 = oDoc.ITEM("Product1.CATProduct")
Set oTopAssy = NewProdDoc2.Product
Set CollNewProd = NewProd.Products
Set NewPart = CollNewProd.AddNewComponent("Part", "")
Set oPartDoc = oDoc.ITEM("Part1.CATPart")
Set oTemplatePart = oPartDoc.GetItem("Part1")
Set ColloTopAssy = oTopAssy.Products
Set oTemplatePartAssy = ColloTopAssy.ITEM("Part1.1")
NewDocProd.Update
Set constraints1 = oTopAssy.Connections("CATIAConstraints")
Set reference1 = oTopAssy.CreateReferenceFromName(oTopAssy.Name & "/" & oTemplatePartAssy.Name & "/!" & oTopAssy.Name & "/" & oTemplatePartAssy.Name & "/")
Set constraint1 = constraints1.AddMonoEltCst(catCstTypeReference, reference1)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top