This is somewhat of a follow-up posting to the previous Translating Files with the API posting since some might consider that saving an Inventor file as a .bmp or other type of image format is a form of translating that file. Here is some information specific to saving an image file.
If you have an Inventor file open and run the Save Copy As command you’ll notice that several of the file types shown are image files, as shown below. This is how you can interactively save an Inventor file as an image file.
The technique described in the Translating Files with the API post that uses the SaveAs method will also work for image file types too. It has all of the same advantages and disadvantages as described in the posting; it’s easy to use but doesn’t provide access to the setting in the options dialog, which in this case allows you to specify the resolution of the output image.
When using the SaveAs method the output resolution will always be the current screen resolution. Here’s an example.
' Get the active document.
Dim oDoc As Document
Set oDoc = ThisApplication.activeDocument
' Save a copy as a BMP file.
Call oDoc.SaveAs("C:\Temp\Test.bmp", True)
End Sub
There aren’t translator add-ins for the image file formats so that option as described in the file translation posting will not work for image files. However, Inventor does support another way to save image files that does allow you to specify the output resolution. This is the View.SaveAsBitmap method. Here’s an example of using it to save a jpg file.
' Get the active view.
Set oView = ThisApplication.ActiveView
Call oView.SaveAsBitmap("C:\Temp\Test.jpg", 700, 500)
End Sub
There are a few things to understand when using this method. First is that it’s a method of the View object and not the Document object. In the API the View object represents a graphics window. This method is supported on the View object because you’re not saving the entire contents of a document, like you do when you use the other translators, but you’re capturing a snapshot of a specific view. It’s possible to display multiple windows for a document, as illustrated below. By choosing which view to call the SaveAsBitmap method on you can control which view is saved as an image file.
There are a couple of ways to access a View object through the API. One of the most common, and the one used in the sample above, is to use the ActiveView property of the Application object. This returns the view that the end-user is currently working on. Only one window is ever active at a time. The other method is to use the Views property of the Document object to access all of the views associated with a particular document.
The second thing to understand is how to specify the format of the image file you’re creating. This is done implicitly by the extension of the supplied filename. In the example above it will create a jpg file because the filename is “Test.jpg”. If “Test.bmp” had been used instead it would have created a bmp file. You can see the formats that Inventor supports by looking at the types shown in the “Save as type” dropdown in the Save Copy As dialog, as shown below. Inventor currently supports bmp, gif, jpg, png, and tiff files.
The final thing to understand is how to control the size, or resolution, of the output image. Unlike a screen capture, you’re not limited by the screen resolution. The two arguments following the filename are the height and width of the output image, where the size is specified as the number of pixels. You can provide zero as the argument value to indicate you want to use the current view size on the screen. For example, the following program will create a jpg file that is exactly the same size as the view on the screen.
' Get the active view.
Set oView = ThisApplication.ActiveView
Call oView.SaveAsBitmap("C:\Temp\Test.jpg", 0, 0)
End Sub
You can also use a combination of values and zeros. This can be useful when you want a specific resolution but also want to maintain the same aspect ratio as the view. The example below will create a jpg that is 2000 pixels wide and the height will be computed by Inventor to be whatever’s necessary to maintain the view’s current height-width ratio.

Subscribe
The example below will create a jpg that is 2000 pixels wide and the height will be computed by Inventor to be whatever’s necessary to maintain the view’s current height-width ratio.
Posted by: buying darkfall online gold | July 08, 2009 at 12:31 AM
You can also use a combination of values and zeros. This can be useful when you want a specific resolution but also want to maintain the same aspect ratio as the view. The example below will create a jpg that is 2000 pixels wide and the height will be computed by Inventor to be whatever’s necessary to maintain the view’s current height-width ratio.
Posted by: eve isk | June 17, 2009 at 02:54 AM