- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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 ![]()
Tom
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
Regards,
Tom
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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