Macro to save geometry as .jt doesnt use .cfg file. How do i get inventor to

Macro to save geometry as .jt doesnt use .cfg file. How do i get inventor to

Anonymous
Not applicable
664 Views
3 Replies
Message 1 of 4

Macro to save geometry as .jt doesnt use .cfg file. How do i get inventor to

Anonymous
Not applicable

Macro to save geometry as .jt doesnt use .cfg file. How do i get inventor to use the cfg file I specify?

0 Likes
Accepted solutions (2)
665 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
Accepted solution

You would have to pass in the relevant options to the TraslatorAddin as a NameValueMap. The options for Config File are as follows:

 

ConfigFilePath          String

ConfigFileEnabled    Boolean   (False)

 

Search Translator Options in API Help for more details on the available options.

 

Syntax of SaveCopyAs Method of TranslatorAddIn Object

TranslatorAddIn.SaveCopyAs( SourceObject As Object, Context As TranslationContext, Options As NameValueMap, TargetData As DataMedium ) 

 

0 Likes
Message 3 of 4

Anonymous
Not applicable

Thanks that gave me the clue i needed.

0 Likes
Message 4 of 4

Anonymous
Not applicable
Accepted solution

Reasonably cleaned up version of final code:

Function func_ConvertFolderContentToJT(ByVal strSourceFolder As String, ByVal strSourceFileType As String, ByVal strDestinationFolder As String, ByVal strDestinationFileType As String, ByVal strConverterConfigFilePath As String) As Boolean
    func_ConvertFolderContentToJT = True
    Dim objFS As FileSystemObject
    Set objFS = CreateObject("Scripting.FileSystemObject")

    If Right(strSourceFolder, 1) <> "\" Then
        strSourceFolder = strSourceFolder & "\"
    End If
    If objFS.FolderExists(strSourceFolder) <> True Then
        func_ConvertFolderContentToJT = False
        Exit Function
    End If
    If strDestinationFolder <> "" Then
        If objFS.FolderExists(strDestinationFolder) <> True Then
            strDestinationFolder = False
        End If
        If Right(strDestinationFolder, 1) <> "\" Then
            strDestinationFolder = strDestinationFolder & "\"
        End If
    End If

    If strSourceFileType = "" Then
        func_ConvertFolderContentToJT = False
        Exit Function
    End If
    
    If strDestinationFileType = "" Then
        func_ConvertFolderContentToJT = False
        Exit Function
    End If
    
    Dim strToLookFor As String
    strToLookFor = strDestinationFileType
    
    If Left(strDestinationFileType, 1) = "." Then
        strToLookFor = Right(strDestinationFileType, Len(strDestinationFileType) - 1)
    Else
        strToLookFor = strDestinationFileType
        strDestinationFileType = "." & strDestinationFileType
    End If
    
    If objFS.FileExists(strConverterConfigFilePath) = False Then
        func_ConvertFolderContentToJT = False
        Exit Function
    End If
    
    Dim flg_TranslationAddInFound As Boolean
    flg_TranslationAddInFound = False
    Dim intAddIn As Long
    intAddIn = 1
    Do
        If InStr(1, UCase(ThisApplication.ApplicationAddIns.Item(intAddIn).Description), UCase(strToLookFor)) > 0 Then
            flg_TranslationAddInFound = True
            Exit Do
        End If
        intAddIn = intAddIn + 1
    Loop Until intAddIn = ThisApplication.ApplicationAddIns.Count + 1

    If flg_TranslationAddInFound <> True Then
        func_ConvertFolderContentToJT = False
        Exit Function
    End If
    
    Dim JTAddIn As TranslatorAddIn
    Set JTAddIn = ThisApplication.ApplicationAddIns.ItemById(ThisApplication.ApplicationAddIns.Item(intAddIn).ClientId)
   
    Dim oContext As TranslationContext
    Set oContext = ThisApplication.TransientObjects.CreateTranslationContext
            
    Dim oOptions As NameValueMap
    Set oOptions = ThisApplication.TransientObjects.CreateNameValueMap

    Dim oDataMedium As DataMedium
    Set oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
    
    Dim objFolder As Folder
    Dim objFile 'As File
    Set objFolder = objFS.GetFolder(strSourceFolder)
    Debug.Print "Convert Content of Folder: " & strSourceFolder
    For Each objFile In objFolder.Files
        Dim strFullFilePath As String
        strFullFilePath = objFile
        If Right(objFile, Len(strSourceFileType)) = strSourceFileType Then
            Dim oPartDoc As PartDocument
            Set oPartDoc = ThisApplication.Documents.Open(strFullFilePath)
            If JTAddIn.HasSaveCopyAsOptions(oPartDoc, oContext, oOptions) = True Then
                oOptions.Value("ConfigFilePath") = strConverterConfigFilePath
                oOptions.Value("ConfigFileEnabled") = True
                oContext.Type = kFileBrowseIOMechanism
                If strDestinationFolder <> "" Then
                    strFullFilePath = Replace(strFullFilePath, strSourceFolder, strDestinationFolder)
                End If
                oDataMedium.FileName = strFullFilePath & strDestinationFileType
                JTAddIn.SaveCopyAs oPartDoc, oContext, oOptions, oDataMedium
                oPartDoc.Close True
            Else
                If strDestinationFolder <> "" Then
                    strFullFilePath = Replace(strFullFilePath, strSourceFolder, strDestinationFolder)
                End If
                
                oPartDoc.SaveAs strFullFilePath & strDestinationFileType, True
                oPartDoc.Close True
            End If
        End If
    Next objFile
End Function

 


 

0 Likes