Continue to Site

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!

macro to search Cat Tree in 3D and Select

Status
Not open for further replies.

noobcat

Aerospace
Nov 19, 2012
9
CA
I would like to search the tree for my part from a list of part number I have, and select the part from the tree once found.
 
Replies continue below

Recommended for you

Use Edit + Search. Type in the *part number* in the Name field (PN with * before and after). click the binocular icon to search. If it finds the part, click the SELECT box on the bottom to select that instance of the part.
 
sry i forgot to clarify. I am trying to write an macro for that search function.
 
Hi,

From what I understood, you have a list (I suppose in a text file), you want to read from macro that list line by line then select in product structure those names, correct ?

If so, take a look at and see how you can read a text file with some data inside , then try to record a macro with search function as Jackk suggested and put all code toghether.

If you have problems, post the code here so we can help you.

Regards
Fernando

 
i dont know how to begin unfortunately. I was able to call the top level tree, but then each tree has a product, and product have an item, and item will have a product... after several, i will find a product with x amount of items which i will need.
 
Hi,

Write a text file and put it in folder C:Temp. Text should look like bellow

PartName1
PartName2
test

In your Product structure, just for testing purposes, should have at least one part (or product) with name PartName1 and one (or more) with PartName2

Copy in a CATscript the code bellow. If you will look at code you will see that is searching for names in product structure, no matter where they are. I've inserted also a check, just for exemplification.

Sub CATMain()

Dim productDocument1 As Document
Set productDocument1 = CATIA.ActiveDocument

Dim selPN As Selection
Set selPN = productDocument1.Selection

Dim objFSO, strTextFile, strData, strLine, arrLines
CONST ForReading = 1

'name of the text file
strTextFile = "C:\Temp\test.txt"

'Create a File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")

'Open the text file - strData now contains the whole file
strData = objFSO.OpenTextFile(strTextFile,ForReading).ReadAll

'Split the text file into lines
arrLines = Split(strData,vbCrLf)

'~ 'Step through the lines
For Each strLine in arrLines
'~ ''''''''''''''''''''''''''''''''''''''''
MsgBox "Name of Part in line to be selected: " & strLine
selPN.Search "Name=" & strLine & "*" & " ,all"
If selPN.Count = 0 Then
MsgBox "Part Name in text file does not exist in product structure"
Else
MsgBox "Number of selections for " & strLine & " = " & selPN.Count
End If
Next
selPN.Clean
'Cleanup objFSO
Set objFSO = Nothing

End Sub

You have to modify yourself the code according to your needs.




Regards
Fernando

 
thank you. I recently figured out an implicit function to achieve my goal. however, that has proven to be many use for me later in my programings.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top