Assembly level visibility tools

Assembly level visibility tools

Anonymous
Not applicable
568 Views
4 Replies
Message 1 of 5

Assembly level visibility tools

Anonymous
Not applicable

I've been working for quite a while to create some assembly level tools for controlling visibilities for work features.

The situation is that in our office we commonly work with very large, multi-level, assemblies and I'm trying to figure

out a way to quickly hide or show all those work features that are nested in subassemblies on different levels.

 

I've implemented the part level code that Curtis Waguespack posted on his blog in another tool, where he used the referenced documents from the assembly. However, getting the same kind of behavior in an assembly environment is really stumping me, and the use of view representations is hardly making it easier.

Below you can see what I'm trying to do:

 

example.jpg

 

As you can see I have assembly level work features in the top, sub1 and sub2 levels. I'm trying to write my code so that it would traverse down the assembly hierarchy, identify work features of choice and set their visibility.

 

The issues that are preventing me from doing this as far as my understanding goes are:

  • I cannot identify the type of Occurrence in the assembly tree, thus I cannot see if the occurrence is a work feature or not.
  • View representations are messing with what my code can do when it goes deeper down in the hierarchy? If someone could explain, or link to a good explanation of view representation behavior when nesting assemblies, I would be incredibly grateful.

What I've been able to achieve so far is to set visibility for the top level assemblys' work features, or set visibility for *all* occurrences since I can't check what kind of object they are.

 

As far as I can tell, what I'm trying to do should be entirely possible, since the manual way of doing it is to just right click on each of the work planes in the image and disable visibility, so it all happens in the context of the top assembly and its "Default" view rep if I'm not mistaken.

 

Sorry if I went on for quite long here, I just wanted to clarify the issue and my thoughts on this. I hope someone can shed some light on it and, in the worst case, just let me know that this is not possible with iLogic code.

 

Best regards,

Tommy

0 Likes
569 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable

TommySWE:

 

I take it that you know you can use the View tab in the Ribbon to control the Workfeatures. I use "Alt+], Alt+/ & Alt+." all the time to turn these on and off. I do wish that they would stay off when I activate the "Master" View Representation.

 

Workfeatures.gif

0 Likes
Message 3 of 5

Anonymous
Not applicable

I know those checkboxes exist, but if someone wants to turn all of the, say, 200 work planes off in the assembly only to switch a few of them back on to work with, then the object visibility toggles are useless, as all the work planes will become visible again.

 

I feel like I'm missing something crucial here, because it seems like the functionality that I'm looking to create is such an incredibly basic thing.

 

Thanks for your input though, let me know if you think of something else.

0 Likes
Message 4 of 5

GosponZ
Collaborator
Collaborator

I do have this one and using daily. Hope it will help you

 

'Attribute VB_Name = "Hide_Sketches_And_planes"
Sub Hide_Sketches_And_planes()

'catch and skip errors
On Error Resume Next

    ' Get the active document.
    Dim oDoc As Document
    Set oDoc = ThisApplication.ActiveDocument

    If oDoc.DocumentType = kAssemblyDocumentObject Then
    Call HideAssemblyComponents

    ElseIf oDoc.DocumentType = kPartDocumentObject Then
    Call HidePartComponents

    Else
    MsgBox ("The active file is no assembly or part. Script can't be used here.")
    Exit Sub
    End If
    
End Sub

Private Sub HideAssemblyComponents()

Dim oAsmDoc As AssemblyDocument
Set oAsmDoc = ThisApplication.ActiveDocument
'get user input as True or False
Dim Vis As Boolean
Dim result
result = MsgBox("Hide all sketches and workplanes?" & vbCrLf & vbCrLf & "Click Yes to hide all sketches and workplanes." & vbCrLf & "Click No to Show all sketches and worplanes.", vbYesNoCancel)
Select Case result
    Case vbYes
        Vis = False
    Case vbNo
        Vis = True
    Case vbCancel
        Exit Sub
End Select
'catch and skip errors
On Error Resume Next

Dim oSetch As PlanarSketch
Dim oWorkPlane As WorkPlane
Dim oDoc As Inventor.Document

'Iterate tru all referenced documents and change visibility
For Each oDoc In oAsmDoc.AllReferencedDocuments
    For Each oWorkPlane In oDoc.ComponentDefinition.WorkPlanes
    oWorkPlane.Visible = Vis
    Next
    'set work axis visibility
    For Each oWorkAxis In oDoc.ComponentDefinition.WorkAxes
    oWorkAxis.Visible = Vis
    Next
    'set work point visibility
    For Each oWorkPoint In oDoc.ComponentDefinition.WorkPoints
    oWorkPoint.Visible = Vis
    Next
    For Each oSketch In oDoc.ComponentDefinition.Sketches
    oSketch.Visible = Vis
    Next
Next

