Message 1 of 5
Using iLogic to create a unique instance of a component and reset references
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am attempting to use iLogic code to add a component and then save it as a unique instance so that I can create two or more unique instances from the same original model. The code I have written correctly adds the component, creates the new files, and appears to create the unique parts as desired. The problem is that when I close and reopen the assembly the file references do not stay the same and both parts revert to having the same dimensions and referencing only the first set of part files. How can I correct this?
Before closing the file and after reopening:
Below is the code for my saveAs function which creates the unique files for each part and assembly:
'Performs a function similar to 'Place iLogic Component'. This rule 'acts on the component referenced by 'activeComp'. It creates new save 'files for all of the referenced documents for the added component. Dim comp As String comp = activeComp compFile = Left(comp, Len(comp) - 2) & " " & Right(comp, 1) 'The file path to the file the component and parts will be saved to saveLoc = ThisDoc.Path & "\" & compFile & "\" Dim doc As Document 'Reference the proper component assembly doc = ThisAssembly.Components.Item(comp).Occurrence.Definition.Document Try 'Identify and save the component main document Dim displayName As String Dim ref As String displayName = doc.DisplayName ref = Left(displayName, Len(displayName) - 4) ext = "-01" oFile = saveLoc & ref While System.IO.File.Exists(oFile & ext & ".iam") ext = ext & "-01" End While doc.SaveAs(oFile & ext & ".iam", False) Catch MsgBox("Error occurred in saving the main document. The file path may be invalid or files of the same name may already exist.", , "Error Message") End Try Try Dim doc1 As Document Dim name As String 'Iterate through and save all referenced documents Of the chosen assembly For Each doc1 In doc.AllReferencedDocuments name = doc1.DisplayName ref1 = Left(name, Len(name) -4) If doc1.DocumentType = kAssemblyDocumentObject doc1.SaveAs(saveLoc & ref1 & ext & ".iam", False) Else doc1.SaveAs(saveLoc & ref1 & ext & ".ipt", False) End If Next Catch MsgBox("Error occurred in saving the referenced documents. The file path may be invalid or files of the same name may already exist.", , "Error Message") End Try