How to pull Visibility status from an assembly into .idw to turn flat patterns on or off

How to pull Visibility status from an assembly into .idw to turn flat patterns on or off

jared.kauffman
Observer Observer
411 Views
5 Replies
Message 1 of 6

How to pull Visibility status from an assembly into .idw to turn flat patterns on or off

jared.kauffman
Observer
Observer

Hello,

 

I work with large assemblies of parts that vary in style and function depending on the customer, but use a base model for each and have some automation to help with that.

 

In the .idw I have a bunch of flat patterns set up and right now its a manual process to turn these off when they are not needed before I send these drawings out. 

 

I've made some code that will turn flat patterns on or off depending on a parameter, but I'm wondering if there is any way to pull in the status of the inventor part itself, read if that part is currently visible or not, and use that as the determining factor to have a flat pattern turn on or off instead of a created parameter.

 

'' Suppresses/unsupresses views based on if they are on/off in the iLogic menu
'' NOTE: Parameters/views can be selected/seen from the model tab above

' Initializes variables "odoc" and "oSheet"
odoc = ThisDoc.Document
Dim oSheet As Sheet

' If parameter is turned off in the iTrigger menu, then
If Component.Visible("MK HAT SECTION:1")=True Then '<- this is the bit of code that does not work. 
	
' For each Sheet in the document (Code inside will run on every sheet - allows sheet order to be changed)
    For Each oSheet In odoc.Sheets
		
		' Initializes variable "oView"
        Dim oView As DrawingView
		
		' For each DrawingView on the sheet (Runs through every view that the sheet has"
        For Each oView In oSheet.DrawingViews
			
			' Initializes the selection of oView based on the sheet name
            Select Case oView.Name
				
				' Selects which view(s) you want to control
                Case "VIEW53"
				
					' Suppresses the selected views
                    oView.Suppressed = True
					
			' Terminates selection
            End Select

		' Terminates inner for loop
        Next
		
	' Terminates outer for loop
    Next

' If Cabinet 1 is NOT 0 in the iTrigger menu
' Works the same as above, but oView.Suppressed is false turns the view back onCould add more If statements To Replace “else”
Else
	
    For Each oSheet In odoc.Sheets
        Dim oView As DrawingView
        For Each oView In oSheet.DrawingViews    
            Select Case oView.Name
                Case "VIEW53"
                    oView.Suppressed = False
            End Select
        Next
    Next

' Terminates the if statement
End If
0 Likes
412 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor

Hi @jared.kauffman.  This might end up a bit more complicated than you were hoping for.  That iLogic shortcut snippet 'Component.Visible()' is wanting to target either the same document that the rule is saved within, if your rule is saved within the drawing, or the 'active' document, which is still most likely the drawing document.  It is meant for use while an assembly is the active document.  So, you will most likely have to forego the shortcut, and use a lot more code to dig down into the model document being referenced within the view, then find the component by looping through all the components within.  Is the component always going to be in the top level of the assembly (not within any sub assembly), or will it sometimes be down within a sub assembly (lower levels)?  To get to the assembly model document, you can use the DrawingView.ReferencedDocumentDescriptor.ReferencedDocument.  That property returns an Object type though, so you will have to pre-define the variable as Document or AssemblyDocument, so that you can benefit from the 'Intellisense' help after that point.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 6

Ralf_Krieg
Advisor
Advisor

Hello

 

In addition to @WCrihfield 

The document referenced in the drawing view can not only appear in different subassembly levels, it can also appear multiple times in any level but in different visibility states. If a subassembly is inserted 2 times within the main assembly and only one of them is invisible, suppress view or not?


R. Krieg
RKW Solutions
www.rkw-solutions.com
Message 4 of 6

WCrihfield
Mentor
Mentor

Just dropping a link here to another similar sounding post I responded to today, in case it might help you out any.

https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/grabbing-visibility-parameters-from-... 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 6

Ralf_Krieg
Advisor
Advisor

Hello

 

Just a first try.  I try the way from view to model.

- walk through every sheet

- grab every view on sheet

- grab  the referenced document of the view

- get all occurrences of this document

- walk through all occurrences, filter out occurrences in subassemblies and filter out all 2nd, 3rd and so on occurrence in the same (sub)assembly

- as result we get the first occurrence of the document in main assembly

- if this occurrence is invisible, we suppress the view, otherwise we unsuppress it

 

PLEASE, save all your work before. I did not have a drawing with multiple sheets and views to test this. This script may have errors and crash Inventor.

Dim oDrawDoc As DrawingDocument = ThisDrawing.Document
Dim oAssDoc As AssemblyDocument = ThisDrawing.ModelDocument
Dim oRefedDoc As Document
Dim oSheet As Sheet
Dim oView As DrawingView
Dim oOccs As ComponentOccurrencesEnumerator

For Each oSheet In oDrawDoc.Sheets
	For Each oView In oSheet.DrawingViews
		oRefedDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument
		oOccs = oAssDoc.ComponentDefinition.Occurrences.AllReferencedOccurrences(oRefedDoc)
		If oOccs.Count> 0 Then
			For Each oOcc As ComponentOccurrence In oOccs
				If oOcc.ParentOccurrence Is Nothing Then
					If oOcc.Name.EndsWith(":1") Then
						If oOcc.Visible = False Then
							oView.Suppressed = True
						Else
							oView.Suppressed = False
						End If
						Exit For
					End If
				End If
			Next
		End If
	Next
Next

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 6 of 6

jared.kauffman
Observer
Observer

Thank you! I will try these out this week! sorry for the slow response we get limited time for automation improvements due to workload. thank you again for the time!

0 Likes