Yes, this is constant value for Addin
Here is fixed code to import multiple DWG model, but with previously mentioned obscurities.
Sub ImportMultipleDwgModels()
Dim iniFileName As String = "C:\DWG\importDwg.ini"
Dim dwgFileNames As String() = {
"C:\DWG\autocad_3D_1.dwg",
"C:\DWG\autocad_3D_2.dwg",
"C:\DWG\autocad_3D_3.dwg",
"C:\DWG\autocad_3D_4.dwg"
}
For Each dwgFileName As String In dwgFileNames
Dim partDocument As PartDocument = ImportDwgModel(dwgFileName, iniFileName)
If partDocument Is Nothing Then Continue For
Dim iptFileName = System.IO.Path.ChangeExtension(dwgFileName, ".ipt")
'Dim iptFileName = dwgFileName & ".ipt"
partDocument.SaveAs(iptFileName, False)
partDocument.Close()
Next
End Sub
Function ImportDwgModel(dwgFileName As String, iniFileName As String) As PartDocument
'Get DWG Translator
Dim dwgTranslatorId = "{C24E3AC2-122E-11D5-8E91-0010B541CD80}"
Dim dwgTranslator As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById(dwgTranslatorId)
'Create DataMedium
Dim dataMedium As DataMedium = ThisApplication.TransientObjects.CreateDataMedium()
dataMedium.FileName = dwgFileName
'Create translation context
Dim context As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext()
context.Type = IOMechanismEnum.kDataDropIOMechanism
'Create options
Dim options As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap()
Dim hasOpenOptions As Boolean = dwgTranslator.HasOpenOptions(dataMedium, context, options)
'options.Value("Import_Acad_IniFile") = iniFileName
'Import DWG
Dim targetObject As Object
dwgTranslator.Open(dataMedium, context, options, targetObject)
'3D model is imported as side effect not as primary output
Dim primaryOutputDoc = TryCast(targetObject, Document)
If Not primaryOutputDoc Is Nothing Then primaryOutputDoc.Close(True)
'Get imported model document from opened documents by it's DisplayName
Dim displayName As String = System.IO.Path.GetFileNameWithoutExtension(dwgFileName)
Dim dwg3dPart As PartDocument = Nothing
For Each document As Document In ThisApplication.Documents
If document.DisplayName.StartsWith(displayName) Then
dwg3dPart = TryCast(document, PartDocument)
If not dwg3dPart Is Nothing Then Exit For
End If
Next
If Not dwg3dPart Is Nothing Then Return dwg3dPart
Logger.Error("Import failed: {0}", dwgFileName)
Return Nothing
End Function