Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic "Catastrophic failure"

14 REPLIES 14
Reply
Message 1 of 15
mrattray
1277 Views, 14 Replies

iLogic "Catastrophic failure"

I have a rule controlled .idw with several rules that call each other and various API macros with views and partslists that all have their own rules.

I want the drawing to close itself without saving the changes after it's done executing all of its code (the end product is written to an excel sheet). Everything works beautiful, and the drawing does close itself like it's supposed to, except for some strange reason it throws an error message when it closes.  I've tried a few different methods of closing it.  The code below is what I want to use.  I've tried it with close set to false as well (saving changes).  I've also tried calling an API macro that's pretty similar looking. They all have the same result. The rest of the code executes just fine, and no errors are thrown if I comment out the code letting the document stay open.

I've even tried making a brand new virgin part, writing a rule with just the below code and executing it. The only difference is the error window is thrown from Inventor instead of windows.

Error message is attached.

Any thoughts? I can't figure out why such a simple code throws an error.


 

DimdocasObject

doc=ThisDoc.Document

doc.Close(True)
Mike (not Matt) Rattray

14 REPLIES 14
Message 2 of 15
Shawn_79
in reply to: mrattray

I use the same code in IV 2010 and do not have issues.

 

Only difference is I do not have the "Dim doc as object" line.  Although I tried it in a new part with that line and it executed without problems.  Best of luck, let us know what solution you come up with.

 

-Shawn

Message 3 of 15
mrattray
in reply to: Shawn_79

Just for the hell of it I tried "thisdoc.document.close(true)" on a virgin part document with the same catastrophic failure. What's strange is I did the same thing but with "thisdoc.document.close(false)" and it just didn't do anything when the rule executed. I tried this a couple of times with different templates and document types, always the same thing.

Mike (not Matt) Rattray

Message 4 of 15
mrattray
in reply to: mrattray

I learned that it was doing nothing when I ran doc.Close(False) because the file had never been saved. When I saved the virgin part file and then ran that code it saved and closed but still threw the same catastrophic failure message.

I tried writting a sub in a text file and running it from iLogic, I got a strange error message which I think meant that I was trying to run COM stuff through Inventor which isn't supported. I don't understand why you can run the code directly out of Inventor but if you run it from a text file in Inventor it's not supported. *shrug*

I also discovered that some of the code coming after the close command gets executed. This seems to apply to anything still in the code up to where another rule or macro is referenced. I tried this with multiple loops displaying message boxes after the .Close and it seems there isn't any limit to how much I could put after it unless I try to reference another rule, then it closes and stops executing at the point where the other rule is referenced. Is this by design?  It seems awefully odd to me.

I found that if I use the .Launch(filename) command before the .Close it works fine without any errors, but if I comment out the .Launch in the same file it throws the error.

Anyways, I'm still stumped on this. The only thing I can think to try at this point is using an external VB application, which I'd really prefer to avoid.

Mike (not Matt) Rattray

Message 5 of 15
Ktelang
in reply to: mrattray

I am stuck with the same problem. Is there a solution/hotfix for this.

BTW I am using 2013

 

Anyhelp 

 

Thanks

------------------------------------------------------------------------------
Config :: Intel (R) Xeon (R) CPU E31245 @ 3.30 GHz, 16.0 GB, 64bit win7
Inventor 2013 and Vault Basic 2013
-----------------------------------------------------------------------------
Message 6 of 15
mrattray
in reply to: Ktelang

Sorry, I never did figure this out.
Mike (not Matt) Rattray

Message 7 of 15
Ktelang
in reply to: mrattray

Thanks Matt for the reply. 

------------------------------------------------------------------------------
Config :: Intel (R) Xeon (R) CPU E31245 @ 3.30 GHz, 16.0 GB, 64bit win7
Inventor 2013 and Vault Basic 2013
-----------------------------------------------------------------------------
Message 8 of 15
MegaJerk
in reply to: Ktelang

