×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Scripting help

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

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

RE: Scripting help

(OP)
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.  

RE: Scripting help

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources