SelectElement2 Access Parent CATPart

Michael Milez

SelectElement2 Access Parent CATPart

Hello All,

I have a question that I'm sure once it clicks isn't super complicated (hopefully, lol) but at the moment I'm stuck.

I am currently writing a VBA in which I would like the user to make a selection within Catia, either on the part geometry, or within the spec tree, and have the CATPart which contains that selection end up being the destination for future operations. For example, I would like the user to identify a CATPart for which later operations will copy the main part bodies from other parts into the user selected CATPart if certain criteria are met.

Below is what I have for the user selection portion:

Sub CATMain()

Dim oSel as Selection
Set oSel = CATIA.ActiveDocument.Selection

Dim oSelLB as Object
Set oSelLB = oSel

ReDim strArray(0)
strArray(0) = "Part"

Dim sStatus as string

msgbox "Please select destination"

sStatus = oSelLB.SelectElement2(strArray, "Select part", False)

'The following line returns the name of the CATPart for the selection that was made.
'I just can't figure out an easier way to access the part to be able to paste other bodies into it later.
Dim DestName as String
DestName = oSelLB.Item(1).Value.Name

End Sub

I am stuck at how to access the CATPart after the selection. I have tried to use the name of the selection to identify the CATPart and then search for the name, but this ends up making the program run time much longer than I believe it needs to be because it keeps having to perform a search every time it finds another part matching criteria it wishes to copy over.

Any help would be greatly appreciated!!! Thank you!

Little Cthulhu

RE: SelectElement2 Access Parent CATPart
(in response to Michael Milez)
Dim instance As Product: set instance = oSelLB.Item(1).LeafProduct
Dim partRoot as Part: set partRoot = instance.ReferenceProduct.Parent.Part