I took a look at this issue and think that I have figured out the problem. 

The test code that I am using is as follows : 

 

Dim oPartDoc As Document
oPartDoc = ThisDoc.Document

If oPartDoc.DocumentType = kPartDocumentObject Then
	Dim oPartCompDef As PartComponentDefinition
	oPartCompDef = oPartDoc.ComponentDefinition
	
	Dim oParams As Parameters
	oParams=oPartCompDef.Parameters
	
	Dim oUserParams As UserParameters
	oUserParams=oParams.UserParameters  
	
	Dim oNewParameter As Parameter
	Try 
		otester = oUserParams.Item("NewParameter")
		Catch
		oNewParameter = oUserParams.AddByExpression("NewParameter", 1.5, 11272)
	End Try
	oPartDoc.Close(True)
End If 
 

 

If I open up a new part from a template and then run this code, it will create a parameter (in order to make sure that the part is dirty), and close it out to the same error (though it seems to not go to the JIT, but the typical iLogic Error dialog with all of the same text as the JIT). 

However, if you put all of that code into an external rule and run that rule directly (right click --> run rule), it doesn't fail at all. 

I think this is simply because you can't close a document from a rule, if the rule closing the document was started inside of the document to be closed. On the other hand you can close a document if the rule that is closing the document was started outside of the document to be closed. 

This means that  

Document with internal rule to close document should fail

Document with internal rule pointing to external rule to close document should fail

 

Document with external rule to close document should succeed

 

Document opened by rule, and later closed by rule, should succeed. 



Again, this is a bit speculation until you give it a shot yourself, but I do hope that it solves your problem and uncovers a bit of the mystery. 



If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
Message 9 of 15
Ktelang
in reply to: MegaJerk

Thanks for that input. I worked just fine.

Perfect!!

------------------------------------------------------------------------------
Config :: Intel (R) Xeon (R) CPU E31245 @ 3.30 GHz, 16.0 GB, 64bit win7
Inventor 2013 and Vault Basic 2013
-----------------------------------------------------------------------------
Message 10 of 15
MegaJerk
in reply to: Ktelang

That’s awesome!

Now I wonder if this wouldn’t have solved mrattray’s Problem from so long ago.



If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
Message 11 of 15
mrattray
in reply to: MegaJerk

I can actually give you an answer as soon as I wrap up my current projects. Those drawings and their associated macros are still around, in use, throwing errors, and eagerly waiting for me to try this out.
My plan is to simply write an external "close the active document" rule and call that from my internal rule. Should be simple and effective.
Mike (not Matt) Rattray

Message 12 of 15
MegaJerk
in reply to: mrattray

The method you are thinking of using will probably not work. In my tests I found that a Document with internal rule pointing to external rule to close document should fail, simply because you’re still running into the same problem. So long as you start from inside of a rule associated with the document that you’re attempting to close, it will go crazy no matter how you attempt to close it.

I think that the correct workflow would be to have an external rule that initiates the entire transaction like:

 

1)  Open the Drawing manually, or run an Application VBA macro that will open up the document.

 

2)  Run an external rule (or VBA macro) that will either do the work of the internal rules, or points to the internal rules and executes them.

 

3)  Close the document from this external rule (or VBA macro).

 

Obviously, you could just write some VBA to probably do the entire thing and it should be A-OK. Because only you know how you’re accessing your drawings (and your workflow), you probably have a better idea about how to get everything started, but sticking to the rough workflow above, everything should run without a hitch.



If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
Message 13 of 15
mrattray
in reply to: MegaJerk

You're right, because now that I'm thinking about it I realize I already tried calling an API "close doc" macro when I was trying to solve this initially.
I'm sure I can figure something out now that we know what the problem is, if I can find the time to deal with it...
Mike (not Matt) Rattray

Message 14 of 15

Did you find the time to test it?

Message 15 of 15

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report