Setting STEP File Save As Options values as defaults

Setting STEP File Save As Options values as defaults

jeremiah_boe
Contributor Contributor
1,785 Views
11 Replies
Message 1 of 12

Setting STEP File Save As Options values as defaults

jeremiah_boe
Contributor
Contributor

I am attempting to create an external rule that gets triggered after file open that will set the Save As options for the STEP file type without actually saving a STEP file (that will be done at a later time).

 

jeremiahboe_0-1665491442895.pngjeremiahboe_1-1665491477256.png

 

I have been able to do something similar with the Print Manager. I have tried to use the STEP Translator codes that are out there, but haven't had any luck in getting the values to remain in the Save As option window as the default values.

 

 

1,786 Views
11 Replies
Replies (11)
Message 2 of 12

tyler.warner
Advocate
Advocate

@jeremiah_boe  you can try this code. It will export a currently open part file to a STP file. It will prompt the save as dialog opening it to the current files location & naming it the same except the file extension. Some of the options are commented out that can help with seeing the steps of the application.

 

    Public Sub ExportToSTL()

        ' CHECK THAT PART FILE IS OPEN.
        If oDocument.DocumentType <> kPartDocumentObject Then 'DOCUMENTTYPEENUM
            MsgBox("The open file is not a part file. The command has been cancelled.")
            Exit Sub
        End If

        ' GET THE STEP EXPORT ADDIN USING ID & ACTIVATE IT.
        Dim oInvAddIns As ApplicationAddIns = ThisApplication.ApplicationAddIns
        Dim STEP_TranslatorAddIn As TranslatorAddIn = oInvAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}") 'TRANSLATOR: STP EXPORT
        STEP_TranslatorAddIn.Activate()
        Dim transientObj As TransientObjects = ThisApplication.TransientObjects
        Dim oContext As TranslationContext = transientObj.CreateTranslationContext
        oContext.Type = kFileBrowseIOMechanism
        Dim oOptions As NameValueMap = transientObj.CreateNameValueMap
        Dim oDataMedium As DataMedium = ThisApplication.TransientObjects.CreateDataMedium

        MsgBox("Before saveas check.")
        ' CHECK IF THE TRANSLATOR HAS 'SAVECOPYAS' OPTIONS
        If STEP_TranslatorAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then

            oOptions.Value("ApplicationProtocolType") = 3               ' INTEGER
            oOptions.Value("IncludeSketches") = False                   ' BOOLEAN
            oOptions.Value("Organization") = "Organization"     ' STRING
            'oOptions.Value("Author") =                                 ' STRING
            'oOptions.Value("Authorization") =                          ' STRING
            'oOptions.Value("Description") =                            ' STRING
            'oOptions.Value("export_fit_tolerance") = ' 0.xxx-xxxxxxxx   ' DOUBLE

            ' SHOW THE OPTIONS DIALOG.
            'STEP_TranslatorAddIn.ShowSaveCopyAsOptions(oDocument, oContext, oOptions)

            ' SET THE STEP TARGET FOLDER PATH. CHECK FOR THE FOLDER. CREATE FOLDER IF IT DOESN'T EXIST.
            'If Not System.IO.Directory.Exists(oFilePath) Then
            'Try
            '    System.IO.Directory.CreateDirectory(oFolder)
            'Catch ex As Exception
            'End Try
            'End If

            ' OPEN FILE DIALOG TO CHOOSE NAME & LOCATION OF EXPORTED STEP FILE.
            ' DEFAULTS TO 3D PRINTER FILE LOCATION & OPEN FILE NAME.
            Dim oSaveFileDialog1 As New SaveFileDialog With
                {
                .InitialDirectory = oFilePath,
                .Filter = "STEP Files (*.stp;*.ste;*.step;*.stpz)|*.stp;*.ste;*.step;*.stpz",
                .FileName = oFileName,
                .DefaultExt = ".stp"
                }

            ' SET THE STEP TARGET FILE NAME BASED ON THE DIALOG INPUT.
            If oSaveFileDialog1.ShowDialog() <> DialogResult.OK Then
                Exit Sub
            End If
            oDataMedium.FileName = oSaveFileDialog1.FileName

            ' EXPORT STEP WITH PRE-SELECTED SETTINGS IN THE SELECTED FILE LOCATION.
            Try
                STEP_TranslatorAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
            Catch ex As Exception
            End Try
        End If

        STEP_TranslatorAddIn.Deactivate()

    End Sub

 

