qayamraza
Aerospace
- Jun 10, 2016
- 3
Hello Everyone
I am working as a electrical design engineer. I want to create a macro in VBA to Clean (Hide geometric set, Set Layer for Bodies and change the colour of rib) electrical bundle.
I have attached image of the Product structure.
My Aim is
1. Walk down on the Tree
2. Select the part (not by User) but through coding condition for selecting part is having “BS” in the naming and then do the cleaning.
3. I have three Geometric bundle and all the geometric bundle having one “BS” part. Different “BS” could have different Colour.
I am getting the Part with “BS” after that I am not able to select that Part through Code…………..
Please see the attached image of Product structure
Wright now I am running separately all the macros, like for changing colour one macro, hiding geometric set one , setting layer one and that to with pre selection of each BS separately.
Please see the code below
--------------------------------------------------------------
Option Explicit
Sub CATMain()
'Get the Current Catia Assembly
Dim oProdDoc As ProductDocument
Set oProdDoc = CATIA.ActiveDocument
Dim oRootProd As Product
Set oRootProd = oProdDoc.Product
'Begin scrool Down the Specification tree
Call WalkDownTree(oRootProd)
End Sub
'WalkDownTree is a recursive function to scroll down the specification tree and output names of each item
Sub WalkDownTree(oInproduct As Product)
Dim oInstances As Products
Set oInstances = oInproduct.Products
'-----------No Instances found then this is a Catpart--------------------
If oInstances.Count = 0 Then
MsgBox "This is a CatPart With Part Number " & oInproduct.PartNumber
If Mid(oInproduct.PartNumber, 17, 2) = "BS" Then
Dim String1 As String
String1 = oInproduct.PartNumber
MsgBox String1
Dim EditBundle As Product
Set EditBundle = CATIA.Documents.Item(String1)
Dim objSelection As Selection
MsgBox "This is a MultiBranchable With Part Number " & oInproduct.PartNumber
End If
Exit Sub
End If
'---------- Found an Instance therefore it is a CATproduct----------------
'MsgBox "This is a CATProduct With Part Number " & oInproduct.ReferenceProduct.PartNumber
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 WalkDownTree(oInst)
Next
End Sub
I am working as a electrical design engineer. I want to create a macro in VBA to Clean (Hide geometric set, Set Layer for Bodies and change the colour of rib) electrical bundle.
I have attached image of the Product structure.
My Aim is
1. Walk down on the Tree
2. Select the part (not by User) but through coding condition for selecting part is having “BS” in the naming and then do the cleaning.
3. I have three Geometric bundle and all the geometric bundle having one “BS” part. Different “BS” could have different Colour.
I am getting the Part with “BS” after that I am not able to select that Part through Code…………..
Please see the attached image of Product structure
Wright now I am running separately all the macros, like for changing colour one macro, hiding geometric set one , setting layer one and that to with pre selection of each BS separately.
Please see the code below
--------------------------------------------------------------
Option Explicit
Sub CATMain()
'Get the Current Catia Assembly
Dim oProdDoc As ProductDocument
Set oProdDoc = CATIA.ActiveDocument
Dim oRootProd As Product
Set oRootProd = oProdDoc.Product
'Begin scrool Down the Specification tree
Call WalkDownTree(oRootProd)
End Sub
'WalkDownTree is a recursive function to scroll down the specification tree and output names of each item
Sub WalkDownTree(oInproduct As Product)
Dim oInstances As Products
Set oInstances = oInproduct.Products
'-----------No Instances found then this is a Catpart--------------------
If oInstances.Count = 0 Then
MsgBox "This is a CatPart With Part Number " & oInproduct.PartNumber
If Mid(oInproduct.PartNumber, 17, 2) = "BS" Then
Dim String1 As String
String1 = oInproduct.PartNumber
MsgBox String1
Dim EditBundle As Product
Set EditBundle = CATIA.Documents.Item(String1)
Dim objSelection As Selection
MsgBox "This is a MultiBranchable With Part Number " & oInproduct.PartNumber
End If
Exit Sub
End If
'---------- Found an Instance therefore it is a CATproduct----------------
'MsgBox "This is a CATProduct With Part Number " & oInproduct.ReferenceProduct.PartNumber
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 WalkDownTree(oInst)
Next
End Sub