Export the drawing in .jpg

Export the drawing in .jpg

Anonymous
Not applicable
1,497 Views
1 Reply
Message 1 of 2

Export the drawing in .jpg

Anonymous
Not applicable

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.

0 Likes
Accepted solutions (1)
1,498 Views
1 Reply
Reply (1)
Message 2 of 2

JhoelForshav
Mentor
Mentor
Accepted solution

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 🙂