Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

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: 

Switch between visible and hide parts in a assembly

13 REPLIES 13
SOLVED
Reply
Message 1 of 14
Anonymous
2878 Views, 13 Replies

Switch between visible and hide parts in a assembly

The issue is that in my company we until 2 yrs ago we was using thinkdesign, a very old and obsolete cad, but it has a very interesting feature: you could hide some parts and then switch between vibile and invisible parts, factually creating a sort of "otherverse" in wich the engineers could "park" some parts they want to dinamically hide in the workflow process. 

 

Listening to this specific complain i am trying to recreate this by ilogic. 

The rule as i written it now search all parts (leaf) of the tree, check one by one if they are visible (and make them invisible) and vice-versa. 

However, i am encountering a problem that i've never seen before: Impossible to find component called System.__ComObject. 

 

Any help?

 

 

    ' Get the active assembly. 
    Dim oAsmDoc As AssemblyDocument 
    oAsmDoc = ThisApplication.ActiveDocument 

    ' Get the assembly component definition. 
    Dim oAsmDef As AssemblyComponentDefinition 
    oAsmDef = oAsmDoc.ComponentDefinition 

    ' Get all of the leaf occurrences of the assembly. 
    Dim oLeafOccs As ComponentOccurrencesEnumerator 
    oLeafOccs = oAsmDef.Occurrences.AllLeafOccurrences 
    
        ' Iterate through the occurrences and print the name. 
    Dim cnt As Integer 
    cnt = 0
    
    
        Dim oOcc As ComponentOccurrence 
    For Each oOcc In oLeafOccs 
        If Component.Visible(oOcc) = True Then
        Component.Visible(oOcc) = False
            cnt = cnt + 1
            Else
            Component.Visible(oOcc) = True
            cnt = cnt + 1
        End If
             
    Next 
13 REPLIES 13
Message 2 of 14
bradeneuropeArthur
in reply to: Anonymous

Hi,

the Command "Isolate" in the context menu (Right Mouse Menu) does the same as you need.

with "Undo Isolate" you make the parts visible again.

 

Regards,

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Message 3 of 14
Anonymous
in reply to: bradeneuropeArthur

I was already aware of isolate, but i want to develope a rule or macro to be key binded as on thinkdesign it was like this and result in a feature very fast and very versatile, i feel like i would "break up the toy" if i gave them in a such articulate and unpleasant manner. 

Message 4 of 14
bradeneuropeArthur
in reply to: Anonymous

use this:

 

Public Sub main()

' Get the active assembly.
    Dim oAsmDoc As AssemblyDocument
   Set oAsmDoc = ThisApplication.ActiveDocument

    ' Get the assembly component definition.
    Dim oAsmDef As AssemblyComponentDefinition
    Set oAsmDef = oAsmDoc.ComponentDefinition

    ' Get all of the leaf occurrences of the assembly.
    Dim oLeafOccs As ComponentOccurrencesEnumerator
    Set oLeafOccs = oAsmDef.Occurrences.AllLeafOccurrences
    
        ' Iterate through the occurrences and print the name.
    Dim cnt As Integer
    cnt = 0
    
    
        Dim oOcc As ComponentOccurrence
    For Each oOcc In oLeafOccs

        If oOcc.Visible = True Then
        oOcc.Visible = False
            cnt = cnt + 1
            Else
            oOcc.Visible = True
            cnt = cnt + 1
        End If
             
    Next

End Sub

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Message 5 of 14

Hi,

 

And you don't need the Counter!!

 

Public Sub main()

' Get the active assembly.
    Dim oAsmDoc As AssemblyDocument
   Set oAsmDoc = ThisApplication.ActiveDocument

    ' Get the assembly component definition.
    Dim oAsmDef As AssemblyComponentDefinition
    Set oAsmDef = oAsmDoc.ComponentDefinition

    ' Get all of the leaf occurrences of the assembly.
    Dim oLeafOccs As ComponentOccurrencesEnumerator
    Set oLeafOccs = oAsmDef.Occurrences.AllLeafOccurrences

        Dim oOcc As ComponentOccurrence
    For Each oOcc In oLeafOccs

        If oOcc.Visible = True Then
        oOcc.Visible = False

            Else
            oOcc.Visible = True
        End If     
    Next
End Sub

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Message 6 of 14
Anonymous
in reply to: bradeneuropeArthur

