Ilogic to turn all the parts in default representation to visible

naveedmX3N25
Contributor
Contributor

Ilogic to turn all the parts in default representation to visible

naveedmX3N25
Contributor
Contributor

Hello,

 

I am new to ilogic and have started to learn creating external rules to help my work flow.

I am currently looking for some help with the code to turn on all parts visible for the default representation. See below:

 

naveedmX3N25_0-1699303403049.png

 

0 Likes
Reply
Accepted solutions (2)
705 Views
19 Replies
Replies (19)

Frederick_Law
Mentor
Mentor

You picked something that look easy but in fact pretty complicated.

The "All Hidden" command depends on selection, in this case "Default" in View Rep.

To select "Default" you need to get the "Browser Pane".  Find "Representations" then "View" then "Default".

Select "Default" then execute "All Hidden".

Which require to find "Internal command name" of "All Hidden".

 

There is more detective work then coding 🤣

 

I was trying to sort "Titleblock", "Sketch Symbol" in drawing.

 

Using "Event Watcher" from SDK the command is:

"AssemblyAllInvisibleDesignViewCmd"

and

"AssemblyAllVisibleDesignViewCmd"

0 Likes

naveedmX3N25
Contributor
Contributor

@Frederick_Law  -

Thanks for the reply.

Got it.

I thought it was something easy. Also I wanted all Visible not all Hidden. Mistake on my side on the question.

 

Do you know of an easier way to code make all parts visible in an assembly not taking this route?

 

Thanks.

0 Likes

Frederick_Law
Mentor
Mentor

I'm almost there:

Got it:

 

 

ThisApplication.ActiveDocument.BrowserPanes.ActivePane.TopNode.BrowserNodes.Item("Representations").BrowserNodes.Item(1).BrowserNodes.Item("Default").DoSelect
ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyAllVisibleDesignViewCmd").Execute

 

 

Can't use name to get "View" because the label depends on view activated.

Actually might need to activate "Default" before setting "All Visible".

naveedmX3N25
Contributor
Contributor
Thank you!!! Works Great!
0 Likes

Frederick_Law
Mentor
Mentor

Do need to "Activate" and "Select" it again.

ThisApplication.ActiveDocument.BrowserPanes.ActivePane.TopNode.BrowserNodes.Item("Representations").BrowserNodes.Item(1).BrowserNodes.Item("Default").DoSelect 'Representation
ThisApplication.CommandManager.ControlDefinitions.Item("ActivateDesignViewCmd").Execute
ThisApplication.ActiveDocument.BrowserPanes.ActivePane.TopNode.BrowserNodes.Item("Representations").BrowserNodes.Item(1).BrowserNodes.Item("Default").DoSelect 'Representation
ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyAllVisibleDesignViewCmd").Execute

naveedmX3N25
Contributor
Contributor
I was thinking the same thing.
Thanks again!!!
0 Likes

A.Acheson
Mentor
Mentor

Hi @naveedmX3N25 

This is also possible with the inventor API which would be the preferred method over using commands. 

Dim occs As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
Dim asmDef As AssemblyComponentDefinition = ThisDoc.Document.ComponentDefinition
For Each leafOcc In asmDef.Occurrences.AllLeafOccurrences
    occs.add(leafOcc)
Next

Dim designViewRep As DesignViewRepresentation = asmDef.RepresentationsManager.DesignViewRepresentations.Item("Default")

designViewRep.SetVisibilityOfOccurrences(occs, True)

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan

naveedmX3N25
Contributor
Contributor
Thank you. This also works but you have to have default selected.
0 Likes

A.Acheson
Mentor
Mentor

To select just use activate see help page here

Syntax

DesignViewRepresentation.Activate()

 

 

 

Dim designViewRep As DesignViewRepresentation = asmDef.RepresentationsManager.DesignViewRepresentations.Item("Default")

designViewRep.Activate

 

 

Updated code

Dim occs As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
Dim asmDef As AssemblyComponentDefinition = ThisDoc.Document.ComponentDefinition
For Each leafOcc In asmDef.Occurrences.AllLeafOccurrences
    occs.add(leafOcc)
