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: 

Export the drawing in .jpg

1 REPLY 1
SOLVED
Reply
Message 1 of 2
Anonymous
935 Views, 1 Reply

Export the drawing in .jpg

Hi,

I'm trying to export the drawing in .jpg format. Not like exporting in .pdf, the exported image doesn't fit as drawing frame but shows the screen at the moment (as shown picture below).

 

08249B.jpg

 

My current code is something like below.

Dim drawingNumber As String
drawingNumber = textbox_drawingNumber.Text

Dim oDoc As Inventor.DrawingDocument
Call oDoc.SaveAs("C:\testFile\" + drawingNumber + ".jpg", True)

 

If possible, I also would like to set DPI and the size (width, height).

Thank you for your help in advance.

Labels (1)
1 REPLY 1
Message 2 of 2
JhoelForshav
in reply to: Anonymous

Hi @Anonymous 

With a lot of ideas from this thread: https://forums.autodesk.com/t5/inventor-customization/create-jpeg-of-drawing-idw-through-inventor-api/td-p/1560890

I wrote this ilogic function for you:

Sub Main
SaveAsJPG("C:\Users\hfljf\Pictures\test\drwg.jpg", 3000)
End Sub

Public Sub SaveAsJPG(oPath As String, oWidth As Integer)

Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument

Dim oSheet As Sheet = oDoc.ActiveSheet

Dim oView As Inventor.View = ThisApplication.ActiveView

Dim dAspectRatio As Double = 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 = 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
oView.SaveAsBitmap(oPath, oWidth, oWidth * dAspectRatio)

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

End Sub

There is no straight forward way to do this as I know of so you'll have to find the aspect ratio of the width/height by code, then fit and set extents to the camera to capture the drawing with no background.

 

The function lets you put in the save path and the width of your jpeg.

 

Hope this helps 🙂

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report