Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic to remove component visibility from drawings enviroment

10 REPLIES 10
Reply
Message 1 of 11
Dis-Daraco
2223 Views, 10 Replies

iLogic to remove component visibility from drawings enviroment

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.

10 REPLIES 10
Message 2 of 11

Does switch to LOD "All Content Center Suppressed" solve your problem? Or you need to filter bolts only to hide them?


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 3 of 11

I am trying to prevent bolt, washer, nut, beveled washer ect from showing in the drawings but still have them show up in the bom.

We are currently sorting thru the browser for each view and looking for each bolt and turning off the visibility. In a large model with thousands of bolts this can take quite some time.
Message 4 of 11
xiaodong_liang
in reply to: Dis-Daraco

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

 

Message 5 of 11
Dis-Daraco
in reply to: xiaodong_liang

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

 

 

Message 6 of 11
david.campbell
in reply to: Dis-Daraco

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.

Inventor 2013
Message 7 of 11

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, 


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 8 of 11
rbrilho
in reply to: xiaodong_liang

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.

Message 9 of 11
jhdietz
in reply to: xiaodong_liang

Is it possible to have this example reworked to go through all drawing views and for a sub-component?

Message 10 of 11
ysbaodnj
in reply to: xiaodong_liang

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

Message 11 of 11

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! 

 


Logo MCMCAD
https://mcmcad.com/

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report