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: 

Create JPEG of Drawing (idw) through Inventor API

22 REPLIES 22
Reply
Message 1 of 23
ankit_19dec
3605 Views, 22 Replies

Create JPEG of Drawing (idw) through Inventor API

Hi,
I wanted to know how to create JPEG image of a drwing (idw) file in Inventor through Inventor API? Is there a way out?

I have even installed the "Export Viewable Files" from the http://www.kwikmcad.com site but am not able to automate it using API.

Can you help me out??

Ankit
22 REPLIES 22
Message 2 of 23
Anonymous
in reply to: ankit_19dec

Here is a macro that will save the active idw file to jpeg format.

Sub SaveDrawingAsJPEG()

Dim oDoc As DrawingDocument
Set oDoc = ThisApplication.ActiveDocument

oDoc.SaveAs "C:\temp\idw_to_jpg.jpg", True

End Sub

Sanjay-


wrote in message news:5090386@discussion.autodesk.com...
Hi,
I wanted to know how to create JPEG image of a drwing (idw) file in Inventor
through Inventor API? Is there a way out?

I have even installed the "Export Viewable Files" from the
http://www.kwikmcad.com site but am not able to automate it using API.

Can you help me out??

Ankit
Message 3 of 23
Anonymous
in reply to: ankit_19dec

I am interested in this macro and created it. But it doesn't work for me. Am I missing something?
Message 4 of 23
louloizides
in reply to: ankit_19dec

I wasn't aware that Inventor could save jpegs. I thought it was just bmps. If you want to save as a bmp and convert to jpeg, look into using the image magick com library: http://www.imagemagick.org/script/binary-releases.php. The code would be simple:

Dim retval, oldpic, newpic
oldpic="pic1.bmp"
newpic="pic1.jpg"
Dim im As New ImageMagickObject.MagickImage
retval = im.Convert(oldpic, newpic)
Set im = Nothing

I started using this because it worked with the wmfs that save in the part files and it's hard to find something that does. If you want a small library that you can distribute, tho, try the intel jpeg library.
Message 5 of 23
Anonymous
in reply to: ankit_19dec

Yes, Inventor can save to jpegs. You can do this in the UI by doing a "Save
Copy As" and selecting the "Save as type" to be "JPEG". The macro that I
posted earlier still works fine for me.

Sanjay-

wrote in message news:5123055@discussion.autodesk.com...
I wasn't aware that Inventor could save jpegs. I thought it was just bmps.
If you want to save as a bmp and convert to jpeg, look into using the image
magick com library: http://www.imagemagick.org/script/binary-releases.php.
The code would be simple:

Dim retval, oldpic, newpic
oldpic="pic1.bmp"
newpic="pic1.jpg"
Dim im As New ImageMagickObject.MagickImage
retval = im.Convert(oldpic, newpic)
Set im = Nothing

I started using this because it worked with the wmfs that save in the part
files and it's hard to find something that does. If you want a small library
that you can distribute, tho, try the intel jpeg library.
Message 6 of 23
Anonymous
in reply to: ankit_19dec

Is there a way to change the size of the image through the API like there is manually under the options button in the save dialog box?
Message 7 of 23
Anonymous
in reply to: ankit_19dec

You can specify the image size in the View.SaveAsBitmap method. This method
currently supports bmp format only. In the upcoming release (Inventor 2008),
other formats (jpg, png, etc.) are supported as well.

Sanjay-

wrote in message news:5510863@discussion.autodesk.com...
Is there a way to change the size of the image through the API like there is
manually under the options button in the save dialog box?
Message 8 of 23
Fredake
in reply to: ankit_19dec

Nice macro. In the ordinary "Save as" messagebox its possible to set resolution in X and Y direction.
Is it possible to set the resolution of the jpg in the macro with some arguments?

/Fred
Message 9 of 23
Anonymous
in reply to: ankit_19dec

As Sanjay said in a previous post, you can use the SaveAsBitmap method,
which allows you to set the resolution.
--
Brian Ekins
Autodesk Inventor API

wrote in message news:5607116@discussion.autodesk.com...
Nice macro. In the ordinary "Save as" messagebox its possible to set
resolution in X and Y direction.
Is it possible to set the resolution of the jpg in the macro with some
arguments?

/Fred
Message 10 of 23
Fredake
in reply to: ankit_19dec

DOH!! Sorry, It was to close to my question... 😉
Thanks

To bad it only applies to bitmap creation. Shouldn´t there be a SaveAsJPG in Inventor 2008?
I´m a novis on Inventor API so please have same patience. :-) Message was edited by: fredake
Message 11 of 23
Anonymous
in reply to: ankit_19dec

The SaveAsBitmap method works for types other than .bmp in Inventor 2008.
The extension of the file name provided in the FullFileName argument
specifies the type to export the file to. So to save as jpg, you would do
something like:

View.SaveAsBitmap("C:\temp\image.jpg", width, height)

Sanjay-

wrote in message news:5610532@discussion.autodesk.com...
DOH!! Sorry, It was to close to my question... 😉
Thanks

