llbbyy
Mechanical
- Mar 21, 2017
- 21
I create a macro,the object is to:
1)rename the part name and instance name,
2) the instance name same to part name suffix ,for example, the part number is xxxx-001, the instance should be 001, if there are sevral xxx-001, the instance name should be 001, 001.1 001.2 etc.
3)save the renamed part to a specified path specified by inputbox,
4)save the filename same as renamed number.(macro see attachment).
now the macro have some problems:
1)the firt part (xxxx-001) filename is different,maybe xxxx-003,
2)specified path failed
3)when a part more than 1 piece, the instance name wound different to partnumber, ie, the partnumber xxxx-001, the instance number maybe 008.1 etc.
any help would be appriciated.
''''''''''''''''''''''''''
Language = "VBScript"
Sub CATMain()
CATIA.DisplayFileAlerts = False
new_str = inputbox("Enter the prefix:")
new_path = inputbox("Save to new path:")
str_len = len(new_str)
Set prod_Doc = CATIA.ActiveDocument
Set prod = prod_Doc.Product
Set prods = prod.Products
j = 1
k =1
For i = 1 To prods.Count
if left(prods.Item(i).PartNumber,str_len)<>new_str then
if j <10 then
prods.Item(i).PartNumber = new_str&"-00"&(j)
prods.Item(i).name = "00"&(j)
else
prods.Item(i).PartNumber = new_str&"-0"&(j)
prods.Item(i).name = "0"&(j)
end if
j = j + 1
else
prods.Item(i).name = "00"&(j)&"."&(k)
k = k + 1
end if
newName = prods.Item(j).PartNumber
Set docs = CATIA.Documents
set doc1 = docs.Item(j)
doc1.SaveAs new_path & NewName & ".CATPart"
Next
End Sub
1)rename the part name and instance name,
2) the instance name same to part name suffix ,for example, the part number is xxxx-001, the instance should be 001, if there are sevral xxx-001, the instance name should be 001, 001.1 001.2 etc.
3)save the renamed part to a specified path specified by inputbox,
4)save the filename same as renamed number.(macro see attachment).
now the macro have some problems:
1)the firt part (xxxx-001) filename is different,maybe xxxx-003,
2)specified path failed
3)when a part more than 1 piece, the instance name wound different to partnumber, ie, the partnumber xxxx-001, the instance number maybe 008.1 etc.
any help would be appriciated.
''''''''''''''''''''''''''
Language = "VBScript"
Sub CATMain()
CATIA.DisplayFileAlerts = False
new_str = inputbox("Enter the prefix:")
new_path = inputbox("Save to new path:")
str_len = len(new_str)
Set prod_Doc = CATIA.ActiveDocument
Set prod = prod_Doc.Product
Set prods = prod.Products
j = 1
k =1
For i = 1 To prods.Count
if left(prods.Item(i).PartNumber,str_len)<>new_str then
if j <10 then
prods.Item(i).PartNumber = new_str&"-00"&(j)
prods.Item(i).name = "00"&(j)
else
prods.Item(i).PartNumber = new_str&"-0"&(j)
prods.Item(i).name = "0"&(j)
end if
j = j + 1
else
prods.Item(i).name = "00"&(j)&"."&(k)
k = k + 1
end if
newName = prods.Item(j).PartNumber
Set docs = CATIA.Documents
set doc1 = docs.Item(j)
doc1.SaveAs new_path & NewName & ".CATPart"
Next
End Sub