Export Assembly and the "children" to step file at other folder

Export Assembly and the "children" to step file at other folder

eladm
Collaborator Collaborator
432 Views
4 Replies
Message 1 of 5

Export Assembly and the "children" to step file at other folder

eladm
Collaborator
Collaborator

Hello

I need your help 🙂

I want to export an assembly file and all the children files (subassembly and parts ) to to step file.

The assembly is locating in C / subfolder and the "children's" files in other subfolder . The step file need to be create at network drive :  P:/StepFiles , but to save the folder hierarchy from C drive 

Thanks

0 Likes
433 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

Hi @eladm.  When you say 'children', do you mean just the top level components within the assembly, or do you mean every component in every level of the assembly structure?  Also, you may need to provide more details about the folder scenario.  Do you want the step file of the main assembly saved directly to this "P:/StepFiles" folder, or should it be in its own sub folder below that folder?  If within a sub folder, then what would that sub folder be named?  Then, are you saying the code will need to determine the relative folder structure for each lower level model file, in relation to the main assembly, then recreate that same folder structure below the P:/StepFiles sub folder (where the main assembly's step file is saved)?  Should all the sub folders be named exactly the same in both locations?  Is there anything special about how these step files should be named, or just use same file names, with .stp file extensions?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 5

eladm
Collaborator
Collaborator

Hello

 

Children - I mean all the subassembly and their subassembly and the parts . or if the assembly have only parts .

All the files in the assembly.

The New step files need to be saved at P:/stepfiles and in that folder need to be create the folder from the target path of the file

for example

The assembly is saved at c:/Invnetor/2022 . The main assembly contain one subassembly , that saved at c:/Inventor/2022/PPP .The Subassembly have one  part that saved at D:/qqq

The result :

At P:/stepfiles/2022 - main assembly.stp

At P:/stepfiles/2022/ppp - subassembly.stp

At P:/stepfiles/qqq - part.stp

regards

0 Likes
Message 4 of 5

JelteDeJong
Mentor
Mentor

Maybe this is what you are looking for:

Sub Main()

	' replaces with your folders
    Dim orgFolder = "C:\subfolder"  ' this gets replaced
    Dim stepFolder = "P:\stepfiles" ' by this

    Dim doc As Document = ThisDoc.Document

    For Each refDoc As Document In doc.AllReferencedDocuments
        Dim fileName = refDoc.FullFileName
        fileName = IO.Path.ChangeExtension(fileName, "stp")
        fileName = fileName.Replace(orgFolder, stepFolder)

        Logger.Info(fileName)
        CreateFoldersFor(fileName)
        ExportToSTEP(refDoc, fileName)
    Next
End Sub
Sub ExportToSTEP(doc As Document, fileName As String)

    ' Get the STEP translator Add-In.
    Dim oSTEPTranslator As TranslatorAddIn = 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 = ThisApplication.TransientObjects.CreateTranslationContext
    Dim oOptions As NameValueMap = 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 = IOMechanismEnum.kFileBrowseIOMechanism

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

        Call oSTEPTranslator.SaveCopyAs(doc, oContext, oOptions, oData)
    End If
End Sub
Private Sub CreateFoldersFor(fileName As String)
    Dim dirs As New List(Of String)
    Dim fileInfo As New IO.FileInfo(fileName)
    Dim dirInfo = fileInfo.Directory
While dirInfo.Exists = False dirs.Add(dirInfo.Name) dirInfo = dirInfo.Parent End While For i = dirs.Count - 1 To 0 Step -1 Dim name = dirs.Item(i) dirInfo.CreateSubdirectory(name) Dim newDir = IO.Path.Combine(dirInfo.FullName, name) dirInfo = New IO.DirectoryInfo(newDir) Next 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

0 Likes
Message 5 of 5

eladm
Collaborator
Collaborator

Hi

It didn't work. I didn't get any step file . I replaced the folder in the rule.

The original folder will change at every time . I don't want to replace it manually.

The target for the step will always will be p:/stepfile+ the folder from the source file 

regards

0 Likes