When calling the Camera.SaveAsBitmap method and specifying a background color, should it reset the background color of the current view? Calling it in 2014 does this.
Also is there a way to apply the camera settings without changing the current view? I want to change the camera settings but just save the images to a file?
Solved! Go to Solution.
Solved by philippe.leefsma. Go to Solution.
Hi Thomas,
I think that method should not change the view...
A couple of suggestions for you:
1/ You could try to add a new view: Doc.Views.Add, then modify that view camera, take the picture and close the view.
2/ Use a transient camera. Below is a piece of code that was used in an Apprentice sample:
' Open the specified file. Dim doc As Inventor.ApprenticeServerDocument = m_apprentice.Open(filename) ' Create a camera. m_camera = m_apprentice.TransientObjects.CreateCamera ' Associate the camera with the part's component definition. m_camera.SceneObject = doc.ComponentDefinition m_camera.Fit() m_camera.ApplyWithoutTransition() Dim tg As Inventor.TransientGeometry = m_apprentice.TransientGeometry m_camera.Eye = tg.CreatePoint(-10, 10, 10) m_camera.UpVector = tg.CreateUnitVector(0, 1, 0) m_camera.Target = tg.CreatePoint(0, 0, 0) m_camera.Fit() m_camera.ApplyWithoutTransition() Dim picDisp As stdole.IPictureDisp picDisp = m_camera.CreateImage(PictureBox1.Width, PictureBox1.Height) ' Return the image. PictureBox1.Image = Microsoft.VisualBasic.Compatibility.VB6.IPictureDispToImage(picDisp)
I hope it helps,
Philippe.
Using a Transient Camera Object in Inventor 2014 has unpredictable results. Sometimes the addin continues and sometimes it doesn't. But it doesn't throw any errors or exceptions. It just stops and eventually hangs Inventor. I'm trying to show a dialog after creating the camera. Setting a new camera object wants the SceneObject to be a View object. Setting a new camera to an existing view behaves unpredictably too.
Using a new view works. But it throws a ComException when attempting to close the view as well. ComException errors occur that don't seem to be caught by a try statement in c#. The view closes as expected. It also seems to raise the OnNewView event as well. But my code that responds to it doesn't run til after the command completes at which point the View object they operate on may be invalid. It appears that accessing the view com object hangs the debugger in Visual Studio. Running Inventor without debugging and using a new view works as expected. But I suspect that com errors are being thrown in the background. My guess it has to do with the order of events firing.
Excuting it using a new view works and accomplishes the task but seems very hackish to avoid having the background color being changed on a view. The simplest solution would be to save the image and reset the background to the original colors. But I haven't found a way to get what the colors are. I could save my view images and then reset the camera to the original settings and save a temporary image using the original background colors to reset the view to avoid the apperance of a view change.
At the moment adding a new view works the best and is the most transparent to the user. Unfortunately while debugging and running the command causes a ComException error that I can't catch and have to ignore.
Can you give a try at those 3 VBA samples below. All of them seem to work fine on my side.
When you mentioned initially that Camera.SaveAsBitmap is reseting the background color, what does it do exactly?
Thanks,
Philippe.
Sub CamSaveAsBitmap1() Dim view As view Set view = ThisApplication.ActiveView Dim camera As camera Set camera = view.camera Dim topClr As color Set topClr = ThisApplication.TransientObjects.CreateColor(255, 0, 0) Dim bottomClr As color Set bottomClr = ThisApplication.TransientObjects.CreateColor(0, 255, 0) Call camera.SaveAsBitmap("C:\Temp\test.png", view.width, view.height, topClr, bottomClr) End Sub Sub CamSaveAsBitmap2() Dim doc As Document Set doc = ThisApplication.ActiveDocument Dim view As view Set view = doc.views.Add Dim camera As camera Set camera = view.camera Dim topClr As color Set topClr = ThisApplication.TransientObjects.CreateColor(255, 0, 0) Dim bottomClr As color Set bottomClr = ThisApplication.TransientObjects.CreateColor(0, 255, 0) Call camera.SaveAsBitmap("C:\Temp\test.png", view.width, view.height, topClr, bottomClr) view.Close End Sub Sub CamSaveAsBitmap3() Dim doc As Document Set doc = ThisApplication.ActiveDocument Dim view As view Set view = ThisApplication.ActiveView Dim camera As camera Set camera = ThisApplication.TransientObjects.CreateCamera camera.SceneObject = doc.ComponentDefinition camera.ViewOrientationType = kIsoTopLeftViewOrientation camera.Fit camera.ApplyWithoutTransition Dim topClr As color Set topClr = ThisApplication.TransientObjects.CreateColor(255, 0, 0) Dim bottomClr As color Set bottomClr = ThisApplication.TransientObjects.CreateColor(0, 255, 0) Call camera.SaveAsBitmap("C:\Temp\test.png", view.width, view.height, topClr, bottomClr) End Sub
Hello@philippe.leefsma, @rjay75
I also used CamSaveAsBitmap3 for my needs and works great excluding one detail. I am getting coordinate system arrows in the resulting picture. Do you know guys how to disable that?
ThisApplication.DisplayOptions.Show3DIndicator = False
https://forums.autodesk.com/t5/inventor-forum/ilogic-save-image-of-model/td-p/6875045