Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Any Help Deeply appreciated

Status
Not open for further replies.

qayamraza

Aerospace
Jun 10, 2016
3
DE
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
 
 http://files.engineering.com/getfile.aspx?folder=df5f2c1c-5187-4464-a17c-0970c04375fb&file=123.jpg
Replies continue below

Recommended for you

Hello!

Why don't you use the search function?
Code:
Sub CATMain()
set Sel = CATIA.ActiveDocument.Selection 
Sel.Search "Name=BS,all"
End Sub

That way you may find the part with BS in it
 
Hello Thanks For the Reply
I can do it if all the BS having Same Colour.
I have three Harness with three different colour.
If you check the attached image you will find............
 
Hello
Still there is no reply, without any help I am not able to continue
 
is your recursive script working?

if so then just call your other macro with the BS part as argument at the right time.





Eric N.
indocti discant et ament meminisse periti
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top