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!

macro to save selected partsto specified path failed

Status
Not open for further replies.

llbbyy

Mechanical
Mar 21, 2017
21
I creat a macro( see bellow) to save selected part to a specified Path but failed. any help will be appreciated.
''''''''''''''''''''
Language = "VBScript"

CATIA.DisplayFileAlerts = False
sub CATMain()
Set cad = CATIA.ActiveDocument
Set sel = cad.Selection
Set prod = cad.Product.Products
Set docs = CATIA.Documents

If sel.count =0 Then
MsgBox "Select parts from tree.", ,msgboxtext
Exit Sub
End If


docPath=InputBox("Enter the Path:")

for i=1 to sel.count

set doc1= docs.item(i)
doc1.saveas docPath & prod.item(i).PartNumber &".CatPart" 'failed here

next

End sub
 
Replies continue below

Recommended for you

It still doesn't work.How to set Selection in Design Mode?
 
set doc1= docs.item(i)

this is not linked with sel (your selection) so it will save each doc.item in the open document... this will not take selected part into account

Eric N.
indocti discant et ament meminisse periti
 
To itsmyjob,
thanks for your reply.
Yes,I find a macro in the forum, which can save all items to one folder, but I expect to save selected part to different folder,let say some to Folder A, some to Folder B, bolt and nut to a Fastener Folder, motor and cylinder to purchased part Folder,etc…

The question is how to link docs.item(i) to select parts
Take following as an Example
Product..
|---A
|---A
|---B
|---B
|---C
|---D
|---E

If I select the 5th to 7th parts, ie, C,D, and E, and save this three to a defined folder. I don't know how to link docs.item(i) to selected D and E?
The docs.item(i) can get the filename, I wonder how to get its partnumber or instance name , if its partnumber or instance name are got,I think doc.item(i) can link to selected parts through them.
 
to ferdo,
Sorry to make you misunderstanding.
My purpose is to select some parts( say, part_1 to part_n,see bellow), and save them to a specified folder,for example, E:\wlding_jig\unit_1, which is input in InputBox.
I know this can be realised by saveas one by one, but it's wastetime.
------------------
welding_jig
|--------Unit_1
| |----part_1
| |----part_2
| |----part_2
| |----part_3
| |----part_3
| |----part_4
| .
| |----part_n
| .
| |----bolt_M10x65
| |----Bolt_M8x50
| |----nut_M10
| |----nut_M8
|
|--------unit_2
| |----
|

Thank you any way.



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor