macro to save selected partsto specified path failed
macro to save selected partsto specified path failed
(OP)
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
''''''''''''''''''''
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





RE: macro to save selected partsto specified path failed
Your macro is working fine but you need to have the selection in design mode and not in visualization mode.
Regards
Fernando
https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU
RE: macro to save selected partsto specified path failed
RE: macro to save selected partsto specified path failed
Regards
Fernando
https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU
RE: macro to save selected partsto specified path failed
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
indocti discant et ament meminisse periti
RE: macro to save selected partsto specified path failed
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.
RE: macro to save selected partsto specified path failed
Regards
Fernando
https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU
RE: macro to save selected partsto specified path failed
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.
RE: macro to save selected partsto specified path failed
Regards
Fernando
https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU