Hi,
I am stuck with a macro, I hope you could help me.I am trying to write a short macro to go thru each one of the parts in a product and just let me know if it's visible or not.
Shouldn't be so complicated, use search function for parts inside assembly, count parts, see if each one of them is visible (or hidden) , if condition is true (or false) then write in a text file part name (or use a message).
Can we see what you've done up to now ? If I remember correctly I've posted a macro which is putting in show all hidden parts and products (but frankly speaking I'm not so sure I really did it ).
I tried two different ways. Option one: Check every parts in the product and report if it's visible or not.
For iProduct = 1 To oParent.Products.Count
Set oChild = oParent.Products.Item(iProduct)
If oChild.Parameters.Count <> 0 Then
If oChild.Parameters.Item(oChild.Parameters.Count).ValueAsString = "true" Then <----Original code which I wanted to change to check the visibility
frmGXCreator.lstParts.AddItem oChild.PartNumber
Set params = oParent.Products.Item(iProduct).Parameters
If oChild.Products.Count = 0 Then
' oChild.PartNumber = oChild.PartNumber & "_" & strAppend
' SaveAsPartNumber oChild.ReferenceProduct
Else
WalkThroughTree oChild.ReferenceProduct
End If
End If
End If
Next
Option two: Search and select only visible parts. The part I cannot do is to check the properties of each one of the selected items.
Dim MySel
Set MySel = CATIA.ActiveDocument.Selection
MySel.Clear
MySel.Search ("'Assembly Design'.Part.Visibility=Visible")
MsgBox MySel.Item(1).Name
For iProduct = 1 To MySel.Count
''
''Code to check each one of the selected parts
''
Next iProduct
Thanks Fernando, It worked fine. I tried to improve the code by adding
for k = 1 to selection1.Count
MsgBox "PartName: " & selection1.Item(k).LeafProduct.Name
selection1.Item(k).LeafProduct.saveas("C:\" & k & ".CATPart") <----line added
next
...but it didn't work. Could you help me out once more.
So far my program does the following:
-Read the existing files in a folder e.g. GX001.CATPart, GX002.CATPart, etc.
-Create a list of the visible parts in the Product. <---Done with your code, thanks.
-Propose and alternative name for the visible parts with the next sequential GX-number
-Product save as GX003.CATProduct
-Save AS each one of the visible parts in the product as GX004.CATPart, GX005.CATPart, and so on <---this is the next step which I cannot make it work so far.
I have previous experience writing code in VB and VBA but I have recently started with CATIA so I still do not know the objects/methods/properties of CATIA in VBA.
Well, I believe CATIA already have a tool....use Save Management with Patern Name saving...and search v5automation.chm file for more info about CATIA automation.
What you want it can be done, but it takes a little time to do it.
I've used Pattern Name saving before but that is not exactly what I am trying to do. I want to give them a completely new and unique name to each of the visible parts in the product.
So far I've been using v5automation.chm as my main source of information.
Thank you