Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Hide component in a view on the drawing

tomislav.peran
Advocate

Hide component in a view on the drawing

tomislav.peran
Advocate
Advocate

Hello,

 

Does anybody have an example of a code used to hide a component in a certain view on the drawing? 

 

I have added an assembly onto the sheet but I would like to hide some components in one of the views (not all

 

views). 

 

If anybody has an example please let me know. 

 

Regards,

Tom

0 Likes
Reply
Accepted solutions (1)
937 Views
5 Replies
Replies (5)

Michael.Navara
Advisor
Advisor

This is the function from my active project

This function will hides all occurrences in the "basView" except the "occ". Argument "asm" is referenced document of "baseView"

 

private static void HideOtherOccurrences(AssemblyDocument asm, ComponentOccurrence occ, DrawingView baseView)
{
    Point2d position = baseView.Position;
    foreach (ComponentOccurrence occurrence in asm.ComponentDefinition.Occurrences)
    {
        baseView.SetVisibility(occurrence, occurrence == occ);
    }

    baseView.Position = position;
}

 

0 Likes

tomislav.peran
Advocate
Advocate

Hi Michael,

 

Thank you for your help. I apologize for my lack of understanding of how code works but If I put your code in Inventor I get a lot of errors. I assume this code is not used in Inventor? 

 

I would like precisely the opposite then what your code does. To hide only one component in one of the projected views. And if possible in the form I can put in inventor like:

 

Dim oDrawingDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oSheet As Sheet = oDrawingDoc.Sheets.Item(1)
Dim oView2 As DrawingView etc...

I hope that I am making some sense :grinning_face_with_smiling_eyes:

 

Tom

0 Likes

Michael.Navara
Advisor
Advisor

This code is written in C#. You need to convert them to iLogic/VB.net like this one. This code hides specific occurrence in the drawing view and show others.

If you want, you can keep hidden occurrences hidden (check baseView.GetVisibility(occ)), pass multiple occurrences as parameter, etc.  

Sub Main()

    Dim drw As DrawingDocument = ThisDoc.Document
    Dim baseView As DrawingView = drw.ActiveSheet.DrawingViews(1)
    Dim asm As AssemblyDocument = baseView.ReferencedDocumentDescriptor.ReferencedDocument
    Dim occ As ComponentOccurrence = asm.ComponentDefinition.Occurrences(1)

    HideOccurrence(asm, occ, baseView)

End Sub

Private Sub HideOccurrence(asm As AssemblyDocument, occ As ComponentOccurrence, baseView As DrawingView)

    Dim position As Point2d = baseView.Position
    For Each occurrence As ComponentOccurrence In asm.ComponentDefinition.Occurrences
        baseView.SetVisibility(occurrence, occurrence IsNot occ)
    Next

    baseView.Position = position
End Sub

 

0 Likes

tomislav.peran
Advocate
Advocate

Thanks, Michael, I will look into it.

 

Btw,  I have a friend who has been working as a Java developer for the last 20 years. He told me specifically to stay away from C# or C++ due to its complexity :slightly_smiling_face: 

 

Regards,

Tom

 

 

 

0 Likes

tomislav.peran
Advocate
Advocate
Accepted solution

Here is what I had in mind. This is really part specific and can be used to show parts in the drawing which might be hidden in assembly. It is useful for standard assemblies/drawings.

 

Found this @ https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/ilogic-to-remove-component-visibilit...

 

Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument
    
Dim oActiveSheet As Sheet
oActiveSheet = oDoc.ActiveSheet
    
Dim oDrawingView As DrawingView
oDrawingView = oActiveSheet.DrawingViews(1)
    
Dim oRefDoc As AssemblyDocument
oRefDoc = oDrawingView.ReferencedDocumentDescriptor.ReferencedDocument
    
Dim oAssDef As AssemblyComponentDefinition
oAssDef = oRefDoc.ComponentDefinition
    
Dim oOcc As ComponentOccurrence
	
For Each oOcc In oAssDef.Occurrences
		
       If oOcc.Name = "Arrow up:1" Then

          Call oDrawingView.SetVisibility(oOcc, True)
       End If
	   
	   If oOcc.Name = "Arrow down:1" Then

          Call oDrawingView.SetVisibility(oOcc, True)
       End If       
    Next
    

Regards,

Tom

0 Likes