View Suppression When Part is suppressed

View Suppression When Part is suppressed

Anonymous
Not applicable
1,430 Views
16 Replies
Message 1 of 17

View Suppression When Part is suppressed

Anonymous
Not applicable

I have a model which uses iLogic to change the size from a form. I have a drawing linked to this file.  There is a part that is either on or suppressed depending on the size. I would like to suppress the view of this part in the drawing when it is suppressed in the model.  I have found the ActvieSheet,View command and can turn the view off but how do I access the model and the part that is suppressed from the drawing to use the command and suppress the view based on the state of the part? Thanks, John

0 Likes
1,431 Views
16 Replies
Replies (16)
Message 2 of 17

Anonymous
Not applicable

 

Here is a simple example of an iLogic rule to be placed in the drawing. I would recommend adding an event trigger on Drawing view change.

 

 

	'Set our application and active document
Dim oApp As Application = ThisApplication
Dim oDwgDoc As DrawingDocument = oApp.ActiveDocument

	'Declare variables to use
Dim SubDoc As ComponentOccurrence
Dim oView As DrawingView
Dim oOccs As ComponentOccurrences

'Variables to control selection of view, assemblydoc, and sub part
ViewNumber = 1
RefDocNumber = 1
PartName = "MyPart" 'Set our view to control oView = oDwgDoc.ActiveSheet.DrawingViews.Item(ViewNumber) 'Set the list of occurrences from our referenced assembly oOccs = oDwgDoc.ReferencedDocuments(RefDocNumber).ComponentDefinition.Occurrences 'Select and set the partDoc oSubDoc = oOccs.ItemByName(PartName) 'Perform our suppression action based on the If oSubDoc.Suppressed Then oView.Suppressed = True Else oView.Suppressed = False End If

 

Best Regards,

Tyler Boni

 

Please Mark as Solution if this is your answer!

 

0 Likes
Message 3 of 17

Anonymous
Not applicable

Tyler,

Thanks for your response.  The view I need to suppress is View 13 on sheet 3.  Does the sheet need to be activated prior to calling the view? My part name is M600 Stiffener Flange.  Does that go in the Part Name Statement? What is the RefDocNumber=1 looking for? My document name is M600 Blower Extension Assembly is that it.  Thanks for all your help. John

0 Likes
Message 4 of 17

Anonymous
Not applicable

Also when I run I get this error message:

 

System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
   at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
   at Inventor.DrawingViews.get_Item(Int32 Index)
   at LmiRuleScript.Main()
   at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
   at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

Thanks, John

0 Likes
Message 5 of 17

Anonymous
Not applicable

John,

 

I have revised the code to be a little better for your situation, and a little better in general. The view does not need to be on the activesheet for this to work.

 

-SheetName is the name of the sheet seen in the model browser.

 

 

-ViewNumber is the index of the view on any (1) sheet.

 

IE: We have set oSheet to the sheet named "MySheet:1". 

This Sheet only contains "View3" and "View4".

The index of "View3" is 1

The index of "View4" is 2

 

-PartName should be the name of the part that is shown in the model browser in your assembly. 

 

 

'Set our application and active document
Dim oApp As Application = ThisApplication
Dim oDwgDoc As DrawingDocument = oApp.ActiveDocument

	'Declare objects to use
Dim oSubDoc As ComponentOccurrence
Dim oSheet As Sheet
Dim oView As DrawingView
Dim oViewDoc As AssemblyDocument
Dim oOccs As ComponentOccurrences


'Variables to control selection of view, assemblydoc, and sub part
SheetName = "MySheet:1" 'the name of the sheet seen in the model browser.
ViewNumber = 1          'the index of the view on any (1) sheet.
PartName = "MyPart"     'the name of the part that is shown in the model browser in your assembly. 

	'Set the sheet to control
oSheet = oDwgDoc.Sheets.Item(SheetName)

	'Set our view to control
oView = oSheet.DrawingViews.Item(1)

	'Set the document contained in our view
oViewDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument

	'Set the list of occurrences from our referenced assembly
oOccs = oViewDoc.ComponentDefinition.Occurrences

	'Select and set the partDoc
oSubDoc = oOccs.ItemByName(PartName)

	'Perform our suppression action based on the 
If oSubDoc.Suppressed Then
	oView.Suppressed = True
Else
	oView.Suppressed = False
End If

 

I removed the generic Reference doc code, and instead grabbed the document that is consumed by the view we selected. Both work, but this is a better solution because we always want to referencing the assembly document in the selected view.

 

I know this can be confusing. I would suggest learning how to use the vba editor to see the architecture of the objects. It will make understanding all of this a lot easier. There are plenty of tutorials on creating macros.

 

Let me know if you would like more explanation.

 

Best Regards,

Tyler Boni

 

Please Mark as Solution if this is your answer!

0 Likes
Message 6 of 17

Anonymous
Not applicable

Tyler, thanks for helping.  I will be the first to admit I am not very good at this and need to get some training or find tutorials.  I have taken your suggested code and put it in a rule and added my information.  Not sure if I did it correctly but here it is:

 

 

'Set our application and active document
Dim oApp As Application = ThisApplication
Dim oDwgDoc As DrawingDocument = oApp.ActiveDocument

    'Declare objects to use
Dim oSubDoc As ComponentOccurrence
Dim oSheet As Sheet
Dim oView As DrawingView
Dim oViewDoc As AssemblyDocument
Dim oOccs As ComponentOccurrences


'Variables to control selection of view, assemblydoc, and sub part
SheetName = "Sheet:3" 'the name of the sheet seen in the model browser.
ViewNumber = 2          'the index of the view on any (1) sheet.
PartName = "M600 Stiffener Flange"     'the name of the part that is shown in the model browser in your assembly. 

    'Set the sheet to control
oSheet = oDwgDoc.Sheets.Item(SheetName)

    'Set our view to control
oView = oSheet.DrawingViews.Item(1)

    'Set the document contained in our view
oViewDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument

    'Set the list of occurrences from our referenced assembly
oOccs = oViewDoc.ComponentDefinition.Occurrences

    'Select and set the partDoc
oSubDoc = oOccs.ItemByName(PartName)

    'Perform our suppression action based on the 
If oSubDoc.Suppressed Then
    oView.Suppressed = True
Else
    oView.Suppressed = False
End If

When I run it I get this error:

Error in rule: Rule2, in document: M600 Blower Extension Assembly.idw

Unable to cast COM object of type 'System.__ComObject' to interface type 'Inventor.AssemblyDocument'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{29F0D465-C114-11D2-B77F-0060B0F159EF}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

 

System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'Inventor.AssemblyDocument'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{29F0D465-C114-11D2-B77F-0060B0F159EF}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
   at LmiRuleScript.Main()
   at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
   at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

Not sure what I am doing wrong but I appreciate your help. John

0 Likes
Message 7 of 17

Anonymous
Not applicable

John,

 

I see one error in the code i sent. Fixed in red below. Give this a shot.

 

 

'Set our application and active document
Dim oApp As Application = ThisApplication
Dim oDwgDoc As DrawingDocument = oApp.ActiveDocument

    'Declare objects to use
Dim oSubDoc As ComponentOccurrence
Dim oSheet As Sheet
Dim oView As DrawingView
Dim oViewDoc As AssemblyDocument
Dim oOccs As ComponentOccurrences


'Variables to control selection of view, assemblydoc, and sub part
SheetName = "Sheet:3" 'the name of the sheet seen in the model browser.
ViewNumber = 2          'the index of the view on any (1) sheet.
PartName = "M600 Stiffener Flange"     'the name of the part that is shown in the model browser in your assembly. 

    'Set the sheet to control
oSheet = oDwgDoc.Sheets.Item(SheetName)

    'Set our view to control
oView = oSheet.DrawingViews.Item(ViewNumber)

    'Set the document contained in our view
oViewDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument

    'Set the list of occurrences from our referenced assembly
oOccs = oViewDoc.ComponentDefinition.Occurrences

    'Select and set the partDoc
oSubDoc = oOccs.ItemByName(PartName)

    'Perform our suppression action based on the 
If oSubDoc.Suppressed Then
    oView.Suppressed = True
Else
    oView.Suppressed = False
End If

  

