×
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

Simple macro to know if a part is visible or not

Simple macro to know if a part is visible or not

Simple macro to know if a part is visible or not

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

Thank you.

RE: Simple macro to know if a part is visible or not

Hi,

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 smile ).

Regards
Fernando

https://picasaweb.google.com/102257836106335725208

RE: Simple macro to know if a part is visible or not

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

RE: Simple macro to know if a part is visible or not

Language="VBSCRIPT"

Sub CATMain()

Dim productDocument1 As Document
Set productDocument1 = CATIA.ActiveDocument

Dim selection1 As Selection
Set selection1 = productDocument1.Selection

''''''''''''''''''''''''''''''''''''''''
selection1.Search "CATAsmSearch.Part.Visibility=Hidden,all"

MsgBox "Number of CATParts in NoShow: " & selection1.count

for k = 1 to selection1.Count

MsgBox "PartName: " & selection1.Item(k).LeafProduct.Name

next


End Sub

Regards
Fernando

https://picasaweb.google.com/102257836106335725208

RE: Simple macro to know if a part is visible or not

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

RE: Simple macro to know if a part is visible or not

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

Thank you.

RE: Simple macro to know if a part is visible or not

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.

Regards
Fernando

https://picasaweb.google.com/102257836106335725208

RE: Simple macro to know if a part is visible or not

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

RE: Simple macro to know if a part is visible or not

One ideea it would be to select what you want (let say a specific part number), open in new window, use SaveAs, close the document, next....

Regards
Fernando

https://picasaweb.google.com/102257836106335725208

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