By Adam Nagy
When you import a non-native file then you are using a translator add-in to do the import. Each of them might have different options which can affect how you implement things.
As shown in this blog post you can easily find out all the options available for a translator add-in:
http://adndevblog.typepad.com/manufacturing/2014/02/get-option-names-and-values-supported-by-inventor-translator-addins-via-api.html
For SolidWorks translator add-in's open options you'd get something like this in Inventor 2016:
SaveComponentDuringLoad True SaveLocationIndex 1 ComponentDestFolder C:\Users\adamnagy\Documents\Inventor\SW\ AssemDestFolder C:\Users\adamnagy\Documents\Inventor\SW\ SaveAssemSeperateFolder False AddFilenamePrefix False FilenamePrefix AddFilenameSuffix False FilenameSuffix EmbedInDocument True SaveToDisk False ImportSolid True ImportSurface True ImportWire True CreateIFO False ImportAASP False ImportAASPIndex 0 CreateSurfIndex 1 GroupName GroupNameIndex 0 ExplodeMSB2Assm False ImportUnit 0 CheckDuringLoad False AutoStitchAndPromote True AdvanceHealing False EdgeSplitAndMergeDisabled False FaceSplitAndMergeDisabled False AssociativeImport False Selective Import False Link Visibility True
E.g. if you want to import a complete SolidWorks assembly and save the created Inventor files, then the translator has an option for that. You can specify where the created files should be placed and also if they should be saved during the creation of those files, so you don't even have to iterate through them and save them - actually if you save the main assembly and use
Application.SilentOperation = True, that should do the trick too.
The following code can automate the whole import and save part:
Sub ImportAndSaveSolidWorksFiles() Dim oAddIns As ApplicationAddIns Set oAddIns = ThisApplication.ApplicationAddIns ' SolidWorks translator addin Dim oTA As TranslatorAddIn Set oTA = oAddIns.ItemById("{402BE503-725D-41CB-B746-D557AB83BAF1}") ' Activate if needed If Not oTA.Activated Then oTA.Activate Dim oTO As TransientObjects Set oTO = ThisApplication.TransientObjects Dim oDM As DataMedium Set oDM = oTO.CreateDataMedium oDM.FileName = "C:\Gears\gears.SLDASM" Dim oTC As TranslationContext Set oTC = oTO.CreateTranslationContext oTC.Type = kFileBrowseIOMechanism Dim oNVM As NameValueMap Set oNVM = oTO.CreateNameValueMap ' Show the options dialog if you want ' Call oTA.ShowOpenOptions(oDM, oTC, oNVM) ' and print out the available options ' Call PrintInfo(oNVM, 1) ' Set the options we need Call oNVM.Add("SaveComponentDuringLoad", True) Call oNVM.Add("SaveLocationIndex", 1) Call oNVM.Add("ComponentDestFolder", "C:\Users\adamnagy\Documents\Inventor\SW\") Call oNVM.Add("SaveAssemSeperateFolder", False) Dim oDoc As Document Call oTA.Open(oDM, oTC, oNVM, oDoc) End Sub Sub PrintInfo(v As Variant, indent As Integer) If TypeOf v Is NameValueMap Then Dim nvm As NameValueMap Set nvm = v Dim i As Integer For i = 1 To nvm.Count Debug.Print Tab(indent); nvm.Name(i) Call PrintInfo(nvm.Value(nvm.Name(i)), indent + 1) Next Else Debug.Print Tab(indent); v End If End Sub
Result: