Component Occurrence Visibility in Drawing View

Component Occurrence Visibility in Drawing View

tdant
Collaborator Collaborator
2,616 Views
4 Replies
Message 1 of 5

Component Occurrence Visibility in Drawing View

tdant
Collaborator
Collaborator

Hello All,

 

I'm trying to turn off visibility for all part occurrences named "break representation" in a drawing document. Here's what I've come up with so far:

 

Sub HideBreakRepresentationsInDrawing()
    
    Dim Counter As Integer
    Counter = 0
    
    If ThisApplication.Documents.Count <> 0 Then
        Dim Doc As DrawingDocument
        Set Doc = ThisApplication.ActiveDocument
    Else
        Call MsgBox("No open documents")
        Exit Sub
    End If
    
    Dim Sheets As Sheets
    Set Sheets = Doc.Sheets
    
    'recurse all sheets in drawing document
    Dim Sheet As Sheet
    For Each Sheet In Sheets
        Dim Views As DrawingViews
        Set Views = Sheet.DrawingViews 'recurse views here
        
        'recurse all drawing views in sheet
        Dim View As DrawingView
        For Each View In Views
            'assumes the drawing view references an assembly
            If View.ReferencedDocumentDescriptor.ReferencedDocumentType = kAssemblyDocumentObject Then
                Dim RefDoc As AssemblyDocument
                Set RefDoc = View.ReferencedDocumentDescriptor.ReferencedDocument
            
                'recurse all components in assembly referenced by view
                Call recurseOccurrences(RefDoc.ComponentDefinition.Occurrences, Counter)
            End If
        Next
    Next
    
    Call MsgBox(Counter)
End Sub

Function recurseOccurrences(Occurrences As ComponentOccurrences, Counter As Integer)
    Dim Occurrence As ComponentOccurrence
    For Each Occurrence In Occurrences
        If Occurrence.DefinitionDocumentType = kAssemblyDocumentObject Then
            'found assembly, find subparts
            Call recurseOccurrences(Occurrence.SubOccurrences, Counter)
        ElseIf Occurrence.DefinitionDocumentType = kPartDocumentObject And InStr(LCase(Occurrence.Name), "break representation") Then
            'do something to a part
            Occurrence.Visible = False
            Counter = Counter + 1
        End If
    Next
End Function

My counter returns 34, so I know the script is finding what I want it to find, but none of the part occurrences are affected. Does ComponentOccurrence.Visible = False not work in the drawing environment or something?

0 Likes
Accepted solutions (1)
2,617 Views
4 Replies
Replies (4)
Message 2 of 5

MechMachineMan
Advisor
Advisor

Somewhat correct.

 

The call you are making is changing the ASSEMBLY DOCUMENT, not the Drawing Document.

 

I think to make that work there are 2 steps you can take:

1. Use a Design View in your drawing views that is neither Master, nor Locked.

2. Ensure the Views are set to be Assosciative to Design view (the chain link in the edit view window).

 

There is not really a ton of support for changing visibility of specific occurrences in drawings through api otherwise.


--------------------------------------
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 3 of 5

tdant
Collaborator
Collaborator

I need to avoid changing the assembly document if at all possible. So basically, there's no way to control drawing document occurrence visibility from the API? That seems weird.

0 Likes
Message 4 of 5

MechMachineMan
Advisor
Advisor
Accepted solution

No.

 

It seems Autodesk's supported workflow is to use Design View Reps from the assembly to control occurrence visibility in ALL cases.

 

Being able to change it in a drawing is a simple override to allow users to still get the job done if they don't understand the preferred workflow. If they were to add-in API control to all of the overrides that would just allow improper workflow to proliferate.


--------------------------------------
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
0 Likes
Message 5 of 5

Anonymous
Not applicable

Hi together,

 

also this is an old thread i would answer for others who read this in future.

 

It is possible to change the visibility of occurences in drawing views.

 

Just use the

DrawingView.SetVisibility(Occurence, True/False)

switch

 

It has to be done for each drawing view on the sheet(s)

 

This method was introduced in Inventor 11

 

 

Greetz