I've accepted the last as solution, however in the past days i've struggle to keybind the ilogic.

I've understood that i must have a rule in all the assembly files (i've scripted it onto the template so it's in every .iam), but i cant call it from a macro in order to keybind it. 

The rules is called "test_1"

I create a macro very simple like 

Sub test()
RuniLogic "test_1"
End Sub

 

But i obtain a "Sub or Function not defined". It seems like RuniLogic is not a command. Is it possible? 

 

Message 7 of 14
tobias_wiesendanger
in reply to: Anonymous

Does it have to be iLogic? Why not create it as vba, which is easy to set a hotkey. Also you can then add your code to the default vba projetc, which is something you can maintain.

 

How would you update iLogic rules inside many diffrent assemblies?

 

regards

 

Tobias

Message 8 of 14

Good argument from @tobias_wiesendanger .

Actually the safest and best way to walk regarding usability and maintenance is to start programming add-ins.

Most reaction regarding this is "it is not easy and to complex to learn" , but it isn't.

All other mechanisms (build in code like VBA and I-ligic) make it more complex afterwards, like removing errors, updating code, maintenance etc..

 

Regards,

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Message 9 of 14
Anonymous
in reply to: bradeneuropeArthur

Ufnortunately at today i've nor the coding experience and granted the time by my company to start wandering trough vba and add-ins.

I can use ilogic because in this years i've became sufficiently proficient.

 

What are the correct form for calling an irule from inventor VBA?

Message 10 of 14
bradeneuropeArthur
in reply to: Anonymous

Hi,

 

Via Vba with I-logic use this: (more difficult)

Public Sub LaunchMyRule()

  RuniLogic "YOUR RULE NAME" 

End Sub

Public Sub RuniLogic(ByVal RuleName As String)
  Dim iLogicAuto As Object
  Dim oDoc As Document

  Set oDoc = ThisApplication.ActiveDocument
  
  If oDoc Is Nothing Then
    MsgBox "Missing Inventor Document"
    Exit Sub
  End If

  Set iLogicAuto = GetiLogicAddin(ThisApplication)
  If (iLogicAuto Is Nothing) Then Exit Sub

  iLogicAuto.RunRule oDoc, RuleName 'Name of the rule changed RunExternalRule to RunRule here if needed
End Sub

Function GetiLogicAddin(oApplication As Inventor.Application) As Object
'Find the add-in you are looking for
Dim addIn As ApplicationAddIn

On Error GoTo NotFound
Set addIn = oApplication.ApplicationAddIns.ItemById("{3bdd8d79-2179-4b11-8a5a-257b1c0263ac}")

If (addIn Is Nothing) Then Exit Function

addIn.Activate
Set GetiLogicAddin = addIn.Automation
Exit Function
NotFound:
End Function

With Vba only: (easier)

Public Sub Main()

' Get the active assembly.
    Dim oAsmDoc As AssemblyDocument
   Set oAsmDoc = ThisApplication.ActiveDocument
    ' Get the assembly component definition.
    Dim oAsmDef As AssemblyComponentDefinition
    Set oAsmDef = oAsmDoc.ComponentDefinition
    ' Get all of the leaf occurrences of the assembly.
    Dim oLeafOccs As ComponentOccurrencesEnumerator
    Set oLeafOccs = oAsmDef.Occurrences.AllLeafOccurrences
        Dim oOcc As ComponentOccurrence
    For Each oOcc In oLeafOccs
        If oOcc.Visible = True Then
        oOcc.Visible = False
            Else
            oOcc.Visible = True
        End If     
    Next
End Sub

Put both Vba rules (LaunchMyRule and Main) into your ribbon and ready to use...

 

Regards,

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Message 11 of 14
Anonymous
in reply to: Anonymous


@Anonymous wrote:

 

 

What are the correct form for calling an irule from inventor VBA?

 

 

 


this is the VBA code so i could buttons to our ribbons to lock and unlock all views... you dont need to put the code in all assemblies.. make the rule external and make sure all the machines are pointing to the same folder for the external rules and are loaded in the ilogic browser.  you can add and take away as you need...

 

-----------------------------------------------------------

Public Sub LockViews()
Dim addIn As ApplicationAddIn
Dim addIns As ApplicationAddIns
Set addIns = ThisApplication.ApplicationAddIns
For Each addIn In addIns
If InStr(addIn.DisplayName, "iLogic") > 0 Then
addIn.Activate
Dim iLogicAuto As Object
Set iLogicAuto = addIn.Automation
Exit For
End If
Next
Debug.Print addIn.DisplayName