To bad it only applies to bitmap creation. Shouldn´t there be a SaveAsJPG in
Inventor 2008?
I´m a novis on Inventor API so please have same patience. 🙂

Message was edited by: fredake
Message 12 of 23
RonnieWilkins
in reply to: ankit_19dec

Shouldn't the function then be renamed 'SaveAsImage'?
Ronnie Wilkins, Jr.
Message 13 of 23
Anonymous
in reply to: ankit_19dec

The term bitmap is a generic term used to denote any raster image. See
http://dictionary.reference.com/browse/bitmap. Unfortunately the name
become somewhat associated with Microsoft's .bmp format. When we named the
method it was intended to handle any raster image format that Inventor would
support, not just the .bmp format.
--
Brian Ekins
Autodesk Inventor API

wrote in message news:5612611@discussion.autodesk.com...
Shouldn't the function then be renamed 'SaveAsImage'?
Message 14 of 23

Hello Sanjay and Brian,
My problem is another point.

The Saveas, save the active window in IDW, but I have the Active sheet. For Example in A4. The picture have background and sheet.

Are you have solution for this??
Message 15 of 23
Anonymous
in reply to: ankit_19dec

Sorry, I'm not clear on what you need. Could you describe your requirement
in more detail?

Sanjay-

wrote in message news:5783590@discussion.autodesk.com...
Hello Sanjay and Brian,
My problem is another point.

The Saveas, save the active window in IDW, but I have the Active sheet. For
Example in A4. The picture have background and sheet.

Are you have solution for this??
Message 16 of 23

Sanjay, more one time sorry.
I try describe for you.
On IDW, the command "saveas" in JPG, today it's save the active window, with background.
(attached file: 1.jpg)
I need the (attached file: 2.jpg), without background, only sheet size.

Hope thats helps.
Message 17 of 23
Anonymous
in reply to: ankit_19dec

This turned out to be an interesting problem. I didn't find a
straightforward way to do this via the user interface. The best way that I
could come up thru the API was to resize the view so it matched the aspect
ratio of the sheet and then zoom in so the sheet fit in just right. I've
attached the code below with some comments.

Sanjay-

Public Sub SaveAsJPG()

Dim oDoc As DrawingDocument
Set oDoc = ThisApplication.ActiveDocument

Dim oSheet As Sheet
Set oSheet = oDoc.ActiveSheet

Dim oView As View
Set oView = ThisApplication.ActiveView

Dim dAspectRatio As Double
dAspectRatio = oSheet.height / oSheet.Width

' Adjust the aspect ratio of the view to match that of the sheet
oView.height = oView.Width * dAspectRatio

Dim oCamera As Camera
Set oCamera = oView.Camera

' Center the sheet to the view
oCamera.Fit

' Zoom to fit the sheet exactly within the view
' Add some tolerance to make sure the sheet borders are contained
oCamera.SetExtents oSheet.Width * 1.003, oSheet.height * 1.003

' Apply changes to the camera
oCamera.Apply

' Save view to jpg. Make sure that the aspect ratio is maintained when
exporting
Call oView.SaveAsBitmap("C:\temp\drwg.jpg", 800, 800 * dAspectRatio)

' Restore the view
oCamera.Fit
oCamera.Apply
oView.WindowState = kMaximize

End Sub

wrote in message news:5794020@discussion.autodesk.com...
Sanjay, more one time sorry.
I try describe for you.
On IDW, the command "saveas" in JPG, today it's save the active window, with
background.
(attached file: 1.jpg)
I need the (attached file: 2.jpg), without background, only sheet size.

Hope thats helps.
Message 18 of 23

Sanjay,
Good solution.
When you Call oView.SaveAsBitmap is possible with JPG??

Note: save in JPG = small file size.
save in BMP is Medium or Large

The solution save in jpg, but no have compression. So it's BMP.

Tks for all
--
Cristiano Oliveira
Autodesk Certified
http://managermachine.blogspot.com
Message 19 of 23
Anonymous
in reply to: ankit_19dec

The code is saving the picture as a JPEG, see the extension of the filename
(notice the .jpg):

Call oView.SaveAsBitmap("C:\temp\drwg.jpg"

--
T. Ham
CAD Automation & Systems Administrator
CDS Engineering BV

HP xw4300 Workstation
Dual Pentium XEON 3.6 Ghz
4 GB SDRAM
NVIDIA QUADRO FX 3450/4000 SDI (Driver = 6.14.10.9185)
250 GB SEAGATE SATA Hard Disc
3Com Gigabit NIC

Windows XP Professional SP2
Autodesk Inventor Series 10 SP3a
Autodesk Inventor Suite 2008 SP1
--
Message 20 of 23

Teun,
The VBA save in BMP with extension JPG.
Because I inform the extension wrong. Ok.

But the problem is a function SaveAsBitmap, is that where I define the aspectratio.

If you try save in JPG with options (aspectioratio).
If use saveas only, no have teh same options.

Sorry my basic english.

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

Post to forums  

Autodesk Design & Make Report