Save and Replace a Frame assembly from an iLogic rule

Save and Replace a Frame assembly from an iLogic rule

fridtjofZM5ME
Collaborator Collaborator
486 Views
4 Replies
Message 1 of 5

Save and Replace a Frame assembly from an iLogic rule

fridtjofZM5ME
Collaborator
Collaborator

Frame assemblies can't be Save and Replaced with the regular functionality within Inventor because the skeleton.ipt also needs to be copied with it. So as a result, the following snippet won't work with the frame assemblies:

 

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 'This is the main assembly
Dim oFrame As ComponentOccurrence = oAsmClean.ComponentDefinition.Occurrences.ItemByName("SK5-2 fl. iLogic - Frame 001:1") 'this is the frame subassembly
Dim oGD As ComponentOccurrence = oAsmClean.ComponentDefinition.Occurrences.ItemByName("SK5-2 fl. iLogic_GD:1")
Dim oBFocc As ComponentOccurrence = oAsmClean.ComponentDefinition.Occurrences.ItemByName("SK5-2 fl. iLogic_BF:1") 'this is a subassembly containing another frame assembly
	
Dim oColl As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
Dim oCollOcc As ComponentOccurrence
oColl.Add(oFrame)
oColl.Add(oGD)
oColl.Add(oBFocc)
	
ThisApplication.Documents.Open(oAsmClean.FullDocumentName, False)
	
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"
	ThisApplication.Documents.Open(oSubAsm.FullDocumentName, False)	
	oSubAsm.SaveAs(sSubAsmPath, True)
	oSubAsm.Close(True)
	ThisApplication.Documents.Open(sSubAsmPath, False)
	Dim oSubAsmClean As AssemblyDocument = ThisApplication.Documents.ItemByName(sSubAsmPath)
        oAsmClean.ComponentDefinition.Occurrences.ItemByName(oCollOcc.Name).Replace2(oSubAsmClean.FullFileName, False)
        ThisApplication.UserInterfaceManager.DoEvents
Next

 

 

Copying the frame is however possible with Design Assistant, which resembles Vaults Copy Design function, but that doesen't do me any good at all unless I can preform the operation from an iLogic rule.

 

The goal here is to create a create functionality for my configurator assembly, which features all possible configurable components, that will create a copy of the main assembly, and copy replace any subassembly at any level beneath it, to then be able to iterate through everything and delete all suppressed components in in the entire design tree without affecting the configurator assembly or any of its original subassemblies, and then check the copied and cleaned file structure into Vault to then do the copy design (with renaming) routine without having to include the files suppressed in the particular configuration. Less file references going around, less mess, and less potential for errors...

 

It's worth mentioning that this all culminates in a drawing file of flat patterns from sheet metal parts (including the frame members that are authored as sheet metal parts). A lot of the components featured are sheet metal components that originate from solid bodies in parent sheet metal components that may or may not have a split feature activated (which doesen't allow you to have a flat pattern along with it, and thus the reason solid body generated files are there to begin with.)

 

From a more top-down perspective I want to open the configurator, run the rule(s), check in everything, copy/design what I need, and be done with it, with as few mouse clicks as possible.

 

So are there any clever ways to save a copy of a frame assembly from an iLogic rule?

0 Likes
487 Views
4 Replies
Replies (4)
Message 2 of 5

Lucas.dolinarVFXZU
Collaborator
Collaborator

although a little late:
do you know about the ilogic copy command (only usable if all documents are closed)

i don't know if you can automate it using that, but maybe there's a source code of that somewhere...

0 Likes
Message 3 of 5

fridtjofZM5ME
Collaborator
Collaborator

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
Message 4 of 5

HogueOne
Advocate
Advocate

Did you ever figure out the best way to make a copy of an assembly that contains a frame generator assembly without bricking it?

0 Likes
Message 5 of 5

fridtjofZM5ME
Collaborator
Collaborator

Not really no. But to me that doesn't matter either, because I only need to copy the frame to be able to archive the file set sent to manufacturing. You should put in a request for better support of Design Accelerator components within the scope of iLogic, maybe we'll get it in the future.