Save as STEP using iLogic

Save as STEP using iLogic

phila
Enthusiast Enthusiast
6,524 Views
11 Replies
Message 1 of 12

Save as STEP using iLogic

phila
Enthusiast
Enthusiast

I found this code that exports to stp and am trying to get it to work the way I want the file name to appear.

 

Originally, the code would check to see if there was an existing file with the same name and increment the file name using the variable counter if needed. This works perfectly, just not what the client wants. 721001_Vxx.stp

 

I would like to have it add the date instead so the filename reads: 721001 8/11/2015 5:25 PM.stp

 

There is a custom iprop called PlotDate&Time in my part and asm files I am trying to use instead of the _Vxx.

 

The code runs as modified and gets to the open folder dialog but when opening the folder there isn't a file there. It seems to be doing something, just not creating the file.

 

Not knowing programming much at all, I don't know how to get this to work as I would like.

 

Any help would be much appreciated.

 

 

0 Likes
Accepted solutions (1)
6,525 Views
11 Replies
Replies (11)
Message 2 of 12

humbertogo
Advocate
Advocate

From Autodesk Inventor API.chm

 

Public Sub ExportToSTEP()
    ' Get the STEP translator Add-In.
    Dim oSTEPTranslator As TranslatorAddIn
    Set oSTEPTranslator = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")

    If oSTEPTranslator Is Nothing Then
        MsgBox "Could not access STEP translator."
        Exit Sub
    End If

    Dim oContext As TranslationContext
    Set oContext = ThisApplication.TransientObjects.CreateTranslationContext
    Dim oOptions As NameValueMap
    Set oOptions = ThisApplication.TransientObjects.CreateNameValueMap
    If oSTEPTranslator.HasSaveCopyAsOptions(ThisApplication.ActiveDocument, oContext, oOptions) Then
        ' Set application protocol.
        ' 2 = AP 203 - Configuration Controlled Design
        ' 3 = AP 214 - Automotive Design
        oOptions.Value("ApplicationProtocolType") = 3

        ' Other options...
        'oOptions.Value("Author") = ""
        'oOptions.Value("Authorization") = ""
        'oOptions.Value("Description") = ""
        'oOptions.Value("Organization") = ""

        oContext.Type = kFileBrowseIOMechanism

        Dim oData As DataMedium
        Set oData = ThisApplication.TransientObjects.CreateDataMedium
        oData.FileName = "C:\temptest.stp"

        Call oSTEPTranslator.SaveCopyAs(ThisApplication.ActiveDocument, oContext, oOptions, oData)
    End If
End Sub
0 Likes
Message 3 of 12

phila
Enthusiast
Enthusiast

Thanks for the reply.

 

The code you posted is part of the code in the attachment with the original post.

As said, the original code works perfectly. I want to have the date in the file name instead of the _Vxx

 

Attached is the original code.

 

0 Likes
Message 4 of 12

phila
Enthusiast
Enthusiast

I'm getting closer to gettig this to work. It saves the STEP file but ignores the Sdate in the filename when saving.

 

What needs to change to get it in there? TIA

 

 

Format:HTML Format Version:1.0 StartHTML: 165 EndHTML: 2611 StartFragment: 314 EndFragment: 2579 StartSelection: 314 EndSelection: 314SyntaxEditor Code Snippet

Stepfilename = ThisDoc.PathAndFileName(False)

oSdate = iProperties.Value("Custom","PlotDate&Time")
 
    CurrentFile = Stepfilename & " " & Sdate & ".stp"
 

 

0 Likes
Message 5 of 12

Owner2229
Advisor
Advisor
Accepted solution

Here you go . Should work now.

 

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 6 of 12

Anonymous
Not applicable

You have Sdate in your code, but your variable is called oSdate.

0 Likes
Message 7 of 12

phila
Enthusiast
Enthusiast

Thank you! That worked.

 

Using the datestring looks to be the difference. Makes more sense and direct than iProps.

 

Just curious, Why wasn't using the info from custom iProps working for this code? I have seen it used in other code that worked.

0 Likes
Message 8 of 12

Owner2229
Advisor
Advisor

It might work, but you'll need another rule that will write the date in the iProp, so I rather specifed it myself, because I didn't know if you have such a rule added.

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 9 of 12

phila
Enthusiast
Enthusiast

I do have a rule for it but your method is more straight forward.

 

Another question. Is it possible to save the step files in different folder than the same one as the source file? Preferably under the same folder as the source.

 

PARTS

            STEP files

 

I tried to add it to the

 

oData,FileName = currentfile

 

but it gives a unknown error when run.

 

I Tried     oData,FileName = "E:\ STEP\"  & currentfile    to try it out but gave up when it didn't work.

 

The folder already exists.

0 Likes
Message 10 of 12

Owner2229
Advisor
Advisor

You have your path specifed on 2th line:

Stepfilename = ThisDoc.PathAndFileName(False)

You can change it to something like this:

Stepfilename = "E:\ STEP\"

btw. is the space in "E:\ STEP\" intended?

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 11 of 12

Owner2229
Advisor
Advisor

I've made a mistake, it should be like this:

Stepfilename = "E:\ STEP\" & ThisDoc.FileName(False)

 

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 12 of 12

phila
Enthusiast
Enthusiast

Thank you again for the guidence.

 

I did this so it would put the file in a folder under the source file folder. I also changed the dialog box to open the tstep folder if desired .

 

 

Stepfilename = ThisDoc.Path & "\TSTEP\" & ThisDoc.FileName(False)

 This works well now.

 

However....

 

I was just asked when running this code, if it could compare filenames and if it existed with an earlier date in the name, delete that file, then save the new file. This way only one file for each part would be in the folder and not several with just a different date.

Can this be done?

Is there code out there that can be added that does this?

Did a quick search and haven't found anything.

 

Typical boss, "That's great. Now, can we do this or change that"

 

0 Likes