Copy components and assembly

Copy components and assembly

ngowans
Contributor Contributor
439 Views
3 Replies
Message 1 of 4

Copy components and assembly

ngowans
Contributor
Contributor

I have an iLogic assembly of a handful of sheetmetal components which are driven by an Ilogic form. So far this all works brilliantly. However I would like to make a script which saves a copy of the assembly and all of it's constituent parts into a specific folder at the click of a button and ensures they retain their relationships. In the process I would like to remove all the ilogic scripts and forms as well as supressed components from the top level assembly so I have a more or less static record of a specific configuration of the assembly. 

 

So far my manual workflow involves the following.

1 - Using my form I set my geometry to whichever specific arrangement I need.

ngowans_0-1649923902882.png

 

2 - This sets the part numbers of all components correctly based on their geometry.

 

3 - I then click "copy" within the pattern menu in the assembly.

4 - I select all parts by selecting the top level of the assembly in the browser. This normally ignores anything supressed and reuses any design centre parts

ngowans_1-1649923925576.png

 

5 - I select next, then select "create new assembly" 

6 - I then rename all my parts with a suitable suffix in this case P-001

7 - I create a folder by choosing workspace and then typing \P-001

ngowans_3-1649924042638.png

Clicking ok creates the appropriate files in the appropriate folder and all is good, however I want this process to be fully automatic based on the part number of the top level assembly or the value of an arbitrary custom iproperty (or maybe even a parameter) and function with the click of a single button for any future assembly arrangement. 

 

 So far I am able to create my folder automatically based on whether a suitably named folder already exists in the appropriate location. But I haven't found anything which will do the actual saving and rereferencing of the files in an appropriate way. They normally just refer to the master file which is no good. Anything I find online just seems to want to refer me to ilogic design copy. 

 

Can anyone help?

 

 

 

0 Likes
440 Views
3 Replies
Replies (3)
Message 2 of 4

dalton98
Collaborator
Collaborator

This should be what your looking for. You will have to manually delete the forms.

'create folder in project file
Dim IPJ As String
Dim IPJ_Name As String
Dim IPJ_Path As String
Dim FNamePos As Long
IPJ = ThisApplication.FileLocations.FileLocationsFile
FNamePos = InStrRev(IPJ, "\", -1)    
IPJ_Name = Right(IPJ, Len(IPJ) - FNamePos)
IPJ_ShortName = Left(IPJ_Name, Len(IPJ_Name) - 4)
IPJ_Folder_Location = Left(IPJ, Len(IPJ) -Len(IPJ_Name))

Dim oFolder As String
oFolder = IPJ_Folder_Location & "P-001\"
If System.IO.Directory.Exists(oFolder) = False
	System.IO.Directory.CreateDirectory(oFolder)
End If

'copy current assembly
Dim oAss As AssemblyDocument
oAss = ThisApplication.ActiveDocument
Dim newAss As String = oFolder & System.IO.Path.GetFileNameWithoutExtension(oAss.FullDocumentName) & "-P-001.iam"
oAss.SaveAs(newAss, True)

'open new assembly
Dim oAssNew As AssemblyDocument
oAssNew = ThisApplication.Documents.Open(newAss, True)

'go through each component in the assembly, copy, replace
Dim oOcc As ComponentOccurrence
For Each oOcc In oAssNew.ComponentDefinition.Occurrences
	If oOcc.Suppressed = False
	Dim oDoc As Document
	oDoc = oOcc.Definition.Document
	If oDoc.DocumentType = kPartDocumentObject
		Dim newDoc As String = oFolder & System.IO.Path.GetFileNameWithoutExtension(oDoc.FullDocumentName) & "-P-001.ipt"
		Try
		oDoc.SaveAs(newDoc, True)
		Catch
		End Try
		oOcc.Replace(newDoc, False)
	End If
	End If
Next

iLogicVb.Automation.DeleteAllRulesInDocument(oAssNew)
0 Likes
Message 3 of 4

1830108CDDDF
Contributor
Contributor

Hi @dalton98, I've just found this thread, the code you posted seems to work pretty well in the top level of the assembly, it could be modified in a way that works with everything involved in the assembly? E.g. Sub-assemblies and its parts. 

Thanks in advanced, greetings!

0 Likes
Message 4 of 4

dalton98
Collaborator
Collaborator

@1830108CDDDF Hello. This is sloppy and not well written so you would probably be better off creating a new topic haha(was fairly new to ilogic).

If you want the reach sub assemblies you would need to create a recursive sub routine that would loop through each component  ex.

Sub Main
	Dim oADoc As AssemblyDocument = ThisDoc.Document
	Call RecursiveOccurrences(oADoc.ComponentDefinition.Occurrences)
End Sub

Sub RecursiveOccurrences(oOccs As ComponentOccurrences)
	For Each oOcc As ComponentOccurrence In oOccs
		If oOcc.Definition.Document.DocumentType = kAssemblyDocumentObject
			'loop through each sub occurrence
			Call  RecursiveOccurrences(oOcc.SubOccurrences)
		ElseIf oOcc.Definition.Document.DocumentType = kPartDocumentObject
			'do  stuff
			'MessageBox.Show("Message", "Title")
			'Return
		End If
	Next
End Sub