Share

Open an NX file suing the NX Translator Sample

Description

This sample demonstrates how open an NX file using the NX translator add-in.

Code Samples

Sub ImportNXFile()
    ' Set NX translator's CLSID and the NX file name.
    Dim strCLSID As String
    Dim strFileName As String
    strCLSld = "{93D506C4-8355-4E28-9C4E-C2B5F1EDC6AE}"
    
    ' Please set the full file name here, such as "C:\Part1.prt"
    strFileName = "C:\Part1.prt "
      
    Dim oAddIns As ApplicationAddIns
    Set oAddIns = ThisApplication.ApplicationAddIns
    
    ' Find the NX translator, get the CLSID and activate it.
    Dim oTransAddIn As TranslatorAddIn
    Set oTransAddIn = oAddIns.ItemById(strCLSld)
    oTransAddIn.Activate
    
    ' Get the transient object and take it as a factory to produce other objects.
    Dim transientObj As TransientObjects
    Set transientObj = ThisApplication.TransientObjects
    
    ' Prepare the first parameter for Open(), the file name.
    Dim file As DataMedium
    Set file = transientObj.CreateDataMedium
    file.FileName = strFileName
    
    ' Prepare the second parameter for Open(), the open type.
    Dim context As TranslationContext
    Set context = transientObj.CreateTranslationContext
    context.Type = kDataDropIOMechanism
    
    ' Prepare the third parameter for Open(), the options.
    Dim options As NameValueMap
    Set options = transientObj.CreateNameValueMap
    options.Value("SaveComponentDuringLoad") = False
    options.Value("SaveLocationIndex") = 0
    options.Value("ComponentDestFolder") = ""
    options.Value("SaveAssemSeperateFolder") = False
    options.Value("AssemDestFolder") = ""
    options.Value("ImportSolid") = True
    options.Value("ImportSurface") = True
    options.Value("ImportWire") = True
    options.Value("ImportWorkPlane") = True
    options.Value("ImportWorkAxe") = True
    options.Value("ImportWorkPoint") = True
    options.Value("ImportPoint") = True
    options.Value("ImportAASP") = False
    options.Value("ImportAASPIndex") = 0
    options.Value("CreateSurfIndex") = 1
    options.Value("GroupNameIndex") = 0
    options.Value("GroupName") = ""
    options.Value("ImportUnit") = 0
    options.Value("CheckDuringLoad") = False
    options.Value("AutoStitchAndPromote") = True
    options.Value("AdvanceHealing") = False
    
    options.Value("CHKSearchFolder") = True
    
    '100 is the search folder maximum that you can specify.
    'Assign separate search folder one by one.
    
    Dim searchFolder(100) As String
    searchFolder(0) = "C:\Folder1\"
    searchFolder(1) = "C:\Folder2\"
    options.Value("SearchFolder") = searchFolder
    
    'Prepare the fourth parameter for Open(), the final document
    Dim sourceObj As Object
    
    'Open the NX file.
    oTransAddIn.Open file, context, options, sourceObj
End Sub


Was this information helpful?