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).
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.
Solved! Go to Solution.
Solved by JhoelForshav. Go to 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 🙂
Jhoel Forshav
Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website
Can't find what you're looking for? Ask the community or share your knowledge.