Save as jpeg

Save as jpeg

tomislav.peran
Advocate Advocate
580 Views
5 Replies
Message 1 of 6

Save as jpeg

tomislav.peran
Advocate
Advocate

Hello,

 

Sometimes If I have an assembly or a part opened I export it as a jpeg file to get a picture of it. 

 

I assume it is possible to do this via code?

 

Therefore,  1. File -> Export Assembly/Part -> Image -> Jpeg files (.jpg)

                    2. Location: same location where assembly/part is saved.  

 

That code would be really cool to have, so if anyone knows the code, please let me know.

Regards,

Tom

0 Likes
Accepted solutions (1)
581 Views
5 Replies
Replies (5)
Message 2 of 6

fullevent
Advisor
Advisor

Hi @tomislav.peran,

 

I made once this function to do exactly that. It's for IPTs but that could be adjusted.
Maybe that will help you 🙂

 

 

Private Sub create_jpg(saveName As String)
    Dim oPartDoc As PartDocument
    Set oPartDoc = ThisApplication.ActiveDocument
    Dim oActiveView As View
    Set oActiveView = ThisApplication.ActiveView
    Dim oCamera As Camera
    Set oCamera = oActiveView.Camera
    oCamera.ViewOrientationType = kTopViewOrientation
    oCamera.Apply
    ThisApplication.ActiveView.Fit
    Dim oWorkAxes As WorkAxes
    Set oWorkAxes = oPartDoc.ComponentDefinition.WorkAxes
    oWorkAxes.Item(1).Visible = True
    oWorkAxes.Item(2).Visible = True
    Call oActiveView.SaveAsBitmap(saveName & ".jpg", 1000, 800)
    oWorkAxes.Item(1).Visible = False
    oWorkAxes.Item(2).Visible = False
End Sub

 


Edit:
To get the saveName I have this line somewhere

Left$(oPartDoc.FullDocumentName, Len(oPartDoc.FullDocumentName) - 4)

 

Best regards,


Aleksandar Krstic
Produkt- und Projektmanager

0 Likes
Message 3 of 6

tomislav.peran
Advocate
Advocate

Hi fullevent,

 

Thanks for the code. This idea is exactly what I want. 🙂 Top view with axes.

However, I get an error when it wants to save as jpg:

 

Call oActiveView.SaveAsBitmap(saveName & ".jpg", 1000, 800)

Error on line 16 in rule: Rule0, in document: MyPart.ipt

Klasse is niet geregistreerd

 

SaveName -> is it the same as the given document name? And will it save it at the same location as part/assy?

 

I have also removed "set" at the start of the lines. I use code in Inventor and it does not want to have "set" in the code.

Also, It wants me to change Prive Sub to Sub main.

 

Tom

0 Likes
Message 4 of 6

fullevent
Advisor
Advisor
Accepted solution

Hi Tom,

 

didn't know you are trying to create an iLogic.
Try this rule. I just tested it and it works for me.

 

Dim saveName As String
Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument
Dim oActiveView As View
oActiveView = ThisApplication.ActiveView
Dim oCamera As Camera	
oCamera = oActiveView.Camera
oCamera.ViewOrientationType = kTopViewOrientation
oCamera.Apply
ThisApplication.ActiveView.Fit

saveName = Left$(oDoc.FullDocumentName, Len(oDoc.FullDocumentName) - 4)

Call oActiveView.SaveAsBitmap(saveName & ".jpg", 1000, 800)

 

The filename contains the full path. Therefor it will safe the jpg at same location and same name as the assembly/part.


Greetings,


Aleksandar Krstic
Produkt- und Projektmanager

0 Likes
Message 5 of 6

tomislav.peran
Advocate
Advocate

Hi fullevent,

 

Works perfect. Thank you a lot!

 

Tom

0 Likes
Message 6 of 6

fullevent
Advisor
Advisor

Greate, you're welcome 🙂


Aleksandar Krstic
Produkt- und Projektmanager

0 Likes