ILOGIC, SaveAsBitmap to folder location

ILOGIC, SaveAsBitmap to folder location

Anonymous
Not applicable
784 Views
5 Replies
Message 1 of 6

ILOGIC, SaveAsBitmap to folder location

Anonymous
Not applicable

I have some code that I want to use for presentation images. Pretty straight forward, saves a jpg of a desired resolution to a folder that - at the moment is hard coded in to the rule.

 

Each time you run the rule, it overwrites the file made previously.. Which is the purpose of this post as I don't want to over write the files, I need to create unique names.

 

SO...I'd like to either have the system open a save as dialgoue type window and the user can then choose a folder and filename - OR - The code checks if a file of a name exists and if so postfix it with 'something'

 

I've been stuck with this for a little while now so any help will be very warmly received !!

 

Thanks all..

 

 

SyntaxEditor Code Snippet

'catch and skip errors
On Error Resume Next
'define the active assembly
Dim oAssyDoc As AssemblyDocument
oAssyDoc = ThisApplication.ActiveDocument 

'Check all referenced docs
Dim oDoc As Inventor.Document
For Each oDoc In oAssyDoc.AllReferencedDocuments
    'set work plane visibility
    For Each oWorkPlane In oDoc.ComponentDefinition.WorkPlanes
    oWorkPlane.Visible = False
    Next
    'set work axis visibility
    For Each oWorkAxis In oDoc.ComponentDefinition.WorkAxes
    oWorkAxis.Visible = False
    Next
    'set work point visibility
    For Each oWorkPoint In oDoc.ComponentDefinition.WorkPoints
    oWorkPoint.Visible = False
    Next
Next
'update the files
InventorVb.DocumentUpdate()

'Change Scheme to Presentation
ThisApplication.ColorSchemes("Presentation").Activate 
' Get the active view. 
    Dim oView As View 
    oView = ThisApplication.ActiveView
oFolder = Left(oPath, InStrRev(oPath, "C:\temp\temp.jpg")) & "C:\temp\temp.jpg" 
    ' Save the view as a jpg file.  
    Call oView.SaveAsBitmap(oFolder, 6000, 0)
    



 

 

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

Owner2229
Advisor
Advisor

Hi, the easiest thing you can do is use date and time as file name:

 

'catch and skip errors
On Error Resume Next
'define the active assembly
Dim oAssyDoc As AssemblyDocument
oAssyDoc = ThisApplication.ActiveDocument 

'Check all referenced docs
Dim oDoc As Inventor.Document
For Each oDoc In oAssyDoc.AllReferencedDocuments
    'set work plane visibility
    For Each oWorkPlane In oDoc.ComponentDefinition.WorkPlanes
        oWorkPlane.Visible = False
    Next
    'set work axis visibility
    For Each oWorkAxis In oDoc.ComponentDefinition.WorkAxes
        oWorkAxis.Visible = False
    Next
    'set work point visibility
    For Each oWorkPoint In oDoc.ComponentDefinition.WorkPoints
        oWorkPoint.Visible = False
    Next
Next
'update the files
InventorVb.DocumentUpdate()

'Change Scheme to Presentation
ThisApplication.ColorSchemes("Presentation").Activate 
'Get the active view. 
Dim oView As View 
oView = ThisApplication.ActiveView
oFolder = "C:\temp\temp " & Now() & ".jpg"
'Save the view as a jpg file.  
Call oView.SaveAsBitmap(oFolder, 6000, 0)
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 3 of 6

Anonymous
Not applicable

Hi Mike thanks for replying,

 

what that actually does to my code is creare a folder called temp26 (I presume the 26 means the day of month) it then creates a subfolder of 26 called '10' whcih i presume to be the month number...

 

Inside that folder is nothing 😞

 

many thanks for shining some light on this, any other suggestions though>?

 

 

 

thanks!!

0 Likes
Message 4 of 6

Owner2229
Advisor
Advisor
Accepted solution

Oh, sorry, bad date formating. this code below should do it. This is my result from the rule: "C:\temp\temp 10-26-2015 15-15-35.jpg"

 

'catch and skip errors
On Error Resume Next
'define the active assembly
Dim oAssyDoc As AssemblyDocument
oAssyDoc = ThisApplication.ActiveDocument 

'Check all referenced docs
Dim oDoc As Inventor.Document
For Each oDoc In oAssyDoc.AllReferencedDocuments
    'set work plane visibility
    For Each oWorkPlane In oDoc.ComponentDefinition.WorkPlanes
        oWorkPlane.Visible = False
    Next
    'set work axis visibility
    For Each oWorkAxis In oDoc.ComponentDefinition.WorkAxes
        oWorkAxis.Visible = False
    Next
    'set work point visibility
    For Each oWorkPoint In oDoc.ComponentDefinition.WorkPoints
        oWorkPoint.Visible = False
    Next
Next
'update the files
InventorVb.DocumentUpdate()

'Change Scheme to Presentation
ThisApplication.ColorSchemes("Presentation").Activate 
'Get the active view. 
Dim oView As View 
oView = ThisApplication.ActiveView
oTime = TimeString
oTime = Val(oTime) & "-" & Mid(oTime, 4, 2) & "-" & Right(oTime, 2) oFolder = "C:\temp\temp " & DateString & " " & oTime & ".jpg" 'Save the view as a jpg file. Call oView.SaveAsBitmap(oFolder, 6000, 0)

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 5 of 6

Anonymous
Not applicable

many thanks mike

 

you fixed it !!

 

cheers!!!!

0 Likes
Message 6 of 6

Owner2229
Advisor
Advisor

You're welcomed 🙂

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes