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)
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
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.
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.
I am stuck with the same problem. Is there a solution/hotfix for this.
BTW I am using 2013
Anyhelp
Thanks
Thanks Matt for the reply.
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.
Thanks for that input. I worked just fine.
Perfect!!
That’s awesome!
Now I wonder if this wouldn’t have solved mrattray’s Problem from so long ago.
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.
@DRoamgave a beautiful solution to this in this thread:
Jhoel Forshav
Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website