Next

Dim designViewRep As DesignViewRepresentation = asmDef.RepresentationsManager.DesignViewRepresentations.Item("Default")
designViewRep.Activate
designViewRep.SetVisibilityOfOccurrences(occs, True)

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan

naveedmX3N25
Contributor
Contributor
Hello Acheson,
One of the issue I have with code it for some reason when all the parts are visible it doesn't seem to be visible completely what I mean is when I hover over the part it doesn't select the part, only shows a box around the part. But when I manually turn OFF the visibility and turn it ON it works fine.

I am not sure how to fix the code.

Thanks
0 Likes

naveedmX3N25
Contributor
Contributor

@Frederick_Law 

 

I have been using this code for some time. Thanks to you. But I of the issue I constantly get is I have to get the representations expanded to show default for this code to work sometimes it works without expanding it and sometimes I have to manually expand it.

 

Before the code can we add anything that would expand the representations --> View so that this code works all the time.

 

Appreciate the help.

 

Thanks

0 Likes

A.Acheson
Mentor
Mentor

Hi @naveedmX3N25 

Do you have a screenshot of what your seeing? Is the part visible or not visible? Maybe there is an update needed. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes

Frederick_Law
Mentor
Mentor

Check if there is "Default" view first.

Original IV template come with "Primary" only.

Might need to create "Default".

 

I added "Default" and "Design" to my Templates.

0 Likes

naveedmX3N25
Contributor
Contributor
Same here. All of my templates have Default.
I was able to find a solution that works all the time.
Posting it below.
0 Likes

naveedmX3N25
Contributor
Contributor

I have attached the screenshot of what I see when I click on the part.

I have able to solve this with the code I have posted below.

 

 

0 Likes

naveedmX3N25
Contributor
Contributor
Accepted solution

@A.Acheson @Frederick_Law - Below is the code that works all the time. Might help someone looking to do the same.

 

Sub Main()
    Dim doc As AssemblyDocument = ThisApplication.ActiveDocument
    Dim compDef As ComponentDefinition = doc.ComponentDefinition

    ' Iterate through all components in the assembly
    For Each compOccurrence As ComponentOccurrence In compDef.Occurrences
        compOccurrence.Visible = True
    Next
End Sub

Frederick_Law
Mentor
Mentor
Accepted solution

@naveedmX3N25 wrote:

 

Before the code can we add anything that would expand the representations --> View so that this code works all the time.

 


I got it now.

Added a line to expand the node before Activate.

ThisApplication.ActiveDocument.BrowserPanes.ActivePane.TopNode.BrowserNodes.Item("Representations").BrowserNodes.Item(1).BrowserNodes.Item("Default").DoSelect 'Representation
ThisApplication.ActiveDocument.BrowserPanes.ActivePane.TopNode.BrowserNodes.Item("Representations").BrowserNodes.Item(1).BrowserNodes.Item("Default").Expanded = True
ThisApplication.CommandManager.ControlDefinitions.Item("ActivateDesignViewCmd").Execute
ThisApplication.ActiveDocument.BrowserPanes.ActivePane.TopNode.BrowserNodes.Item("Representations").BrowserNodes.Item(1).BrowserNodes.Item("Default").DoSelect 'Representation
ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyAllVisibleDesignViewCmd").Execute

 

A.Acheson
Mentor
Mentor

Hi @naveedmX3N25 

Glad to see your getting some solutions working. 

Interesting why you needed to set each occurrence visible separately. That is the purpose of "designViewRep.SetVisibilityOfOccurrences" once you supply the occurrence collection to the design view rep and select true they are all set to visible. It is working in my test so there must be something in your workflow stopping it from working. Are you using model states? I am only using primary state in 2022. 

designViewRep.SetVisibilityOfOccurrences(occs, True)

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes

naveedmX3N25
Contributor
Contributor
Not I am not using model states. Mine is also set to Primary State in inventor 2023.
0 Likes