'change visibility from active assembly document
For Each oWorkPlane In oAsmDoc.ComponentDefinition.WorkPlanes
    oWorkPlane.Visible = Vis
    Next
    'set work axis visibility
    For Each oWorkAxis In oAsmDoc.ComponentDefinition.WorkAxes
    oWorkAxis.Visible = Vis
    Next
    'set work point visibility
    For Each oWorkPoint In oAsmDoc.ComponentDefinition.WorkPoints
    oWorkPoint.Visible = Vis
    Next
    For Each oSketch In oAsmDoc.ComponentDefinition.Sketches
    oSketch.Visible = Vis
    Next
    
ThisApplication.ActiveDocument.Update
End Sub

Private Sub HidePartComponents()

Dim oPartDoc As PartDocument
Set oPartDoc = ThisApplication.ActiveDocument
'get user input as True or False
Dim Vis As Boolean
Dim result
result = MsgBox("Hide all sketches and workplanes?" & vbCrLf & vbCrLf & "Click Yes to hide all sketches and workplanes." & vbCrLf & "Click No to Show all sketches and worplanes.", vbYesNoCancel)
Select Case result
    Case vbYes
        Vis = False
    Case vbNo
        Vis = True
    Case vbCancel
        Exit Sub
End Select

Dim oSetch As PlanarSketch
Dim oWorkPlane As WorkPlane
Dim oDoc As Inventor.Document
'change visibility from active part document
For Each oWorkPlane In oPartDoc.ComponentDefinition.WorkPlanes
    oWorkPlane.Visible = Vis
    Next
    'set work axis visibility
    For Each oWorkAxis In oPartDoc.ComponentDefinition.WorkAxes
    oWorkAxis.Visible = Vis
    Next
    'set work point visibility
    For Each oWorkPoint In oPartDoc.ComponentDefinition.WorkPoints
    oWorkPoint.Visible = Vis
    Next
    For Each oSketch In oPartDoc.ComponentDefinition.Sketches
    oSketch.Visible = Vis
    Next
ThisApplication.ActiveDocument.Update
End Sub


 

0 Likes
Message 5 of 5

Anonymous
Not applicable

Thanks for your input MisterZS!

 

I tried your code, and it works pretty much as well as my own code this far. Your code manages to Show/Hide all planes/points in my assembly *except* for the work plane in the first subassembly (the red box second from the bottom). I cannot wrap my head around why this is happening, as I run my own code that looks like this:

 

Sub Main()

'define the active assembly
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = oDoc.ComponentDefinition 'Make sure "object visibility" is set to show everything oDoc.ObjectVisibility.AllWorkFeatures() = True
'Create boolean and get choice from dialog Dim wfBoolean As Boolean wfBoolean = InputRadioBox("Set visibility", "True", "False", True, Title := "Title") 'Set Top level work feature visibility SetVisibility(wfBoolean, oDoc) 'Traverse through the assembly occurrences and set work plane visibilities For Each oOcc In oAsmCompDef.Occurrences If Not TypeOf oOcc.Definition Is VirtualComponentDefinition Then If oOcc.DefinitionDocumentType = kPartDocumentObject Or oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then 'If the occurrence is an assembly document, check its definition for work planes and set visibility If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then Dim oWorkPlanes As WorkPlanes oWorkPlanes = oOcc.Definition.WorkPlanes For Each oWorkPlane In oWorkPlanes oWorkPlane.Visible = wfBoolean InventorVb.DocumentUpdate() Next End If End If 'If there are suboccurrences, iterate through them too If oOcc.SubOccurrences.Count <> 0 Then processAllSubOcc(oOcc, wfBoolean) End If End If Next End Sub 'Process all suboccurrences Private Sub processAllSubOcc(ByRef inOcc As ComponentOccurrence, ByRef inState As Boolean) Dim visState As Boolean visState = inState For Each oSubCompOcc In inOcc.SubOccurrences If oSubCompOcc.DefinitionDocumentType = kAssemblyDocumentObject Then Dim oWorkPlanes2 As WorkPlanes oWorkPlanes2 = oSubCompOcc.Definition.WorkPlanes For Each oWorkPlane2 In oWorkPlanes2 MsgBox(oWorkPlane2.Name) oWorkPlane2.Visible = visState InventorVb.DocumentUpdate() Next 'If the suboccurrence has suboccurrences, iterate them too (this loops until leaf nodes) If oSubCompOcc.SubOccurrences.Count <> 0 Then processAllSubOcc(oSubCompOcc, visState) End If End If Next End Sub 'Set work feature visibilities Private Sub SetVisibility(ByRef oState As Boolean, ByRef AssyDoc As AssemblyDocument) 'set work plane visibility For Each oWorkPlane In AssyDoc.ComponentDefinition.WorkPlanes oWorkPlane.Visible = oState Next End Sub

 

I think it has something to do with the subassembly switching view reps? Unfortunately your code changes the view rep in the actual subassemblies, which is not desireable for us as someone might have spent time setting up their visibilities in the active view rep in the subassembly, and the rule would wipe that all out. I'm considering adding a new view rep called "iLogic" to prevent destroying someone's work. The rule I'm trying to build runs only in the active assembly level, and it seems so close to working.. Just that one work plane left that wont abide - its really weird because I can follow the rules' progress with message boxes with the names of the occurrences it finds, and it does find the work plane in question, but it doesnt set its visibility?

0 Likes