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.
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS Come Join Us!Are you an
Engineering professional? Join Eng-Tips Forums!
*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail. Posting GuidelinesJobs |
macro to search Cat Tree in 3D and Select
|
RE: macro to search Cat Tree in 3D and Select
RE: macro to search Cat Tree in 3D and Select
RE: macro to search Cat Tree in 3D and Select
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
RE: macro to search Cat Tree in 3D and Select
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
RE: macro to search Cat Tree in 3D and Select
Just for my curiosity, how is looking that implicit function (can you be more specific how did you achieve your goal) ?
Regards
Fernando
https://picasaweb.google.com/102257836106335725208