I am going to guess that error is because the view the code was trying to update did not contain an assembly.

 

 

0 Likes
Message 8 of 17

Anonymous
Not applicable

John,

 

Just to clarify, is the view we are suppressing a view of the assembly, or is it only a view of the part that is suppressed in the assembly?

 

I apologize if I misunderstood.

 

 

0 Likes
Message 9 of 17

Anonymous
Not applicable

I am trying to suppress the drawing view if the part is suppressed in the main assembly.  The view is on sheet 3 and is view 13.  The part that may or may not be suppressed is M600 Flange Stiffener.  Hope this helps.  Thanks, John

0 Likes
Message 10 of 17

Anonymous
Not applicable

John,

 

Is the view of JUST the part?

 

If yes, then here is some code that should be close. If this does not work, I would request that you send copies of the files we are working with to have a better idea of what the issue is. If this is not possible I understand!

 

 

	'Set our application and active document
Dim oApp As Application = ThisApplication
Dim oDwgDoc As DrawingDocument = oApp.ActiveDocument

	'Declare variables to use
Dim SubDoc As ComponentOccurrence
Dim oView As DrawingView
Dim oOccs As ComponentOccurrences

'Variables to control selection of view, assemblydoc, and sub part
ViewNumber = 2
RefDocNumber = 1
PartName = "M600 Stiffener Flange"

	'Set our view to control
oView = oDwgDoc.ActiveSheet.DrawingViews.Item(ViewNumber)

	'Set the list of occurrences from our referenced assembly
oOccs = oDwgDoc.ReferencedDocuments(RefDocNumber).ComponentDefinition.Occurrences

	'Select and set the partDoc
oSubDoc = oOccs.ItemByName(PartName)

	'Perform our suppression action based on the 
If oSubDoc.Suppressed Then
	oView.Suppressed = True
Else
	oView.Suppressed = False
End If

 

0 Likes
Message 11 of 17

Anonymous
Not applicable

Tyler, thanks for all your help.  I will try the code you sent.  To clarify, what I have is a 3-D model that changes size depending on user input into a box form.  Depending on the size I have an iLogic rule that either leaves the M600 Stiffener Flange suppressed in the model or turns it on.  I have a drawing file associated with the model and when the M600 Stiffener Flange is suppressed I want view 13 on sheet 3 to be suppressed.  When M600 Stiffener Flange is turned on, I want the view to be visible.  Hope this makes sense.  John

0 Likes
Message 12 of 17

Anonymous
Not applicable

An explanation of the RefDocNumber,

 

Every drawing contains a list of reference documents. These are the part/assembly/ipn documents that are shown in the views.

 

If you click Manage->Replace Model Reference you will see a list of these reference docs. RefDocNumber should be the same as the position in this list of the ASSEMBLY that contains the iLogic rule to suppress the part.

 

 

0 Likes
Message 13 of 17

Anonymous
Not applicable

So should I replace RefDocNumber with the path shown in the Manage>Replace Model Reference?  Thanks, John

0 Likes
Message 14 of 17

Anonymous
Not applicable

No, it should be an integer. If the path is 1st on the list, RefDocNumber = 1.

0 Likes
Message 15 of 17

Anonymous
Not applicable

Changed RefDocNumber to =5 as it is the fifth line.  Still getting this error:

 

Error in rule: Rule3, in document: M600 Blower Extension Assembly.idw

Not implemented (Exception from HRESULT: 0x80004001 (E_NOTIMPL))

 

System.NotImplementedException: Not implemented (Exception from HRESULT: 0x80004001 (E_NOTIMPL))
   at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
   at Inventor.ComponentOccurrences.get_ItemByName(String Name)
   at LmiRuleScript.Main()
   at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
   at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

0 Likes
Message 16 of 17

Anonymous
Not applicable

John

 

Unfortunately, without being able to see the documents we are working with I am not sure I can help much more. If you would like more explanation as to what the code I sent is performing let me know. My suggestion would be to follow some tutorials about VBA macros in inventor and then refer back to what I have sent and see if you can work through it.

0 Likes
Message 17 of 17

Anonymous
Not applicable

Thanks for all your help Tyler.

0 Likes