Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

CATIA Macro: search object and add to selection 1

Status
Not open for further replies.

elmundo777

Automotive
Jun 23, 2020
93
Hello. I cannot solve the issue with the selection of several objects.
I'm search for an element by its name. Then I need to add to the selected items.

Here example how I search all elements from active document:
Code:
dim cad = CATIA.ActiveDocument
dim sel = cad.Selection
sel.Search( "CATAsmSearch.Product+CATAsmSearch.Part,all")

But i need a custom selection by partnumber\instance name.
Here example how I search the element by instancename:
Code:
 sel.Search( "Name=" & nameWithoutExt & ".1" & ",all")

How can i add next element to selection?

This option is not suitable, since I need to add an object, not a string
But how to go from string to object?
Code:
 sel.Add(nameWithoutExt)
<--this is wrong


 
Replies continue below

Recommended for you

Well, you have to find an object beforehand or enlist all names in a search query at once: "Name=... + Name=...,all"
 
or do one at a time, in a loop... and store the found item in an array or a dictionary. when you are done, you can add all the members of the array/dict to your selection.

regards,
LWolf
 
i do in a loop
since I cannot add to the collection, only the last element from the cycle remains selected
 
How can I, after I have found an element, put it into the collection, and then add it to the selection when the cycle is over?
 
sel.item(1).value is your object
store it in an array (its size will need to expand with redim preserve statement)
when you are done, loop thru the array and do sel.add of each item

regards,
LWolf
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor