×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

macro to search Cat Tree in 3D and Select

macro to search Cat Tree in 3D and Select

macro to search Cat Tree in 3D and Select

(OP)
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.

RE: macro to search Cat Tree in 3D and Select

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.

RE: macro to search Cat Tree in 3D and Select

(OP)
sry i forgot to clarify. I am trying to write an macro for that search function.

RE: macro to search Cat Tree in 3D and Select

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 http://www.eng-tips.com/viewthread.cfm?qid=334401 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

https://picasaweb.google.com/102257836106335725208

RE: macro to search Cat Tree in 3D and Select

(OP)
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.

RE: macro to search Cat Tree in 3D and Select

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

https://picasaweb.google.com/102257836106335725208

RE: macro to search Cat Tree in 3D and Select

(OP)
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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources