Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scripting help

Status
Not open for further replies.

SaberRaide

Aerospace
Oct 14, 2008
17
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.
 
Replies continue below

Recommended for you

I wish I could just provide you the code but I am not that strong at scripting, but I can tell you why it is happening. The parent product is the container that holds the instance name of the CATPart. You set Set ActDoc = CATIA.ActiveDocument which is the Root assembly. This will only change the CATParts under the root assembly. One fix to this would be to open each product in it's own window to make it the root assembly.



Win XP64
R20/21, 3DVIA Composer 2012, ST R20
Dell T7400 16GB Ram
Quadro FX 4800 - 1.5GB
 
Solved. If I change from recursiveprod.products.item(i).Name to recursiveprod.ReferenceProduct.products.item(i).Name the code will refer to the proper instance name and thus correctly change the instance name.
 
I use this type of script to get through a lot of editing

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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor