iLogic code that allows to export an individual step file from a multibody part file

iLogic code that allows to export an individual step file from a multibody part file

moraesorlando
Advocate Advocate
561 Views
4 Replies
Message 1 of 5

iLogic code that allows to export an individual step file from a multibody part file

moraesorlando
Advocate
Advocate

            Hello Inventor experts!

 

            I am here again to ask for your help.

 

            This time I would like to get help to create an iLogic code that allows me to export an individual step file from a multibody part file.

 

            How I desire that works:

 

            From a multibody part file, after run this rule the user will be prompted which body in the file the wants export.

 

            After select the body using the cursor of the mouse a browser will be show for the user indicates the place to salve the file.

 

            In the initial research I have done regarding this matter I could find the link below.

            I believe is not a exactly what I am looking for but maybe could be a start.

 

https://forums.autodesk.com/t5/inventor-forum/export-individual-step-files-from-multibody-part-file-...

 

            I am available to provide any other information required to achieve this target.

 

            Thanks in advance and best regards to all

0 Likes
Accepted solutions (1)
562 Views
4 Replies
Replies (4)
Message 2 of 5

JelteDeJong
Mentor
Mentor
Accepted solution

try it like this. When you start the rule you need to select a surface body. Then you select a name and place to save the file. 

Public Sub Main()
    Dim body As SurfaceBody = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartBodyFilter, "")

    Dim dialog As Inventor.FileDialog
    ThisApplication.CreateFileDialog(dialog)
    dialog.DialogTitle = "Save as STEP"
    dialog.Filter = "Step file (*.stp)|*.stp"
    dialog.CancelError = True

    Try
        dialog.ShowSave()
    Catch ex As Exception
        Return
    End Try

    Dim doc As PartDocument = ThisDoc.Document
    For Each b As SurfaceBody In doc.ComponentDefinition.SurfaceBodies
        b.Visible = False
    Next
    body.Visible = True
    Export(doc, dialog.FileName)
    For Each b As SurfaceBody In doc.ComponentDefinition.SurfaceBodies
        b.Visible = True
    Next
End Sub

Sub Export(doc As Document, oFilename As String)
    Dim oSTEPTranslator As TranslatorAddIn
    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
    oContext = ThisApplication.TransientObjects.CreateTranslationContext
    Dim oOptions As NameValueMap
    oOptions = ThisApplication.TransientObjects.CreateNameValueMap
    If oSTEPTranslator.HasSaveCopyAsOptions(doc, oContext, oOptions) Then
        ' Set application protocol.
        ' 2 = AP 203 - Configuration Controlled Design
        ' 3 = AP 214 - Automotive Design
        oOptions.Value("ApplicationProtocolType") = 2

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

        oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism

        Dim oData As DataMedium
        oData = ThisApplication.TransientObjects.CreateDataMedium
        oData.FileName = oFilename

        Call oSTEPTranslator.SaveCopyAs(doc, oContext, oOptions, oData)
    End If
End Sub

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 3 of 5

moraesorlando
Advocate
Advocate

Hello @JelteDeJong !!

 

Yes! You are always here to help.

 

I have tested and this is what I was looking forward.

I gave you the deserved like and will mark as solved.

 

Thank you very much one more time.

Best regards

0 Likes
Message 4 of 5

JelteDeJong
Mentor
Mentor

You marked your own comment as "Accepted solution"?

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 5 of 5

moraesorlando
Advocate
Advocate

Hello @JelteDeJong my mistake!

Now it's fixed

Best regards

0 Likes