×
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

Reordering instance numbers

Reordering instance numbers

Reordering instance numbers

(OP)
Hi guys. Could anyone please help me with a problem... This macro does not go trough and I don't know what I'm doing wrong. I'm running it on a structure attached in post. The macro does not rename Product2/Part2 (Part2.2) to (Part2-temp.4).

Thanks
Roman


Option Explicit
Sub CATMain()

Dim productDocument1 As Document
Set productDocument1 = CATIA.ActiveDocument
If InStr(CATIA.ActiveDocument.Name, ".CATProduct") < 1 Then
MsgBox ("Active CATIA Document is not a Product. Open a Product file and run this script again.")
Exit Sub
End If

Call reorder_item(productDocument1.Product)

End Sub

Sub reorder_item(oproduct)

Dim i, j, k As Integer
Dim oproducts As Products

Set oproducts = oproduct.Products

For i = 1 To oproducts.Count
If oproducts.Item(i).Products.Count > 0 Then
Call reorder_item(oproducts.Item(i))
End If
k = 0
For j = 1 To i
If oproducts.Item(j).PartNumber = oproducts.Item(i).PartNumber Then
k = k + 1
End If
Next

If i <> oproducts.Count Then
For j = i + 1 To oproducts.Count
If oproducts.Item(j).PartNumber = oproducts.Item(i).PartNumber Then
If oproducts.Item(j).Name = oproducts.Item(i).PartNumber & "." & k Then
oproducts.Item(j).Name = oproducts.Item(i).PartNumber & "-temp." & j
MsgBox (oproducts.Item(j).Name & " " & j)
End If
End If
Next
End If
oproducts.Item(i).Name = oproducts.Item(i).PartNumber & "." & k
Next
End Sub


RE: Reordering instance numbers

As far as I know there is no direct VBA support for products reordering. Only way how to do it is to use some CUT & PASTE operations (not suitable for large assemblies and also you can break some links), or connect to "Graph tree reordering" window and simulate user. But in your code you are not doing any reordering, you just try to rename instance number, right?

Tesak
http://scripts4all.eu/txtoncurve/ - Curved text for Catia V5

RE: Reordering instance numbers

(OP)
exactly

RE: Reordering instance numbers

But second option is quite good workaround and it is nice programming challenge :)

Tesak
http://scripts4all.eu/txtoncurve/ - Curved text for Catia V5

RE: Reordering instance numbers

i did this trick way back then with my first recursive instance renaming script (sorry can't share).

What I did was a two pass system:

first pass would rename all instances to part.name & "." & (i+1000000)

second pass would just remove 1000000 from all instance number

I used a Dictionary to count the instances in first pass.

I used this 2 pass system because I could not be sure that the first pass would not use a number already used but not found yet.

Eric N.
indocti discant et ament meminisse periti

RE: Reordering instance numbers

(OP)
2 passes would definitely help me and I'll try to rework mine code, but it is still not clear to me why this script refuses to change name in lines:

oproducts.Item(j).Name = oproducts.Item(i).PartNumber & "-temp." & j
MsgBox (oproducts.Item(j).Name & " " & j)

Message box shows old name though it is clearly given a new value that does not exist in any other place. If I run this script only on main product (transfer "Call reorder_item(oproducts.Item(i))" in comment), then it goes trough.

RE: Reordering instance numbers

Hi guys,
this is nice, but not a real solution for product reordering problem.

Tesak
http://scripts4all.eu/txtoncurve/ - Curved text for Catia V5

RE: Reordering instance numbers

(OP)
Product reordering isn't really a topic of this thread. I just want someone to tell me what am I doing wrong with my scipt.

RE: Reordering instance numbers

Try changing the Product you are passing to the Subroutine:

If oproducts.Item(i).Products.Count > 0 Then
Call reorder_item(oproducts.Item(i).ReferenceProduct)
End If

When you are processing the instances in the Subassemblies you will need to make sure you are obtaining the Product object from the 'ReferenceProduct' property of that subassembly before parsing through the Products collection to modify the instances in that subassembly.

RE: Reordering instance numbers

Your code works without any problem on my machine, although it is not making any changes in sub-assemblies. Is this your problem?

Tesak
http://scripts4all.eu/txtoncurve/ - Curved text for Catia V5

RE: Reordering instance numbers

(OP)
Thanks dougsnell ... solved

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