If this solved your problem or answered your question, please click ACCEPT SOLUTION.
If this helped you, please click LIKE.
0 Likes
Message 3 of 12

jeremiah_boe
Contributor
Contributor

Tyler,

 

I am getting a few error statements within the supplied code. I can handle the Line 4 Error, but the others I am not quite certain of.

 

jeremiahboe_0-1665493469434.png

 

0 Likes
Message 4 of 12

tyler.warner
Advocate
Advocate

Sorry about that had variables declared outside the sub & forget to put them in there, try this.

If it's still having trouble with the windows save as dialog, we can change that to an inventor save as dialog.

 

 

 

Imports System.Windows.Forms

Public Sub Main()

    Dim oDocument As Document = ThisApplication.ActiveDocument
    Dim oFileName As String = oDocument.DisplayName.Replace(".ipt", "")
    Dim oFilePath As String = oDocument.FullFileName.Replace("\" & oFileName & ".ipt", "")

    ' CHECK THAT PART FILE IS OPEN.
    If oDocument.DocumentType <> kPartDocumentObject Then 'DOCUMENTTYPEENUM
        MsgBox("The open file is not a part file. The command has been cancelled.")
        Exit Sub
    End If

    ' GET THE STEP EXPORT ADDIN USING ID & ACTIVATE IT.
    Dim oInvAddIns As ApplicationAddIns = ThisApplication.ApplicationAddIns
    Dim STEP_TranslatorAddIn As TranslatorAddIn = oInvAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}") 'TRANSLATOR: STP EXPORT
    STEP_TranslatorAddIn.Activate()
    Dim transientObj As TransientObjects = ThisApplication.TransientObjects
    Dim oContext As TranslationContext = transientObj.CreateTranslationContext
    oContext.Type = kFileBrowseIOMechanism
    Dim oOptions As NameValueMap = transientObj.CreateNameValueMap
    Dim oDataMedium As DataMedium = ThisApplication.TransientObjects.CreateDataMedium

    ' MsgBox("Before saveas check.")
    ' CHECK IF THE TRANSLATOR HAS 'SAVECOPYAS' OPTIONS
    If STEP_TranslatorAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then

        oOptions.Value("ApplicationProtocolType") = 3               ' INTEGER
        oOptions.Value("IncludeSketches") = False                   ' BOOLEAN
        oOptions.Value("Organization") = "Spraying Systems Co."     ' STRING
        'oOptions.Value("Author") =                                 ' STRING
        'oOptions.Value("Authorization") =                          ' STRING
        'oOptions.Value("Description") =                            ' STRING
        'oOptions.Value("export_fit_tolerance") = ' 0.xxx-xxxxxxxx   ' DOUBLE

        ' SHOW THE OPTIONS DIALOG.
        'STEP_TranslatorAddIn.ShowSaveCopyAsOptions(oDocument, oContext, oOptions)

        ' SET THE STEP TARGET FOLDER PATH. CHECK FOR THE FOLDER. CREATE FOLDER IF IT DOESN'T EXIST.
        'If Not System.IO.Directory.Exists(oFilePath) Then
        'Try
        '    System.IO.Directory.CreateDirectory(oFolder)
        'Catch ex As Exception
        'End Try
        'End If

        ' OPEN FILE DIALOG TO CHOOSE NAME & LOCATION OF EXPORTED STEP FILE.
        ' DEFAULTS TO 3D PRINTER FILE LOCATION & OPEN FILE NAME.
        Dim oSaveFileDialog1 As New SaveFileDialog With
            {
            .InitialDirectory = oFilePath,
            .Filter = "STEP Files (*.stp;*.ste;*.step;*.stpz)|*.stp;*.ste;*.step;*.stpz",
            .FileName = oFileName,
            .DefaultExt = ".stp"
            }

        ' SET THE STEP TARGET FILE NAME BASED ON THE DIALOG INPUT.
        If oSaveFileDialog1.ShowDialog() <> DialogResult.OK Then
            Exit Sub
        End If
        oDataMedium.FileName = oSaveFileDialog1.FileName

        ' EXPORT STEP WITH PRE-SELECTED SETTINGS IN THE SELECTED FILE LOCATION.
        Try
            STEP_TranslatorAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
        Catch ex As Exception
        End Try
    End If

    STEP_TranslatorAddIn.Deactivate()

End Sub

 

 

If this solved your problem or answered your question, please click ACCEPT SOLUTION.
If this helped you, please click LIKE.
0 Likes
Message 5 of 12

