Export step file with date in filename

Export step file with date in filename

info5RLCG
Contributor Contributor
481 Views
4 Replies
Message 1 of 5

Export step file with date in filename

info5RLCG
Contributor
Contributor

Hello, 

 

I would like to write a macro, that exports the currently open file/assembly into a spt-file.

The file name should be with a date stamp and the filename, like this: 2023-10-02_filename.stp

 

I found following code in the VBA-samples of Inventor 2021, but I don't have a clue on how the saving with date stamp and filename could work.
Could you please give me a hint on this?

 

Thanks alot!

Best Regards
Martin

 

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
Accepted solutions (1)
482 Views
4 Replies
Replies (4)
Message 2 of 5

bradeneuropeArthur
Mentor
Mentor
Dim oData As DataMedium
oData = ThisApplication.TransientObjects.CreateDataMedium
Dim dat As Date = Date.today

Set oData.FileName = "C:\_Export\temptest"& Replace( dat,"-","") &".stp"

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 3 of 5

info5RLCG
Contributor
Contributor

Hi Arthur, 

thanks for your reply, I really appreciate your effort. 

 

It does not fully work and I get following error:
Translated to English, it says, that the number of arguments is not correct.

 

info5RLCG_0-1696362646018.png

 

Could you please give me a tipp on how to solve this?

Thanks in advance!

 
0 Likes
Message 4 of 5

bradeneuropeArthur
Mentor
Mentor
Accepted solution

Use this in that case:

Dim n As Date = Date.Now

Dim y As String = n.Year.ToString
Dim m As String = n.Month.ToString
Dim d As String = n.Day

Dim oData As DataMedium
oData = ThisApplication.TransientObjects.CreateDataMedium
Dim dat As String = y +m+d

oData.FileName = "C:\_Export\temptest" & dat & ".stp"

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 5 of 5

romu51
Advocate
Advocate

Hi,

I've integrated this to one of my rules but the date displayed as 2024223...

how can i "force" the date to retain a 2 digit format to give me 20240223?

thanks.  

0 Likes