Extract File Name for Save as STEP using iLogic Inventor 2020

Extract File Name for Save as STEP using iLogic Inventor 2020

Anonymous
Not applicable
1,432 Views
6 Replies
Message 1 of 7

Extract File Name for Save as STEP using iLogic Inventor 2020

Anonymous
Not applicable

I am trying to use the file name (minus the extension) to name an exported STEP file.  I know the exporting function works, but I am having difficulty getting the file name to work. Note, in the code below, I am just trying to get the code to run without errors; oFileName = ThisDoc.FileName(False) flags an error "Run-time error '424': Object Required".

 

I don't know why this is the case, because I have been trying to adapt the code from the following post, where their's seems to work.

 

https://forums.autodesk.com/t5/inventor-customization/save-as-step-using-ilogic/td-p/7843312

 

Not sure if this is something with Inventor 2020 changing API structure/terminology causing the other code to be invalid.

 

Another note; Right now I have this running as an external rule so that every part can have access to it, as well as being available to all members of my team. Not sure if this changes how things need to be initialized.

 

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

    oFileName = ThisDoc.FileName(False)

    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 = "S:\Engineering\Step Files\temptest.stp"

        Call oSTEPTranslator.SaveCopyAs(ThisApplication.ActiveDocument, oContext, oOptions, oData)
    End If
End Sub
0 Likes
Accepted solutions (1)
1,433 Views
6 Replies
Replies (6)
Message 2 of 7

MjDeck
Autodesk
Autodesk

If you're running this in iLogic, please remove the word "Set" whenever it occurs at the start of a line. That keyword is only for VBA, not iLogic.

But it sounds like you're actually running this in VBA. If that's the case, ThisDoc.FileName won't work. Let me know if you're running in VBA and I can provide the equivalent VBA code.

 


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 3 of 7

Anonymous
Not applicable

Hi Mike,

 

I am running in VBA. Any help is appreciated!

 

Gary

0 Likes
Message 4 of 7

MjDeck
Autodesk
Autodesk
Accepted solution

It should work if you replace the line:

  oFileName = ThisDoc.FileName(False)

With this:

Dim fullName As String
fullName = ThisApplication.ActiveDocument.FullFileName
Dim oFileName As String
oFileName = CreateObject("Scripting.FileSystemObject").GetBaseName(fullName)

But you're not actually using the filename for anything.
Do you want to save the STEP file in the same folder as the Inventor document?


Mike Deck
Software Developer
Autodesk, Inc.

Message 5 of 7

Anonymous
Not applicable

Mike,


This worked exactly as I hoped.  I had the file location part figured out, and I just replaced the "temptest" name in oData.FileName by concatonating the oFileName into it.

 

Thanks again for the help!

0 Likes
Message 6 of 7

Anonymous
Not applicable

Save as STEP using iLogic Inventor

do you have the value for  (242-Managed Model based 3D Engineering)?

I tried 4 - no good

 

 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") =

0 Likes
Message 7 of 7

MjDeck
Autodesk
Autodesk

Use a value of 5 for the  ApplicationProtocolType.

You can find it on this page.


Mike Deck
Software Developer
Autodesk, Inc.