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!

How to get object from reference (CATIAReference) 2

Status
Not open for further replies.

PrasannaNX

Automotive
Aug 5, 2014
31
IN
Hi,

Is there any way to get object from reference (CATIAReference)?
I have already tried searching the forum but couldn't able to find any relevant thread.

Code:
INFITF.Application catApp = (Application)Marshal.GetActiveObject("Catia.Application");
ProductDocument catProdDoc = (ProductDocument)catApp.ActiveDocument;
Product catProd = catProdDoc.Product;
Constraints catConsts = (Constraints)catProd.Connections("CATIAConstraints");

for (int iIndex = 1; iIndex <= catConsts.Count; iIndex++)
{
    Constraint catCons = (Constraint)catConsts.Item(iIndex); //Fix constraint
    Reference catRef = catCons.GetConstraintElement(1); //Part1 inside Product >> [b]How to convert this reference to Part object?[/b]
}
 
Replies continue below

Recommended for you

Hi.

Easiest (yet perfomance costly) way is to add it to Selection and then read it back:

Code:
Seldection sel = catProdDoc.Selection;
sel.Clear();
sel.Add(catRef);
Product prd = (Product)sel.Item(1).Value;
Part prt = ((PartDocument)prd.ReferenceProduct.Parent).Part
 
Thanks Cthulhu, It worked.
Is there any other way to find it?
 
Is there any other way to find it?

Check DisplayName property of catRef. It contains slash-separated path from top context product to the published instance. Path elements are instance names, first element is partnumber of context product.
 
Yes i noticed that Cthulhu.
Even if i use the slash delimiter and get the string i am searching for.
How do i use the string(Part name) to get its object?

Actually i am looking for something similar to this API FindObjectByName which is under Part object.
Anyways thanks for your help, for now i guess i can manage with your first suggestion.

- PrasannaNX
 
Code:
var path = catRef.DisplayName.Split("/");
var current = catApp.Documents.OfType<ProductDocument>().First(x => c.Product.get_Name() == path[0]).Product;
foreach (var token in path.Skip(1)) {
  current = current.Products.Item(name);
}
 
A crucial update.

Use Part.HybridShapeFactory.GSMGetObjectFromReference(reference)
 
Part.HybridShapeFactory.GSMGetObjectFromReference(reference) does not work with all references.

Can you throw some light on which type of references this works and on which references it does not work.

For example I got a reference object from a publication (using Publication.Valuate).
When I pass this reference to GSMGetObjectFromReference it generates an error 'Method failed'.

But it did work with a reference of a Pad.

So, its confusing to say the least.
 
Hi.
Well, I doubt it works with references to faces, edge and vertices. Is it your case?
 
Yes.

But can we not form any logical reasoning to find out how and when it works.
It will save lot of time every body spends in learning by trial and re-inventing the wheel.
 
If you really want to know how it works, ask Dassault. Best of luck since we're talking about proprietary code.

Trials and errors are inevitable with these kinds of APIs. At least you have places to look for answers.
 
Why be so sarcastic and negative.
If everybody can share their experience wouldn't it help others? let us help ourselves.
 
I've got no time for sarcasm, just being real. Be aware this APIs can behave whatever they like, so be prepared and expect the unexpected.

Totally agree on the last point, that's why we here for.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top