Select/copy a feature from a specific instance in an assembly

Vyndell Michael

Select/copy a feature from a specific instance in an assembly

Hello,

I'm working on a custom sectioning tool, where one can cut (not) selected parts of an assembly.

The section plane or planes can be created be selecting any geometry. Extracts of the selected geometry is copied to a new part where the definition of the section plane(s) will be calculated.

There are problems if there is more than one instance of the Catiapart of the created extract.

 

To make it easy: Lets say I have an assembly like this:

MainProduct (active document):
-Product1 (Instance of Part1)
-Product2 (Instance of Part2)
-Product3 (Instance of Part2)
-Product4 (Instance of Part3)
...

Now, I select a cylinder face from Product3 and then I want to copy/paste an extract of it into a new product/part.
But I run into problems when selecting the feature programmatically, because there are 2 instances of Part2.

I can't control which feature will be selected by 

CATIA.ActiveDocument.Selection.Add(myExtractReference)

Catia always selects the feature from Product2 instead of the feature from Product3. So the position of the pasted feature will be wrong!

Does anybody know this problem and has a solution to it?

During the geometry selection I need to know where the selection is made. In Product2 or Product3. The BRep also only refers to the part, not the product (instance).

 

Thanks in advance,

Vyndell

Little Cthulhu

RE: Select/copy a feature from a specific instance in an assembly
(in response to Vyndell Michael)
During the geometry selection I need to know where the selection is made. In Product2 or Product3. 

 

SelectedElement has LeafProduct property exactly for that reason.

However I don't think you can create an Extract feature from geometry located in another part with Automation. HybridShapeFactory.AddNewExtract simply won't accept "foreign" Reference objects. And it makes sense since when you're referencing geometry in another part when creating features manually CATIA copies that geometry with link and then uses copy, not original object.

So what you can do is to imitate CATIA's approach and to use Selection.Copy and Selection.Paste to bring selected geometry to your part.

Alternatively since you're working with planes only it is possible to get selected planes vector (using Measurable), apply transformations based on product instance position to move to global axis system and then recreate plane feature in your part (assuming it's located in global axis system's origin).

Vyndell Michael

RE: Select/copy a feature from a specific instance in an assembly
(in response to Little Cthulhu)
SelectedElement has LeafProduct property exactly for that reason.

Thanks! This is exactly what i needed.

 

However I don't think you can create an Extract feature from geometry located in another part with Automation.

When an object is selected (even BReps), i will navtigate through every .Parent until "Document" is part of the object's type.

 

So what you can do is to imitate CATIA's approach and to use Selection.Copy and Selection.Paste to bring selected geometry to your part.

Yes, this is what I do.

 

Alternatively since you're working with planes only...

I don't use only planes for selection. But the transformation can be done with any object. (Background: From the extracts I try to create a simple feature like a plane, an axis or a point by testing Catia's Plane/Line/Point Constructors until no error occurs. With these (more than 1) features the section definition will be made)

 

So this is my new game plan (for the copy/paste part): 

  • Object selected by user (keep a reference to SelectedElement.LeafProduct)
  • Create extract from selection
  • Copy/Paste the extract to a new part
  • Add the extract to the (cleared) selection
  • If the new LeafProduct differs from the original one
    Apply transformation according to the products' Position objects

 

Thanks!