Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Hide / Show in a product 1

Status
Not open for further replies.

MahPLM

Computer
Jun 22, 2016
6
Hello,

I have an assembly , who contains sub-assemblies and parts.
I try to create a macro to hide all parts or products named "Test" , but it not works:


Sub CATMain()
Dim oProdDoc As ProductDocument
Set oProdDoc = CATIA.ActiveDocument
Dim oRootProd As Product
Set oRootProd = oProdDoc.Product
Dim Selection As Selection

Set Slelection = oProdDoc.Selection


Call Hide_Test(oRootProd, Selection)
End Sub

Sub Hide_Test(oInProduct, Selection1)


Dim oInstances As Products



Set oInstances = oInProduct.Product.Products
'-----No instances found then this is CATPart
If oInstances.Count = 0 Then


Selection1.Add oInProduct

If (oInProduct.PartNumber = "Test") Then

Selection1.VisProperties.SetShow catVisPropertyNoShowAttr

Else

Selection1.VisProperties.SetShow catVisPropertyShowAttr

End If

Selection1.Clear
'Exit Sub
Else
'-----Found an instance therefore it is a CATProduct

Selection1.Add oInProduct.ReferenceProduct

If (oInProduct.ReferenceProduct.PartNumber = "Test") Then

Selection1.VisProperties.SetShow catVisPropertyNoShowAttr

Else

Selection1.VisProperties.SetShow catVisPropertyShowAttr

End If

Selection1.Clear


Dim k As Integer
For k = 1 To oInstances.Count
Dim oInst As Product
Set oInst = oInstances.Item(k)
'apply design mode
oInstances.Item(k).ApplyWorkMode DESIGN_MODE
Call Hide_Test(oInst, Selection1)
Next
End If
End Sub

***
Any help please ?
 
Replies continue below

Recommended for you

Hi,

Why don't you simply search by name?

Code:
Language="VBSCRIPT"

Sub CATMain()

Dim productDocument1 As Document
Set productDocument1 = CATIA.ActiveDocument

Dim selection1 As Selection
Set selection1 = productDocument1.Selection

selection1.Search "Name=*your_name_here*,all"

End Sub

Regards
Fernando

- Romania
- EU
 
Hi Ferdo,
Thanks for your answer.
Unfortunately, i make a mistake : I want to hide parts with name different to "Test" :

If (oInProduct.PartNumber = "Test") Then

Selection1.VisProperties.SetShow catVisPropertyShowAttr

Else

Selection1.VisProperties.SetShow catVisPropertyNoShowAttr

Thanks again :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor