iLogic error with folding sheet metal

iLogic error with folding sheet metal

SharkDesign
Mentor Mentor
593 Views
4 Replies
Message 1 of 5

iLogic error with folding sheet metal

SharkDesign
Mentor
Mentor

I am using the following code to automatically create a flat pattern when I save a sheet metal document.

 

Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument
Dim State As SheetMetalComponentDefinition
State=oDoc.ComponentDefinition
If State.HasFlatPattern = False Then
State.Unfold 
End If

 

 

The problem comes when I insert this part into an assembly. When the sheet metal part has been edited and I save the assembly I get the following error:

Error in rule: unfold, in document: Part19.ipt

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

 

More Info tab:

System.InvalidCastException: Unable to cast COM object of type 'Inventor._DocumentClass' to interface type 'Inventor.PartDocument'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{29F0D463-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)

 

Any ideas?

  Inventor Certified Professional
0 Likes
594 Views
4 Replies
Replies (4)
Message 2 of 5

Curtis_Waguespack
Consultant
Consultant

Hi jameswillo,

 

Give this a try.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

'Loop through any and all referenced documents
For Each oDoc In ThisApplication.ActiveDocument.AllReferencedDocuments	
	'look at only sheet metal parts
	If oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
	
		Dim State As SheetMetalComponentDefinition
		State = oDoc.ComponentDefinition
		
		If State.HasFlatPattern = False Then
			'create flat pattern
			State.Unfold 
			
			'flip back to folded model	
			State.FlatPattern.ExitEdit	
			
			'close the file
			oDoc.Close(True) 'True skips the save 
			
		End If
	End If
Next

'update assembly
InventorVb.DocumentUpdate()

EESignature

0 Likes
Message 3 of 5

SharkDesign
Mentor
Mentor

I'm assuming you put this code in the assembly rather than the part?

 

Am I right in thinking that if my assembly is very large this will massively increase my save time if it's going through every sheet metal part?

  Inventor Certified Professional
0 Likes
Message 4 of 5

adam.nagy
Autodesk Support
Autodesk Support

Hi,

 

If the rule is triggered when the assembly is active then this is the part that will fail causing error "Unable to cast COM object of type 'Inventor._DocumentClass' to interface type 'Inventor.PartDocument'" because it's an assembly document:

oDoc = ThisApplication.ActiveDocument

Instead, you should work with the document that the rule resides in:

oDoc = ThisDoc.Document

 

Cheers, 



Adam Nagy
Autodesk Platform Services
0 Likes
Message 5 of 5

SharkDesign
Mentor
Mentor

Ahhhh, that makes sense. Thanks, I'll try that. 

  Inventor Certified Professional
0 Likes