Hello,
I have been working on some iLogic code where I am trying to save a bmp of the model. I have it to run on close of the document but I keep running into a couple issues. First randomly this will rotate the drawing to an ISO image when the model has already been closed. Second I get an error if I close the model while having the drawing open. It will not run the command and tries to run when closing the drawing and gives me an error. How can I specify to run only if its an .ipt or .iam not a .dwg or .idw. I have this set to execute on close of document because of running into issues with having it not save the files with the part number after save. We seemed to have some lag and it required the user to hit save twice in order to save the image.
Any help or advice would be appreciated.
Here is my code I currently have.
oFileName = ThisDoc.FileName(False)
Dim m_Camera As Inventor.Camera
Dim m_Doc As Inventor.Document
Dim m_TO As Inventor.TransientObjects
m_TO = ThisApplication.TransientObjects
m_Doc = ThisDoc.Document
m_Camera = ThisApplication.ActiveView.Camera
'm_Camera.Perspective = True
m_Camera.ViewOrientationType = Inventor.ViewOrientationTypeEnum.kIsoTopLeftViewOrientation
m_Camera.Fit
m_Camera.ApplyWithoutTransition
Dim m_CV as Inventor.View
m_CV = ThisApplication.ActiveView
Dim m_PrevMode As Integer
Dim m_Disp3D As Boolean
m_PrevMode = m_CV.DisplayMode
m_Disp3D = ThisApplication.DisplayOptions.Show3DIndicator
m_CV.DisplayMode = Inventor.DisplayModeEnum.kSHADEDWITHEDGESRendering
ThisApplication.DisplayOptions.Show3DIndicator = False
'MessageBox.Show(m_CV.DisplayMode)
m_CV.Update
m_Camera.SaveAsBitmap("T:\inventor workspace\inventor labels\"& oFileName &".bmp", 800, 600, m_TO.CreateColor(255,255,255))
m_CV.DisplayMode = m_PrevMode
ThisApplication.DisplayOptions.Show3DIndicator = m_Disp3D
m_CV.Update
Solved! Go to Solution.
Solved by MjDeck. Go to Solution.
Hi beth.maddux,
So try this version with the file type check and using the Before Save event, note I changed the output path for my testing to c:\Temp, so be sure to change that back.
Edit: I just realized that maybe you're needing to run this after save or on close, because the file name = part number hasn't happened yet for new documents when using the Before Save?
Also just as a tip, you can search and ask programming questions of this type on the Inventor Customization forum too:
http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/bd-p/120
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Dim m_Doc As Inventor.Document m_Doc = ThisDoc.Document If m_Doc.DocumentType <> kAssemblyDocumentObject _ And m_Doc.DocumentType <> kPartDocumentObject Then MessageBox.Show("File is not a model.", "iLogic") Return 'exit rule End If Dim m_Camera As Inventor.Camera Dim m_TO As Inventor.TransientObjects m_TO = ThisApplication.TransientObjects oFileName = ThisDoc.FileName(False) m_Camera = ThisApplication.ActiveView.Camera 'm_Camera.Perspective = True m_Camera.ViewOrientationType = Inventor.ViewOrientationTypeEnum.kIsoTopLeftViewOrientation m_Camera.Fit m_Camera.ApplyWithoutTransition Dim m_CV as Inventor.View m_CV = ThisApplication.ActiveView Dim m_PrevMode As Integer Dim m_Disp3D As Boolean m_PrevMode = m_CV.DisplayMode m_Disp3D = ThisApplication.DisplayOptions.Show3DIndicator m_CV.DisplayMode = Inventor.DisplayModeEnum.kSHADEDWITHEDGESRendering ThisApplication.DisplayOptions.Show3DIndicator = False m_CV.Update m_Camera.SaveAsBitmap("C:\Temp\"& oFileName &".bmp", 800, 600, m_TO.CreateColor(255,255,255)) m_CV.DisplayMode = m_PrevMode ThisApplication.DisplayOptions.Show3DIndicator = m_Disp3D m_CV.Update
Yes we have it set on close because of it not putting the part number into the file. So I put this in our template and I am getting the same error this happens when I close the model and then make changes to the drawing. Then I go to save and close the drawing and then it gives me an error about the document being set. Does that make sense to you? Same as my drawings are still rotating but it happens when you open another drawing and close it then the one you didn't close rotates. I just am stuck at why it keeps doing this and I am not sure how to stop it.
Hi beth.maddux,
I have a general idea of what might be happening, so I'll try to have another look and post back later.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Hi beth.maddux,
I still can't get the rule to run on the Close Document event ( I put a message box at the end as a test).
I tried this as an external rule and an internal rule.
But I do see that if I set this rule to run on the assembly close event, and then save and close the model file, and then save and close an open drawing file that references that same model, I get the error you mentioned coming from this rule.
I don't understand it, but maybe @MjDeck knows something about the Close Document event trigger that would help us understand what is happening.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
When you close a drawing, it will also close all its referenced model documents (unless they are open in a separate window).
Try adding this to the top of the rule:
If ThisApplication.ActiveView.Document IsNot ThisDoc.Document Then Return
(Note: IsNot is one word.)
That will prevent the rule from doing anything when thw document is being closed from a drawing.
I am still getting errors if I have the drawing open and then close the model the rule will not run.
If ThisApplication.ActiveView.Document IsNot ThisDoc.Document Then Return
Dim m_Doc As Inventor.Document
m_Doc = ThisDoc.Document
If m_Doc.DocumentType <> kAssemblyDocumentObject _
And m_Doc.DocumentType <> kPartDocumentObject Then
MessageBox.Show("File is not a model.", "iLogic")
Return 'exit rule
End If
Dim m_Camera As Inventor.Camera
Dim m_TO As Inventor.TransientObjects
m_TO = ThisApplication.TransientObjects
oFileName = ThisDoc.FileName(False)
m_Camera = ThisApplication.ActiveView.Camera
'm_Camera.Perspective = True
m_Camera.ViewOrientationType = Inventor.ViewOrientationTypeEnum.kIsoTopLeftViewOrientation
m_Camera.Fit
m_Camera.ApplyWithoutTransition
Dim m_CV as Inventor.View
m_CV = ThisApplication.ActiveView
Dim m_PrevMode As Integer
Dim m_Disp3D As Boolean
m_PrevMode = m_CV.DisplayMode
m_Disp3D = ThisApplication.DisplayOptions.Show3DIndicator
m_CV.DisplayMode = Inventor.DisplayModeEnum.kSHADEDWITHEDGESRendering
ThisApplication.DisplayOptions.Show3DIndicator = False
m_CV.Update
m_Camera.SaveAsBitmap("T:\inventor workspace\inventor labels\"& oFileName &".bmp", 800, 600, m_TO.CreateColor(255,255,255))
m_CV.DisplayMode = m_PrevMode
ThisApplication.DisplayOptions.Show3DIndicator = m_Disp3D
m_CV.Update
@MjDeck wrote:
When you close a drawing, it will also close all its referenced model documents (unless they are open in a separate window).
Try adding this to the top of the rule:
If ThisApplication.ActiveView.Document IsNot ThisDoc.Document Then Return(Note: IsNot is one word.)
That will prevent the rule from doing anything when thw document is being closed from a drawing.
Hi MjDeck,
Ah-ha. So that helps me understand the Close Document event.
If you close the model when the drawing is still open the Close Document event does not fire the rule, because the document is still open from Inventor's view point.
However, even with the addition of the line you suggested I still see the error when I have both the model and the drawing open and I close the model, then close the drawing. Attached are some example file with the rule as an internal rule in the part.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Add another test to the top of the rule. Put the tests in this order:
If ThisApplication.ActiveView Is Nothing Then Return
If ThisApplication.ActiveView.Document IsNot ThisDoc.Document Then Return
okay that worked kind of.... So now I no longer get the error but how do I get it to run the rule in the model when I close that first? So I don't get the error anymore when I close the drawing but now its not running the rule on my model.
I don't think you can use the ActiveView if you want it to work from a drawing. But there's another way to set up a camera and capture an image, without using a View. See the attached rule. There are some differences in the way the display options work in this case. One difference: it uses the background color that you provide to SaveAsBitmap. So the background will be white (255, 255, 255). You can change that.
Hi MjDeck,
That version worked for me, hopefully it works for beth.maddux too.
Thanks!
Curtis
If you use my version of the rule (not using ActiveView) then you can set the rule to run on the After Save Document event, instead of Close Document. A problem with Close Document is that it will occur even if the document has not been saved. So you could get a picture of the model in a state that doesn't match the saved version.
Can't find what you're looking for? Ask the community or share your knowledge.