jeremiah_boe
Contributor
Contributor

I got the code to run. It is still asking for an actual creation of the STEP file. I am looking for just setting the oOptions.Value part of the code without having to invoke the dialog box.

 

   oOptions.Value("ApplicationProtocolType") = 3               ' INTEGER
        oOptions.Value("IncludeSketches") = False                   ' BOOLEAN
        oOptions.Value("Organization") = "Spraying Systems Co."     ' STRING
        'oOptions.Value("Author") =                                 ' STRING
        'oOptions.Value("Authorization") =                          ' STRING
        'oOptions.Value("Description") =                            ' STRING
        'oOptions.Value("export_fit_tolerance") = ' 0.xxx-xxxxxxxx   ' DOUBLE

 I actually have an automatic STEP file created for us with our vaulting system. I want to ensure that all of our users have the same settings prior to when the auto STEP process kicks in.

0 Likes
Message 6 of 12

tyler.warner
Advocate
Advocate

Could you just include the export options to your Vault STP creation?

 

I'm not sure where the users export settings get stored but the system does remember your last export options.

If this solved your problem or answered your question, please click ACCEPT SOLUTION.
If this helped you, please click LIKE.
0 Likes
Message 7 of 12

WCrihfield
Mentor
Mentor

Hi @jeremiah_boe.  I am simply curious why you would want to set the SaveCopyAs settings at a different time than when you actually use the SaveCopyAs method to export your file?  Are you trying to help performance like processing time, simplify the other code for some reason, or is there another reason?  Also, did you know that you can have the code actually show you that options dialog, so you can manually set the settings you want, instead of having to do it by code, then let the code finish saving out the STEP file?  The TranslatorAddIn object has a method named ShowSaveCopyAsOptions, which you can use, but few folks do, because they want to keep it all automatic (minimal user interaction).

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 8 of 12

jeremiah_boe
Contributor
Contributor

We have multiple users that will kick off manual STEP files for suppliers and not knowing how they configure their STEP files is the reason for this. We have now put in place an automatic STEP file that is created as a viewable file during our store process which utilizes the Save As method for creating the file. By logically putting the STEP option values into our default criteria on open or save, it provides the 3rd party software a consistent starting point across our user base for creating those files and storing them in our vault.

 

And yes I would like to have this as an invisible process to the users.

0 Likes
Message 9 of 12

tyler.warner
Advocate
Advocate

It looks like you might be able to set the Save As (link) or Export (link) options of the user or file without running the actual command. You'll have to do the testing of this. The links are turning on the dialog. The code posted above has that suppressed with the options being set in the code. See if either of these works in combination with the provided code above.

If this solved your problem or answered your question, please click ACCEPT SOLUTION.
If this helped you, please click LIKE.
0 Likes
Message 10 of 12

WCrihfield
Mentor
Mentor

OK.  So, not all users will be using your code tool for generating their STEP files, and you want it so that even if they use the manual process of generating a STEP file, that those specified settings will already be in place, and ready for them to click the Save button.  That makes sense.  However, as @tyler.warner mentioned, there does not appear to be any way to 'store' those settings.  And there does not appear to be a way to 'load' those settings from the 'stored' location/file.  When exporting a DXF, you can save your 'configuration' settings out in an "*.ini" file, and your 'post process' settings out in an "*.xml" file, but when exporting to "*.stp", there is no option to save your current settings, or load any previously saved settings from a file.  This may be a good challenge to ask the folks at Autodesk about directly, and also maybe make a post within the Inventor Ideas Forum about, in an attempt to get something like that implemented in future releases.  Since Autodesk appears to be the author of the TranslatorAddIn being used, they would likely have to be the ones to implement a way to save your settings.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 11 of 12

jeremiah_boe
Contributor
Contributor

Thanks @WCrihfield  and @tyler.warner  for the responses. I will take a crack at the last couple of links that Tyler provided, then if those don't work, send it up the pole to the Inventor Ideas Forum.

0 Likes
Message 12 of 12

SER4
Collaborator
Collaborator

BTW, here is @jeremiah_boe's idea to vote for:
STEP file export options able to be preset - Autodesk Community

P.Eng. Mechanical Engineer
Dell Precision 5680 Laptop; Win11 Pro; 64GB RAM; i9-13900H CPU; Intel Iris Xe Graphics, NVIDIA RTX 3500 Ada Laptop GPU.
Vault Pro 2025.1 (30.1.63.0); Inventor Pro 2025.1.1 (241).
0 Likes