I somehow got it to work tolerable. Its not entirely without its faults and errors, but it gets the job done. My configurator is essentially all possible solutions on top of each other, with the iLogic suppressing/unsuppressing components as needed. I initially just ran the configurator, checked the entire thing into Vault and ran the copy/design command from there, but since that generates a huge amount of uneccesary files and references, I wrote a code that makes copies of the drawing and the main assembly that runs from the idw-file, I then run the external code below from the copy of the main assembly to remove anything that isn't needed. This also includes frame members, so I also need a copy of the Frame subassembly. There was some issue with the skeleton.ipt preventing the frame assembly to copy replace, but by replacing the skeleton with a copy first, then making the copy of the frame, and closing the original frame without saving it after making the copy, I got it to work somehow. It renders the copied frame unusable to work with afterwards, but that doesen't matter as the copied set of files are the final file set used for manufacturing the parts, and will likely never be used for anything again.
Option Explicit On
Sub Main()
ThisApplication.CommandManager.ControlDefinitions.Item("iLogic.FreeILogicMemory").Execute
InventorVb.UpdateWhenDone = True
InventorVb.DocumentUpdate
Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim sDocName As String = oDoc.DisplayName
Dim sConfigName2fl As String = "SK5-2 fl. iLogic_skjæring.idw"
Dim sConfigName1fl As String = "SK5-1 fl. iLogic_skjæring.idw"
If ((sDocName = sConfigName2fl) Or (sDocName = sConfigName1fl)) Then
Return
Else
DeleteOld()
ReplaceRef()
CleanViews()
SaveReplaceCollection()
CleanAsm()
oDoc.Update2(True)
oDoc.Save2(True)
ThisApplication.UserInterfaceManager.DoEvents
End If
MessageBox.Show("And then, 3488 lines of code latar, this apparently rendered the desired results...", "Yippie-kay-yay, mother****er! We're done!!! :-D")
End Sub
Sub DeleteOld()
Dim oFrameSkel As Document = TryCast(ThisApplication.Documents.Open("D:\VaultWS\Designs\Produkter\iLogic\SK5\SK5-2 fl - iLogic\Frame\SK5-2 fl. iLogic_cleaned - Skeleton 001.ipt", False), Document)
Dim oBFframeSkel As Document = TryCast(ThisApplication.Documents.Open("D:\VaultWS\Designs\Produkter\iLogic\SK5\SK5-2 fl - iLogic\Frame\SK5-2 fl. iLogic_BF_cleaned - Skeleton 001.ipt", False), Document)
Dim oFrame As Document = TryCast(ThisApplication.Documents.Open("D:\VaultWS\Designs\Produkter\iLogic\SK5\SK5-2 fl - iLogic\Frame\SK5-2 fl. iLogic_cleaned - Frame 001.iam", False), Document)
Dim oBFframe As Document = TryCast(ThisApplication.Documents.Open("D:\VaultWS\Designs\Produkter\iLogic\SK5\SK5-2 fl - iLogic\Frame\SK5-2 fl. iLogic_BF_cleaned - Frame 001.iam", False), Document)
Dim oGD As Document = TryCast(ThisApplication.Documents.Open("D:\VaultWS\Designs\Produkter\iLogic\SK5\SK5-2 fl - iLogic\SK5-2 fl. iLogic_GD_cleaned.iam", False), Document)
Dim oBF As Document = TryCast(ThisApplication.Documents.Open("D:\VaultWS\Designs\Produkter\iLogic\SK5\SK5-2 fl - iLogic\SK5-2 fl. iLogic_BF_cleaned.iam", False), Document)
Dim oAsm As Document = TryCast(ThisApplication.Documents.Open("D:\VaultWS\Designs\Produkter\iLogic\SK5\SK5-2 fl - iLogic\SK5-2 fl. iLogic_cleaned.iam", False), Document)
Dim oCrapCollection As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
oCrapCollection.Add(oFrameSkel.File)
oCrapCollection.Add(oBFframeSkel.File)
oCrapCollection.Add(oFrame.File)
oCrapCollection.Add(oBFframe.File)
oCrapCollection.Add(oGD.File)
oCrapCollection.Add(oBF.File)
oCrapCollection.Add(oAsm.File)
oFrameSkel.Close
oBFframeSkel.Close
oFrame.Close
oBFframe.Close
oGD.Close
oBF.Close
oAsm.Close
Dim oCrap As File
For Each oCrap In oCrapCollection
Try
System.IO.File.Delete(oCrap.FullDocumentName)
Catch
Continue For
End Try
Next
End Sub
Sub ReplaceRef()
Logger.Info("Running ReplaceRef")
Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oFS As Sheet = oDoc.Sheets.Item(1)
Dim iViewCount As Integer = oFS.DrawingViews.Count
Dim oMasterDrawView As DrawingView = oFS.DrawingViews.Item(iViewCount)
Dim oAsm As AssemblyDocument = oMasterDrawView.ReferencedDocumentDescriptor.ReferencedDocument
Dim sAsmCleanName As String = Left(oAsm.FullDocumentName, Len(oAsm.FullDocumentName) -4) & "_cleaned.iam"
If oAsm.FullDocumentName <> sAsmCleanName Then
Try
oMasterDrawView.ReferencedDocumentDescriptor.ReferencedFileDescriptor.ReplaceReference(sAsmCleanName)
Catch
End Try
End If
ThisApplication.UserInterfaceManager.DoEvents
End Sub
Sub CleanViews()
Logger.Info("Running CleanViews")
Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oSheets As Sheets = oDoc.Sheets
Dim oSheet As Sheet
Dim oView As DrawingView
For Each oSheet In oSheets
For Each oView In oSheet.DrawingViews
Try
If oView.Suppressed = True Then
oView.Delete
Else
Continue For
End If
Catch
Continue For
End Try
Next
Next
End Sub
Sub SaveReplaceCollection()
Logger.Info("Running SaveReplaceCollection")
Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oFS As Sheet = oDoc.Sheets.Item(1)
Dim iViewCount As Integer = oFS.DrawingViews.Count
Dim oMasterView As DrawingView = oFS.DrawingViews.Item(iViewCount)
Dim oAsmClean As AssemblyDocument = oMasterView.ReferencedDocumentDescriptor.ReferencedDocument
Logger.Debug(oAsmClean.FullDocumentName)
ThisApplication.Documents.Open(oAsmClean.FullDocumentName, False)
Dim oFrame As ComponentOccurrence
Dim oGD As ComponentOccurrence
Dim oBFocc As ComponentOccurrence
Dim oColl As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
Dim oCollOcc As ComponentOccurrence
If oAsmClean.FullDocumentName = "D:\VaultWS\Designs\Produkter\iLogic\SK5\SK5-2 fl - iLogic\SK5-2 fl. iLogic_cleaned.iam" Then
oGD = oAsmClean.ComponentDefinition.Occurrences.ItemByName("SK5-2 fl. iLogic_GD:1")
oBFocc = oAsmClean.ComponentDefinition.Occurrences.ItemByName("SK5-2 fl. iLogic_BF:1")
oColl.Add(oGD)
oColl.Add(oBFocc)
Else If oAsmClean.FullDocumentName = "D:\VaultWS\Designs\Produkter\iLogic\SK5\SK5-1 fl - iLogic\SK5-1 fl. iLogic_cleaned.iam" Then
oGD = oAsmClean.ComponentDefinition.Occurrences.ItemByName("SK5-1 fl. iLogic_GD:1")
oColl.Add(oGD)
End If
For Each oCollOcc In oColl
Dim oSubAsm As AssemblyDocument = oCollOcc.Definition.Document
Dim sSubAsmPath As String = Left(oSubAsm.FullDocumentName, Len(oSubAsm.FullDocumentName) -4) & "_cleaned.iam"
Logger.Debug("Opening " & oSubAsm.FullDocumentName &" in background")
ThisApplication.Documents.Open(oSubAsm.FullDocumentName, False)
ThisApplication.UserInterfaceManager.DoEvents
Logger.Debug("Saving " & oSubAsm.FullDocumentName & " as " & sSubAsmPath)
oSubAsm.SaveAs(sSubAsmPath, True)
ThisApplication.UserInterfaceManager.DoEvents
Logger.Debug("Events done!")
Logger.Debug("Closing "& oSubAsm.FullDocumentName)
oSubAsm.Close(True)
ThisApplication.UserInterfaceManager.DoEvents
Logger.Debug("Opening " & sSubAsmPath &" in background")
ThisApplication.Documents.Open(sSubAsmPath, False)
ThisApplication.UserInterfaceManager.DoEvents
Dim oSubAsmClean As AssemblyDocument = ThisApplication.Documents.ItemByName(sSubAsmPath)
Logger.Debug("Replacing " & oSubAsm.FullDocumentName & " with " & oSubAsmClean.FullDocumentName)
oAsmClean.ComponentDefinition.Occurrences.ItemByName(oCollOcc.Name).Replace(oSubAsmClean.FullDocumentName, False)
ThisApplication.UserInterfaceManager.DoEvents
Next
If oAsmClean.FullDocumentName = "D:\VaultWS\Designs\Produkter\iLogic\SK5\SK5-2 fl - iLogic\SK5-2 fl. iLogic_cleaned.iam" Then
Dim oFrameOcc As ComponentOccurrence = oAsmClean.ComponentDefinition.Occurrences.ItemByName("SK5-2 fl. iLogic - Frame 001:1")
Dim oFrameAsm As AssemblyDocument = oFrameOcc.Definition.Document
Dim oFrameFile As File = oFrameAsm.File
Dim sFrameClean As String = Left(oFrameAsm.FullDocumentName, Len(oFrameAsm.FullDocumentName) -16) & "_cleaned - Frame 001.iam"
Dim oFrameSkel As PartDocument = oFrameOcc.SubOccurrences.Item(1).Definition.Document
Dim oFrameSkelFile As File = oFrameSkel.File
Dim sFrameSkelName As String = Left(oFrameSkel.FullDocumentName, Len(oFrameSkel.FullDocumentName) -19) & "_cleaned - Skeleton 001.ipt"
System.IO.File.Copy(oFrameSkelFile.FullFileName, sFrameSkelName, True)
System.IO.File.Copy(oFrameFile.FullfileName, sFrameClean, True)
Dim oFrameClean As AssemblyDocument = ThisApplication.Documents.Open(sFrameClean, False)
oFrameClean.ComponentDefinition.Occurrences.Item(1).Replace(sFrameSkelName, False)
ThisApplication.UserInterfaceManager.DoEvents
oFrameOcc.Replace(sFrameClean, False)
Dim oBF As AssemblyDocument = oAsmClean.ComponentDefinition.Occurrences.ItemByName("SK5-2 fl. iLogic_BF_cleaned:1").Definition.Document
Dim oBFframeOcc As ComponentOccurrence = oBF.ComponentDefinition.Occurrences.ItemByName("SK5-2 fl. iLogic_BF - Frame 001:1")
Dim oBFframeAsm As AssemblyDocument = oBFframeOcc.Definition.Document
Dim oBFframeFile As File = oBFframeAsm.File
Dim sBFframeClean As String = Left(oBFframeAsm.FullDocumentName, Len(oBFframeAsm.FullDocumentName) -16) & "_cleaned - Frame 001.iam"
Dim oBFframeSkel As PartDocument = oBFframeOcc.SubOccurrences.Item(1).Definition.Document
Dim oBFframeSkelFile As File = oBFframeSkel.File
Dim sBFframeSkelName As String = Left(oBFframeSkel.FullDocumentName, Len(oBFframeSkel.FullDocumentName) -19) & "_cleaned - Skeleton 001.ipt"
System.IO.File.Copy(oBFframeSkelFile.FullFileName, sBFframeSkelName, True)
System.IO.File.Copy(oBFframeFile.FullFileName, sBFframeClean, True)
Dim oBFframeClean As AssemblyDocument = ThisApplication.Documents.Open(sBFframeClean, False)
oBFframeClean.ComponentDefinition.Occurrences.Item(1).Replace(sBFframeSkelName, False)
ThisApplication.UserInterfaceManager.DoEvents
oBFframeOcc.Replace(sBFframeClean, False)
Else If oAsmClean.FullDocumentName = "D:\VaultWS\Designs\Produkter\iLogic\SK5\SK5-1 fl - iLogic\SK5-1 fl. iLogic_cleaned.iam" Then
Dim oFrameOcc As ComponentOccurrence = oAsmClean.ComponentDefinition.Occurrences.ItemByName("SK5-1 fl. iLogic - Frame 001:1")
Dim oFrameAsm As AssemblyDocument = oFrameOcc.Definition.Document
Dim oFrameFile As File = oFrameAsm.File
Dim sFrameClean As String = Left(oFrameAsm.FullDocumentName, Len(oFrameAsm.FullDocumentName) -16) & "_cleaned - Frame 001.iam"
Dim oFrameSkel As PartDocument = oFrameOcc.SubOccurrences.Item(1).Definition.Document
Dim oFrameSkelFile As File = oFrameSkel.File
Dim sFrameSkelName As String = Left(oFrameSkel.FullDocumentName, Len(oFrameSkel.FullDocumentName) -19) & "_cleaned - Skeleton 001.ipt"
System.IO.File.Copy(oFrameSkelFile.FullFileName, sFrameSkelName, True)
System.IO.File.Copy(oFrameFile.FullFileName, sFrameClean, True)
Dim oFrameClean As AssemblyDocument = ThisApplication.Documents.Open(sFrameClean, False)
oFrameClean.ComponentDefinition.Occurrences.Item(1).Replace(sFrameSkelName, False)
ThisApplication.UserInterfaceManager.DoEvents
oFrameOcc.Replace(sFrameClean, False)
End If
oAsmClean.Update2(True)
End Sub
Sub CleanAsm()
Logger.Info("Running CleanAsm")
Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oFS As Sheet = oDoc.Sheets.Item(1)
Dim iViewCount As Integer = oFS.DrawingViews.Count
Dim oMasterView As DrawingView = oFS.DrawingViews.Item(iViewCount)
Dim oAsmClean As AssemblyDocument = oMasterView.ReferencedDocumentDescriptor.ReferencedDocument
Logger.Debug(oAsmClean.FullDocumentName)
Dim oFrame As AssemblyDocument
Dim oGD As AssemblyDocument
Dim oBF As AssemblyDocument
Dim oMidtstokk As AssemblyDocument
Dim oColl As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
Dim oCollObj As AssemblyDocument
If oAsmClean.FullDocumentName = "D:\VaultWS\Designs\Produkter\iLogic\SK5\SK5-2 fl - iLogic\SK5-2 fl. iLogic_cleaned.iam" Then
oGD = oAsmClean.ComponentDefinition.Occurrences.ItemByName("SK5-2 fl. iLogic_GD_cleaned:1").Definition.Document
oBF = oAsmClean.ComponentDefinition.Occurrences.ItemByName("SK5-2 fl. iLogic_BF_cleaned:1").Definition.Document
Try
oMidtstokk = oBF.ComponentDefinition.Occurrences.ItemByName("SK5-2 fl. iLogic_BF_cleaned - Frame 001:1").Definition.Document
oFrame = oAsmClean.ComponentDefinition.Occurrences.ItemByName("SK5-2 fl. iLogic_cleaned - Frame 001:1").Definition.Document
Catch
MessageBox.Show("Kjør Design Assistant på Frame assemblies først!", "Finner ikke riktig Frame-fil!", MessageBoxButtons.OK)
Return
End Try
oColl.Add(oFrame)
oColl.Add(oGD)
oColl.Add(oMidtstokk)
oColl.Add(oBF)
oColl.Add(oAsmClean)
Else If oAsmClean.FullDocumentName = "D:\VaultWS\Designs\Produkter\iLogic\SK5\SK5-1 fl - iLogic\SK5-1 fl. iLogic_cleaned.iam" Then
Try
oGD = oAsmClean.ComponentDefinition.Occurrences.ItemByName("SK5-1 fl. iLogic_GD_cleaned:1").Definition.Document
Catch
Dim oGDclean As AssemblyDocument = oAsmClean.ComponentDefinition.Occurrences.ItemByName("SK5-1 fl. iLogic_GD:1").Definition.Document
If oGDclean.FullFileName.EndsWith("_cleaned.iam") Then
oGD = oAsmClean.ComponentDefinition.Occurrences.ItemByName("SK5-1 fl. iLogic_GD:1").Definition.Document
End If
End Try
Try
oFrame = oAsmClean.ComponentDefinition.Occurrences.ItemByName("SK5-1 fl. iLogic_cleaned - Frame 001:1").Definition.Document
Catch
Dim oFrameClean As AssemblyDocument = oAsmClean.ComponentDefinition.Occurrences.ItemByName("SK5-1 fl. iLogic - Frame 001:1").Definition.Document
If oFrameClean.FullFileName.Contains("_cleaned") Then
oFrame = oAsmClean.ComponentDefinition.Occurrences.ItemByName("SK5-1 fl. iLogic - Frame 001:1").Definition.Document
End If
'MessageBox.Show("Kjør Design Assistant på Frame assemblies først!", "Finner ikke riktig Frame-fil!", MessageBoxButtons.OK)
'Return
End Try
oColl.Add(oFrame)
oColl.Add(oGD)
oColl.Add(oAsmClean)
End If
Logger.Info("No. of occurrences in collection: "& oColl.Count)
Dim sRuleName As String = "PurgeSuppressed"
For Each oCollObj In oColl
Logger.Info("Running PurgeSuppressed in " & oCollObj.FullDocumentName)
Dim sPath As String = oCollObj.FullDocumentName
Dim oRunDoc As Document = ThisApplication.Documents.Open(sPath, True)
iLogicVb.Automation.RunExternalRule(oRunDoc, sRuleName)
ThisApplication.UserInterfaceManager.DoEvents
oRunDoc.Close
Next
sRuleName = "ConstraintCleaner"
For Each oCollObj In oColl
Logger.Info("Running PurgeSuppressed in " & oCollObj.FullDocumentName)
Dim sPath As String = oCollObj.FullDocumentName
Dim oRunDoc As Document = ThisApplication.Documents.Open(sPath, True)
iLogicVb.Automation.RunExternalRule(oRunDoc, sRuleName)
ThisApplication.UserInterfaceManager.DoEvents
oRunDoc.Close
Next
End Sub