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!

Selection.Search macro

Status
Not open for further replies.

dddn

Mechanical
Nov 26, 2022
35
IT

Hi all, does anyone know how to use the TopologyCGMFace command inside a for loop?
the code is as follows

Sub CATMain()

Dim partDocument1 As Document
Set partDocument1 = CATIA.ActiveDocument

Set part1 = partDocument1.Part

Set selection1= partDocument1.Selection

Set hybridShapeFactory1 = part1.HybridShapeFactory

Dim ElementsArray(0)
ElementsArray(0) = "AnyObject"
Status = selection1.SelectElement3(ElementsArray, "name", True, CATMultiSelTriggWhenUserValidatesSelection, False)

For n = 1 To selection1.Count
Set selectedProd1 = selection1.Item(n).Value
selectProd1.Search("Topology.CGMFace,sel") '''''This is the error line
Next

Thanks
 
Replies continue below

Recommended for you

I usually save my selection findings into an array. (Selection belongs to the document, not product)
You will be searching each of the array items for something else (i.e your selection will loose the selected items, and show the new result)
I usually try the CATIA selection first (Ctrl + F); with " add to favorites.." command you can easily copy the search string.
In the code I usually assign a search string that copied text:
Code:
SelString = "Topology.Face;sel"
Dim mySel
Set mySel = CATIA.ActiveDocument.Selection
mySel.Search (selString)
After you've created the array of your selected objects;
in your for loop, clear the selection1, add n:th object of the array to the selection, perform search on that...

regards,
LWolf
 
Thank you for your answer.
But I can't get what I want:
in the "selectelement3" line I have already created an array, and when I use the "msgbox selectedProd1.Name" it returns the correct names, but it gives me an error in the selection1.search
Where is the error?
I try to modify in this way, but the error is present

Sub CATMain()

Set PartDocument1 = CATIA.ActiveDocument
Set selection = PartDocument1.Selection

Dim SewFilt(0)
SewFilt(0) = "AnyObject"
Dim ret
selection.Clear
ret = selection.SelectElement3(SewFilt, "Select Sew", False,2, False) ''in this selection, i select all the sew surface
numSew= selection.Count2


ReDim oSewArray(numSew)

For i=1 To numSew
Set oSewArray(i) = selection.Item2(i).Value
msgBox oSewArray(i).Name
Next

Call selection.Clear

For i=1 To numSew
Dim selection1 As Face
set selection1= oSewArray(i)
selection1.Search "Topology.Face; sel" ''ERROR'' ''in this line i want search the face that are present in a specifical sew surface
msbox selection1.Count2
Next

End Sub

Help please
 
Hi ,

I think that the Search method is searching in the document and not inside your array.

Regards
Marc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top