Dim RuleName1 As String
EXTERNALrule = "LOCK VIEWS"


Dim oDoc As Document

Set oDoc = ThisApplication.ActiveDocument
If oDoc Is Nothing Then
MsgBox "Missing Inventor Document"
Exit Sub
End If

iLogicAuto.RunExternalRule oDoc, EXTERNALrule

End Sub

 

Message 12 of 14
filippo.toniello
in reply to: Anonymous

I somewhat figured out to make it work like a simple ilogiic esternal rule and it is good for small assemblies but for big asssy it is slow. I am windering if exists a kind of internal registry in inventor where it stores the current hidden elements. And if it is possibie to get this one so, i think, it would be very fast switching between hidden and visibile items, savingtsaving in a dynamic list and activating them after hiding all or making all components visible (that is a quite fast operation). This avoid to search through al leaf occurrences of the assembly. Could it be a reasonable approach?

Message 13 of 14

Maybe you need to save this state in a view and later just call it. I think that would be the easiest approach.

Message 14 of 14

i respond to myself, poking around with help and forum i "Frankensteined" a ilogic rule that works reasonably fast

 

Public Sub Main()' Inverti Visibilita'()
    Dim oDoc As Inventor.AssemblyDocument
    	oDoc = ThisApplication.ActiveDocument
    
    ' Get assembly component definition
    Dim oCompDef As Inventor.ComponentDefinition
    	oCompDef = oDoc.ComponentDefinition
   
    ' Get all occurrences from component definition for Assembly document
	Dim oCompsHid As New List(Of ComponentOccurrence)
	Dim oCompsShow As New List(Of ComponentOccurrence)
    Dim oCompOcc As ComponentOccurrence
    Dim oNel As Long
    Dim oNelHid As Long
	oNel  = 0
    oNelHid  = 0

  
	For Each oCompOcc In oCompDef.Occurrences
	
        ' Check if it's child occurrence (leaf node)
        If oCompOcc.SubOccurrences.Count = 0 Then
			If oCompOcc.Visible = False Then
				oNel  = oNel + 1
				oNelHid  = oNelHid + 1
				oCompsHid.Add(oCompOcc)
			Else 
				oNel  = oNel + 1
				oCompsShow.Add(oCompOcc)
			End If     
		Else
            Call processAllSubOcc(oCompOcc,oNel,oNelHid,oCompsHid,oCompsShow)
        End If
    Next

' If there are selected components we can do something
If oNelHid < (oNel/2) Then
	ThisApplication.ActiveDocument.ComponentDefinition.RepresentationsManager.ActiveDesignViewRepresentation.HideAll
	For Each oCompOcc In oCompsHid
		oCompOcc.Visible = True
	Next
Else  
	ThisApplication.ActiveDocument.ComponentDefinition.RepresentationsManager.ActiveDesignViewRepresentation.ShowAll
	For Each oCompOcc In oCompsShow
		oCompOcc.Visible = False
	Next
End If
End Sub 

' This function is called for processing sub assembly.  It is called recursively
' to iterate through the entire assembly tree.
Private Sub processAllSubOcc(ByVal oCompOcc As ComponentOccurrence, ByRef oNel As Long, ByRef oNelHid As Long,ByVal oCompsHid As List(Of ComponentOccurrence),ByVal oCompsShow As List(Of ComponentOccurrence))
    
    Dim oSubCompOcc As ComponentOccurrence
'	Dim oSubComps As New List(Of ComponentOccurrence)
    For Each oSubCompOcc In oCompOcc.SubOccurrences
        ' Check if it's child occurrence (leaf node)
        If oSubCompOcc.SubOccurrences.Count = 0 Then
			If oSubCompOcc.Visible = False Then
				oNel  = oNel + 1
				oNelHid  = oNelHid + 1
				oCompsHid.Add(oSubCompOcc)
			Else
				oNel  = oNel + 1
				oCompsShow.Add(oSubCompOcc)
        	End If 
		Else
            Call processAllSubOcc(oSubCompOcc,oNel,oNelHid,oCompsHid,oCompsShow)
        End If
    Next
End Sub

 

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

Post to forums  

Autodesk Design & Make Report