ilogic Save Copy As image with variable name

ilogic Save Copy As image with variable name

Anonymous
Not applicable
854 Views
3 Replies
Message 1 of 4

ilogic Save Copy As image with variable name

Anonymous
Not applicable

Hello!

 

I have an idea of a new iLogic rule I wanted to create. The purpose of it was to Save Copy As an image file of a model.

For an example if I Save Copy As a ".bmp" file with the name "PIC_1", it would be great to Save Copy As a new ".bmp" file called "PIC_2" .  The purpose of the rule is, that it should understand, that if I have a file with the original name saved, it will save a copy with another name.

The beginning of my code works fine, but somehow I just can't get it to write a new picture file with name.

Can anybody more fluent give me a hand with my struggle pleas?

The beginning of my iLogic rule:

sPath = "C:\files\"
ThisDoc.Document.SaveAs(sPath + "PIC_1" + ".bmp", True)

If ThisDoc.Document.SaveAs(sPath + "PIC_1" + ".bmp", True), Then 
 ThisDoc.Document.SaveAs(sPath + "PIC_2" + ".bmp", True)


End If

 

0 Likes
Accepted solutions (1)
855 Views
3 Replies
Replies (3)
Message 2 of 4

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @Anonymous ,

 

Here's an example.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

sPath = "C:\Temp\PIC_.bmp"
sFirstFile = "C:\Temp\PIC_1.bmp"

If System.io.File.Exists(sFirstFile) Then
    Dim folderPath = System.io.Path.GetDirectoryName(sPath)
    Dim fileName = System.io.Path.GetFileNameWithoutExtension(sPath)
    Dim extension = System.io.Path.GetExtension(sPath)
    Dim fileNumber = 0

    Do
        fileNumber += 1
        sPath = System.io.Path.Combine(folderPath,
                                String.Format("{0}{1}{2}",
                                              fileName,
                                              fileNumber,
                                              extension))
    Loop While System.io.File.Exists(sPath)
Else
	sPath = sFirstFile
End If

ThisDoc.Document.SaveAs(sPath, True)

EESignature

Message 3 of 4

Anonymous
Not applicable

Thanks! It works just great!

Can you suggest some any website from where I can learn about iLogic macros and maybe get some macro related commands?

 

With best regards....

0 Likes
Message 4 of 4

Curtis_Waguespack
Consultant
Consultant

Hi @Anonymous 

 

The iLogic editor allows you to use VB.Net code to work with Inventor's API (application programming interface) within in it, and even mix Vb.net with iLogic functions, which technically is what the code I posted would be. So with that in mind you can often do a Google search for what you want to do such as "Vb.net + save file and increment name" which is how I found an example to start with:

http://www.vbforums.com/showthread.php?731011-Increment-the-filename-if-file-already-exists-Resolved

 

To find more information on Inventor's API  you can access the API help from Inventor as shown here:

Autodesk%2BInventor%2BAPI%2BHelp%2BExamples%2B1

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

EESignature