Scripting help
Scripting help
(OP)
I have been working on a script to go through an entire product to rename all part numbers and instances by taking the starting part number and adding a "C" and a revision handler. A seemingly simple task which is proving to be quite difficult. I have attached the code I have been working with. I have gotten it to go through the tree and rename the partnumber for both CATProducts and CATParts and rename the instance name for CATProducts, but cannot get the code to rename the instance name for CATParts and any level other than the active document level in the catia tree.





RE: Scripting help
Win XP64
R20/21, 3DVIA Composer 2012, ST R20
Dell T7400 16GB Ram
Quadro FX 4800 - 1.5GB
RE: Scripting help
RE: Scripting help
try this
catscript
Public StringToReplace As String
Sub CATmain()
Dim myproduct As Product
Set myproduct = CATIA.ActiveDocument.Product
StringToReplace = "XXX"
'msg to tell what your adding
Msg = "THIS WILL ADD (C (XXXX)_Rev--) TO PART NUMBER"
Question = MsgBox(Msg, vbYesNo, "Warning")
If Question = vbNo Then
Exit Sub
End If
' Change the PartNumber of the Root Product
PartNumberRoutine myproduct, StringToReplace
' Launch the scan of the complete product structure
ScanProductStructure myproduct, StringToReplace
myproduct.Update
MsgBox "Finished"
End Sub
'---------------------------------------------------------------------------------------------
' Scanning all the Product Structure, all levels
'-------------------------------------------------------------------------------------------
Sub ScanProductStructure(Myprod As Product, StringToReplace1 As String)
Dim currentprod As Product
Dim Num1 As String
' Info : CATIAProduct.Products Gets collection of Products
For i = 1 To Myprod.Products.Count
Set currentprod = Myprod.Products.Item(i)
If currentprod.Products.Count <> 0 Then 'it is a product
Num1 = currentprod.PartNumber
PartNumberRoutine currentprod, StringToReplace1
ScanProductStructure currentprod.ReferenceProduct, StringToReplace1
Else: InstanceNameRoutine currentprod, StringToReplace1 ' it is a part
PartNumberRoutine currentprod, StringToReplace1
End If
Next
End Sub
'------------------------------------------------------------------------------------
' Sub Routine Change PartNumber
'------------------------------------------------------------------------------------
' thsi Routine will:
' - Scan the PartNumber
' - Find the StringToReplace
' - Replace this string by the new one
'------------------------------------------------------------------------------------
Sub PartNumberRoutine(Myprod As Product, StringToReplace1 As String)
Dim PartNumber1 As String
Dim MyPos2 As Integer
Dim LengthName2 As Integer
Dim NamePartNumber1 As String
Dim NamePartNumber2 As String
Dim NamePartNumber3 As String
Dim NamePartNumber4 As String
Dim ItemNumber As String
Set parameters1 = Myprod.Parameters
On Error Resume Next
ItemNumber = ""
Set strParam1 = parameters1.GetItem("ItemNumber")
ItemNumber = strParam1.Value
PartNumber1 = Myprod.PartNumber
'need to add what you (what your adding) so that the script does not add again
If InStr(Myprod.PartNumber, "_Rev--") Then
'MsgBox "no 2"
Else:
Myprod.PartNumber = "C" & PartNumber1 & "_Rev--"
End If
End Sub