Error when I first run an ilogic rule after opening inventor.

Error when I first run an ilogic rule after opening inventor.

AdamAG99T
Advocate Advocate
747 Views
4 Replies
Message 1 of 5

Error when I first run an ilogic rule after opening inventor.

AdamAG99T
Advocate
Advocate

I have made an ilogic rule to quickly copy sheets in a drawing rather than manually using the workaround of copying and pasting into a separate drawing file and then copying it back. The ilogic uses the same workaround, simply copying the currently active sheet to an empty drawing file I created for this purpose. However the first time I run this rule after opening inventor I get an error saying "Unable to cast object of type 'Inventor._DocumentClass' to type 'Inventor._DrawingDocument'." Every time I run the rule after that it works perfectly with no errors. I'm curious if anyone knows why this may be happening, as it's been annoying to troubleshoot considering I need to restart inventor every time I want to test a possibly fix. I am using the most recent version of inventor 2019.

Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisDoc.Document

Dim oActiveSheet As Sheet
oActiveSheet = oDrawDoc.ActiveSheet

CopyNumString = InputBox("Number of copies of current sheet?", "Copy current sheet", 1)
	
Try
	CopyNum=CDbl(CopyNumString)
Catch
	MessageBox.Show("Must imput a number")
	Return
End Try	


Dim CopyDest As DrawingDocument
CopyDest=ThisApplication.Documents.Open("FILE PATH TO BLANK DRAWING DOCUMENT", False)

Dim oCopySheet As Sheet
oCopySheet = oActiveSheet.CopyTo(CopyDest)
	
	
While CopyNum>0
	oCopySheet.CopyTo(oDrawDoc)
	CopyNum = CopyNum - 1
		
End While
oCopySheet.Delete

 

0 Likes
Accepted solutions (1)
748 Views
4 Replies
Replies (4)
Message 2 of 5

bradeneuropeArthur
Mentor
Mentor

Does this help:

Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisDoc.Document

Dim oActiveSheet As Sheet
oActiveSheet = oDrawDoc.ActiveSheet

CopyNumString = InputBox("Number of copies of current sheet?", "Copy current sheet", 1)
	
Try
	CopyNum=CDbl(CopyNumString)
Catch
	MessageBox.Show("Must imput a number")
	Return
End Try	


Dim CopyDest As DrawingDocument
CopyDest=ThisApplication.Documents.Open("FILE PATH TO BLANK DRAWING DOCUMENT", False)

Dim oCopySheet As Sheet
oCopySheet = oActiveSheet.CopyTo(CopyDest)

oDrawDoc.Activate
	
While CopyNum>0
	oCopySheet.CopyTo(oDrawDoc)
	CopyNum = CopyNum - 1
		
End While
oCopySheet.Delete

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 3 of 5

AdamAG99T
Advocate
Advocate

Unfortunately it still gives the same error with that change. 

Screenshot_6.png

0 Likes
Message 4 of 5

Sergio.D.Suárez
Mentor
Mentor
Accepted solution

 

Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisDoc.Document

Dim oActiveSheet As Sheet
oActiveSheet = oDrawDoc.ActiveSheet

CopyNumString = InputBox("Number of copies of current sheet?", "Copy current sheet", 1)
	
Try
	CopyNum=CDbl(CopyNumString)
Catch
	MessageBox.Show("Must imput a number")
	Return
End Try	


Dim CopyDest As DrawingDocument
CopyDest=ThisApplication.Documents.Open("FILE PATH TO BLANK DRAWING DOCUMENT", True)


Dim oCopySheet As Sheet
oCopySheet = oActiveSheet.CopyTo(CopyDest)
	
	
While CopyNum>0
	oCopySheet.CopyTo(oDrawDoc)
	CopyNum = CopyNum - 1
		
End While
oCopySheet.Delete
CopyDest.Close

Hi, I think the error occurs on the line
oActiveSheet.CopyTo (CopyDest)
Try the following code, open the template in true mode, but I have not seen the error, in the end it closes the template, which was something that seemed to me wrong. regards 


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes
Message 5 of 5

AdamAG99T
Advocate
Advocate

Thank you, that prevents the error but I'm curious why opening the file in False instead of True would fail exactly one time, and then work perfectly every other time I run the code until I restart inventor. 

0 Likes