Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

How to re-use Selection VBA

Status
Not open for further replies.

CarlosR2022

Electrical
Sep 16, 2010
36
Let's say I pre-select a number of geometric elements in a 2D environment. This includes lines and texts. Now I want to have 2 distinct searches to get (1) lines then (2) texts/

Code:
'I selected a number of objects manually.
'because I want to limit my works on these objects only
dim preSelectedItems as Selection
dim selectedLines as Selection
dim selectedTexts as Selection

set preSelectedItems = CATIA.ActiveDocument.Selection
preSelectedItems.Search "Drafting.Line,sel"
set selectedLines = preSelectedItems '<~~~ this is fine

preSelectedItems.Search "Drafting.Text,sel"
set selectedTexts = preSelectedItems '<~~~ this is not ok because sel contains lines from 1st Search
 
Replies continue below

Recommended for you

Hi,
try to insert the line "preSelectedItems.Clear" before the second search; and after insert a string that contain "selectElement3" to re-select the operations.

Bye
 
No, you can't manage selection results as if they were independent collections.

1. Make an initial search
2. Iterate through selection and save items to a Collectionn or an ArrayList
3. Search for lines within "sel" scope
4. Iterate and place lines to their own Collection
5. Clear and reselect items from step 2
6. Search for points within "sel" scope

Consider using TypeName() function or TypeOf ... is operator to determine object type instead of Selection.Search
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor