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: 

Can't Control Visibility From Assembly

8 REPLIES 8
Reply
Message 1 of 9
tdant
878 Views, 8 Replies

Can't Control Visibility From Assembly

Hey All,

 

I frequently find myself manually hiding sketches and work planes in my assemblies. I know the view tab has an option to do it, but they all come back as soon as a new sketch or plane is created. Manually, it's a cumbersome process, so I'm writing a macro to do it for me. I've found that I can control the sketches and planes from inside the part, but when I step up a level to the parent assembly, I can't control the visibility. I have a counter in the same block as the visibility switch, and the counter is engaging, but the visibility switch is ineffective. Does anybody know what I'm doing wrong? Here's the code:

 

Sub HideAllPlanesAndSketches()
    Dim TopDoc As Document
    Set TopDoc = ThisApplication.ActiveDocument
    
    Dim TopOccs As ComponentOccurrences
    
    If TopDoc.DocumentType = kAssemblyDocumentObject Or kPartDocumentObject Then
        Set TopOccs = TopDoc.ComponentDefinition.Occurrences
    Else
        Call MsgBox("Top document is not a part or assembly file", , "Error")
    End If
    
    Dim SketchCounter As Integer
    SketchCounter = 0
    Dim PlaneCounter As Integer
    PlaneCounter = 0
    Dim Sketch As Sketch
    Dim Sketch3D As Sketch3D
    Dim WorkPlane As WorkPlane
    
    For Each Sketch In TopDoc.ComponentDefinition.Sketches
        Sketch.Visible = False
        SketchCounter = SketchCounter + 1
    Next
    
    For Each WorkPlane In TopDoc.ComponentDefinition.WorkPlanes
        WorkPlane.Visible = False
        PlaneCounter = PlaneCounter + 1
    Next
    
    If TopDoc.DocumentType = kPartDocumentObject Then
        For Each Sketch3D In TopDoc.ComponentDefinition.Sketches3D
            Sketch3D.Visible = False
            SketchCounter = SketchCounter + 1
        Next
    End If
    
    Call RecurseForSketchesPlanes(TopOccs, SketchCounter, PlaneCounter)
    
    Call MsgBox(SketchCounter & " Sketches" & vbLf & PlaneCounter & " Planes")
End Sub

Function RecurseForSketchesPlanes(Occs As ComponentOccurrences, SketchCounter As Integer, PlaneCounter As Integer)
    Dim Occ As ComponentOccurrence
    Dim Sketch As Sketch
    Dim Sketch3D As Sketch3D
    Dim WorkPlane As WorkPlane
    For Each Occ In Occs
        If Occ.Definition.Type = kPartComponentDefinitionObject Then
            For Each Sketch In Occ.Definition.Sketches
                Sketch.Visible = False
                SketchCounter = SketchCounter + 1
            Next
            
            For Each Sketch3D In Occ.Definition.Sketches3D
                Sketch3D.Visible = False
                SketchCounter = SketchCounter + 1
            Next
            
            For Each WorkPlane In Occ.Definition.WorkPlanes
                WorkPlane.Visible = False
                PlaneCounter = PlaneCounter + 1
            Next
        ElseIf Occ.Definition.Type = kAssemblyComponentDefinitionObject Then
            For Each Sketch In Occ.Definition.Sketches
                Sketch.Visible = False
                SketchCounter = SketchCounter + 1
            Next
            
            For Each Sketch3D In Occ.Definition.Sketches3D
                Sketch3D.Visible = False
                SketchCounter = SketchCounter + 1
            Next
            
            For Each WorkPlane In Occ.Definition.WorkPlanes
                WorkPlane.Visible = False
                PlaneCounter = PlaneCounter + 1
            Next
            
            Call RecurseForSketchesPlanes(Occ.SubOccurrences, SketchCounter, PlaneCounter)
        End If
    Next
End Function

 

8 REPLIES 8
Message 2 of 9
tdant
in reply to: tdant

Here's what it looks like unaltered:

Control.PNG

 

Here's the macro being run on the part:

Part.PNG

 

And here's the result on the assembly (note the counter is the same as the part plus the 3 origin planes in the assembly, but nothing was hidden):

Assembly.PNG

Message 3 of 9
MechMachineMan
in reply to: tdant

The visibility of these planes is driven from:

 

1. The Part.

2. The Occurrence Proxy.

 

If you never want the planes visible, you should change them in the part. If you want them sometimes visible, but to pop up again in every different level of the assembly, then changing the proxy/occurrence is what you want.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 4 of 9
tdant
in reply to: MechMachineMan

I never want them visible, so I'm trying to turn them off at the part level, which is what my macro is doing (I think).

Message 5 of 9
MechMachineMan
in reply to: tdant

Yes, it does look like it is changing it in the file (accessing the componentdefinition).

 

My guess would be that it's an updating thing or potential limitation of changing the visibility. 

 

Try adding a rebuild or an update to the top level, or even saving the part files after you change it.

 

Didn't look into it too deep, but these would likely be the first other things I would try.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 6 of 9
CCarreiras
in reply to: tdant

HI!

 

I understand your problem, because i suffer due this issue also.

I solve this problem easy and now... i'm nhappy..

 

Here´s my idea:

 

Why you just make a User Command tab with the tools you use often avoiding change tabs, and you can toggle on/off in a quick click? 

 

1.png

CCarreiras

EESignature

Message 7 of 9
tdant
in reply to: MechMachineMan

Alas, no combination of rebuilds/updates/levels works.

Message 8 of 9
MechMachineMan
in reply to: tdant

I don't know if it's the cause of the issue, or just a workaround, but on a hunch I tried changing the DesignViewRep of the file in the context of it's parent assembly, and it seems to work to get things right. (see bolded lines below)

 

 

Sub HideAllPlanesAndSketches()
    Dim TopDoc As Document
    Set TopDoc = ThisApplication.ActiveDocument
    
    Dim TopOccs As ComponentOccurrences
    
    If TopDoc.DocumentType = kAssemblyDocumentObject Or kPartDocumentObject Then
        Set TopOccs = TopDoc.ComponentDefinition.Occurrences
    Else
        Call MsgBox("Top document is not a part or assembly file", , "Error")
    End If
    
    Dim SketchCounter As Integer
    SketchCounter = 0
    Dim PlaneCounter As Integer
    PlaneCounter = 0
    Dim Sketch As Sketch
    Dim Sketch3D As Sketch3D
    Dim WorkPlane As WorkPlane
    
    For Each Sketch In TopDoc.ComponentDefinition.Sketches
        Sketch.Visible = False
        SketchCounter = SketchCounter + 1
    Next
    
    For Each WorkPlane In TopDoc.ComponentDefinition.WorkPlanes
        WorkPlane.Visible = False
        PlaneCounter = PlaneCounter + 1
    Next
    
    If TopDoc.DocumentType = kPartDocumentObject Then
        For Each Sketch3D In TopDoc.ComponentDefinition.Sketches3D
            Sketch3D.Visible = False
            SketchCounter = SketchCounter + 1
        Next
    End If
    
    Call RecurseForSketchesPlanes(TopOccs, SketchCounter, PlaneCounter)
    
    Call MsgBox(SketchCounter & " Sketches" & vbLf & PlaneCounter & " Planes")
End Sub

Function RecurseForSketchesPlanes(Occs As ComponentOccurrences, SketchCounter As Integer, PlaneCounter As Integer)
    Dim Occ As ComponentOccurrence
    Dim Sketch As Sketch
    Dim Sketch3D As Sketch3D
    Dim WorkPlane As WorkPlane
    For Each Occ In Occs
        If Occ.Definition.Type = kPartComponentDefinitionObject Then
            For Each Sketch In Occ.Definition.Sketches
                Sketch.Visible = False
                SketchCounter = SketchCounter + 1
            Next
            
            For Each Sketch3D In Occ.Definition.Sketches3D
                Sketch3D.Visible = False
                SketchCounter = SketchCounter + 1
            Next
            
            For Each WorkPlane In Occ.Definition.WorkPlanes
                WorkPlane.Visible = False
                PlaneCounter = PlaneCounter + 1
            Next
        ElseIf Occ.Definition.Type = kAssemblyComponentDefinitionObject Then
            For Each Sketch In Occ.Definition.Sketches
                Sketch.Visible = False
                SketchCounter = SketchCounter + 1
            Next
            
            For Each Sketch3D In Occ.Definition.Sketches3D
                Sketch3D.Visible = False
                SketchCounter = SketchCounter + 1
            Next
            
            For Each WorkPlane In Occ.Definition.WorkPlanes
                WorkPlane.Visible = False
                PlaneCounter = PlaneCounter + 1
            Next
            
            Call RecurseForSketchesPlanes(Occ.SubOccurrences, SketchCounter, PlaneCounter)
        End If
        oStr = Occ.ActiveDesignViewRepresentation
        
        If oStr = "" And Occ.IsAssociativeToDesignViewRepresentation() = False Then: oStr = "Master"
        
        Call Occ.SetDesignViewRepresentation(oStr)
    Next
End Function

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 9 of 9
dgreatice
in reply to: MechMachineMan

Hi All,

 

Don't forgot, if you set Representation View at "Master" its locked. When save and close, then open that file again, it will show workplanes and sketchs agains.

 

Set it all assembly and Sub Assembly to "Default" Representation View.

 

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report