- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I need an ilogic rule that will let me save an assembly and its parts and subassemblies into designated folder, with a changed prefix.
So what the rule would do is save an assembly and its components with a changed prefix, and then replaced old components in a new assembly with new components with updated prefix.
So it would look like this:
Original assembly:
ER-1_1.1(A)_Main_assembly
ER-1_1.1(A)_Part_1
ER-1_1.1(A)_Part_2
ER-1_1.1(A)_Part_3
ER-1_1.1(A)_Subassembly
ER-1_1.1(A)_Subassembly_Part1
And i would like to copy and replace with other prefix like this:
ER-2_2.2(B2)_Main_assembly
ER-2_2.2(B2)_Part_1
ER-2_2.2(B2)_Part_2
ER-2_2.2(B2)_Part_3
ER-2_2.2(B2)_Subassembly
ER-2_2.2(B2)_Subassembly_Part1
I found this post with similiar rule that i need :
and it was solved by @WCrihfield
But naming in this rule is different, here is the rule:
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then MsgBox("This rule '" & iLogicVb.RuleName & "' only works for Assembly Documents.",vbOK, "WRONG DOCUMENT TYPE") Return End If Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument Dim oFileDlg As Inventor.FileDialog = Nothing ThisApplication.CreateFileDialog(oFileDlg) oFileDlg.Filter = "Autodesk Inventor Assembly Files (*.iam)|*.iam" oFileDlg.InitialDirectory = ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath oFileDlg.FileName = IO.Path.GetFileName(oADoc.FullFileName).TrimEnd("."c,"i"c,"a"c,"m"c) oFileDlg.DialogTitle = "Specify New Name & Location For Copied Assembly" oFileDlg.CancelError = True On Error Resume Next oFileDlg.ShowSave If Err.Number <> 0 Then MsgBox("No File Saved.", vbOKOnly, "DIALOG CANCELED") ElseIf oFileDlg.FileName <> "" Then oNewFileName = oFileDlg.FileName oADoc.SaveAs(oNewFileName, False) End If oADoc = Nothing InventorVb.DocumentUpdate() oADoc = ThisApplication.ActiveDocument Dim oLast3Chars As String For Each oRefDoc As Document In oADoc.AllReferencedDocuments ThisApplication.Documents.Open(oRefDoc.FullFileName,False) oLast3Chars = Left(Right(oRefDoc.FullFileName, 7), 3) If oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then oRefDoc.SaveAs(Left(oADoc.FullFileName, Len(oADoc.FullFileName) -4) & oLast3Chars & ".ipt", True) ElseIf oRefDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then oRefDoc.SaveAs(Left(oADoc.FullFileName, Len(oADoc.FullFileName) -4) & oLast3Chars & ".iam", True) End If oRefDoc.Close Next Dim oOccDoc As Document Dim oOccNewFileName As String For Each oOcc As ComponentOccurrence In oADoc.ComponentDefinition.Occurrences oOccDoc = oOcc.Definition.Document oLast3Chars = Left(Right(oOccDoc.FullFileName, 7), 3) If oOccDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then oOccNewFileName = Left(oADoc.FullFileName,Len(oADoc.FullFileName)-4) & oLast3Chars & ".ipt" ElseIf oOccDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then oOccNewFileName = Left(oADoc.FullFileName,Len(oADoc.FullFileName)-4) & oLast3Chars & ".iam" End If oOcc.Replace(oOccNewFileName, True) Next
So what i needed to change in it was how the names were generated, but i cant figure it out.
i have tried using lines like this:
Old_prefix = InputBox("Please enter old prefix", "Warning", "")
New_prefix = InputBox("Please enter new prefix", "Warning", "")
Replace(oADoc.FullFileName, Old_prefix, New_prefix)
So that i could just type in old prefix and new prefix and it would replace the prefix in part name, but i cant really make it work.
I think i have a problem with getting a proper path and filename for the files that i am saving.
i also tried something like this
oRefDoc.SaveAs(Replace(oADoc.FullFileName, Old_prefix, New_prefix) & ".ipt", True)
But it still did not work.
Any tips how to do it properly?
Solved! Go to Solution.