I am looking for a way to create an external rule that will allow me to turn off the visibility of bolt generator items in the model while I am looking at the drawing. Bolts may be burried several subassemblies (4 - 6) deep. I seem very lost on this one.
Does switch to LOD "All Content Center Suppressed" solve your problem? Or you need to filter bolts only to hide them?
Hi,
you will have to iterate to find which one to make it visible. Following is a code demo. It just finds the bolted connection in the first level of the assembly, in the first drawing view of the active sheet of a drawing document.
Sub test() Dim oDoc As DrawingDocument Set oDoc = ThisApplication.ActiveDocument Dim oActiveSheet As Sheet Set oActiveSheet = oDoc.ActiveSheet Dim oDrawingView As DrawingView Set oDrawingView = oActiveSheet.DrawingViews(1) Dim oRefDoc As AssemblyDocument Set oRefDoc = oDrawingView.ReferencedDocumentDescriptor.ReferencedDocument Dim oAssDef As AssemblyComponentDefinition Set oAssDef = oRefDoc.ComponentDefinition Dim oOcc As ComponentOccurrence For Each oOcc In oAssDef.Occurrences If oOcc.Name = "Bolted Connection:1" Then ' assume the bolted connection is in the first level of the assembly ' if other deeper level, you will need to iterate the levels the find which one ' you want to make it invisible Call oDrawingView.SetVisibility(oOcc, False) End If Next End Sub
I had to make some minor changes to get the code to run as external iLogic code.
The two changes were to add sub main to call sub test and remove Set from the code.
As the code stands now I have several issues.
1. Code does not handle renamed Bolted Connections.
ie. when Bolted Connection:1 is renamed to Frame bolts or Head Bolts
I may be able to avoid renaming the bolts but having that option may be better for others that may use this code.
2. Code does not handle more than one bolted connection
ie. Bolted Connection:1 will change but not Bolted Connections:2 or Bolted Connection:3
As I mentioned earlier a model can have many many bolted connections.
3. I understand that cycling thru views and subassemblies was not part of the demo code but that is necessary for the code to become usefull.
We only use one sheet per document so cycling thru the sheets is not necessary to me in this case but maybe nice to others.
I really appreciate anyone who helps with this.
current code attached
We often have bolts in our projects also that we do not want to have shown in drawings to resolve this we use view representation.
On bolted component identification.
Any Bolted Connection component has attribute set “FDesign” and attribute “Req” with the integer value 1.
You may traverse assembly tree at all levels and identify bolted connections by this condition.
Here is VBA sample. It scans all components at the first level and prints TRUE if this is a bolted connection component.
Sub BoltedConnectionTest() Dim oAssyDoc As AssemblyDocument Set oAssyDoc = ThisApplication.ActiveDocument Dim oAssyCompDef As AssemblyComponentDefinition Set oAssyCompDef = oAssyDoc.ComponentDefinition Dim oOccs As ComponentOccurrences Set oOccs = oAssyCompDef.Occurrences Dim oOcc As ComponentOccurrence For Each oOcc In oOccs Debug.Print oOcc.Name & " => " & IsBoltedConnection(oOcc) Next Beep End Sub Function IsBoltedConnection(ByRef oOcc As ComponentOccurrence) As Boolean IsBoltedConnection = False ' default answer = No 'DA component is an assembly If Not TypeOf oOcc.Definition Is AssemblyComponentDefinition Then Exit Function Dim oAttrSets As AttributeSets Set oAttrSets = oOcc.AttributeSets 'this is not Design Accelerator component If oAttrSets.Count = 0 Then Exit Function If Not oAttrSets.NameIsUsed("FDesign") Then Exit Function Dim oAttrSet As AttributeSet Set oAttrSet = oAttrSets.Item("FDesign") Dim oAttr As Inventor.Attribute Set oAttr = oAttrSet.Item("Req") If oAttr.Value = 1 Then IsBoltedConnection = True End Function
Inventor API Help contains the sample “Traverse an Assembly API Sample“ that shows how to recursively traverse an assembly and get access to all components and subassemblies.
Cheers,
Sorry xiaodong.liang,
I copy your code demo and change the name of component to my component name and I try to run, but it isn't working. The CALL function is not recognized. I can not understand what is wrong. I need just turn off some components in few views in my drawing. Thank you if you can help me.
Is it possible to have this example reworked to go through all drawing views and for a sub-component?
Hello,
I was looking for a solution to the same problem and came across the code you left by chance.
I wonder how to write the code in a deeper level.
thank you
Hi!, here is the code to do the recursive :
Sub Main
' Get the active assembly.
Dim oAssyDoc As AssemblyDocument
oAssyDoc = ThisApplication.ActiveDocument
' Call the function
Call TraverseAssembly(oAssyDoc.ComponentDefinition.Occurrences)
End Sub
Sub TraverseAssembly(oOccs As ComponentOccurrences)
' Iterate through all of the occurrence in this collection
Dim oOcc As ComponentOccurrence
For Each oOcc In oOccs
If oOcc.Name = "Bolted Connection:1" Then
' assume the bolted connection is in the first level of the assembly
' if other deeper level, you will need to iterate the levels the find which one
' you want to make it invisible
Call oDrawingView.SetVisibility(oOcc, False)
End If
' Recursively call sub if needed
If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
Call TraverseAssembly(oOcc.SubOccurrences)
End If
Next
End Sub
Hope it help!
Can't find what you're looking for? Ask the community or share your knowledge.