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 ?
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 ?