' Start of iLogic code ------------------------------------------------------------------------------------- ' Note this iLogic rule takes a copy of the active assembly and associated drawing file ' ...then associates the drawing with the newly copied assembly. ' This rule is a variation on a previous blog by Luke Davenport located here: ' https://www.cadlinecommunity.co.uk/hc/en-us/articles/203347701-Inventor-2016-iLogic-Copy-Assembly-Model-and-Drawing ' This rule allows any name to be input for the copied drawing and assembly, the code in the blog linked above ' ...allows only a suffix to be entered. ' Set drawing extension you are using here by commenting out as required. Dim DWGType As String = ".dwg" 'Dim DWGType As String = ".idw" Dim oDoc As AssemblyDocument = Nothing Try oDoc = ThisApplication.ActiveEditDocument Catch MsgBox("This rule must be run from the assembly document that you wish to copy! - Exiting...", 64, "Cadline iLogic") Return End Try ' Get current filename without extension Dim CurrentFilename As String = System.IO.Path.GetFileNameWithoutExtension(oDoc.FullDocumentName) ' Get current path Dim Path As String = System.IO.Path.GetDirectoryName(oDoc.FullDocumentName) ' Check that the drawing for this assembly can be found If Not System.IO.File.Exists(System.IO.Path.ChangeExtension(oDoc.FullDocumentName, DWGType)) Then MsgBox("Unable to locate the drawing file below for this assembly:" & vbLf & vbLf & _ CurrentFilename & DWGType & vbLf & vbLf & _ "Please make sure it's in the same folder as this assembly, has the same name, and has the file extension '" & DWGType & "'", 64, "Cadline iLogic") Return End If ' Prompt user for job number Dim NewFileName As String = InputBox("You are creating a new copy of this assembly and its 2D drawing file" & vbLf & vbLf & _ "Please input a job number suffix to use for the filename" & vbLf & vbLf & _ "Note the current assembly will be closed and the new one opened...." & vbLf & vbLf & _ "Proceed?", "Cadline - Copy Assembly and Drawing", "0000") If NewFileName = "" Then ' Cancel was hit Return End If ' Perform Save As of Assembly oDoc.SaveAs(Path & "\" & NewFileName & ".iam", False) ' Open the current drawing (in same folder location) Dim DrawingDoc As DrawingDocument = ThisApplication.Documents.Open(Path & "\" & CurrentFilename & DWGType) ' Replace reference to assembly model Dim oFD As FileDescriptor oFD = DrawingDoc.ReferencedFileDescriptors(1).DocumentDescriptor.ReferencedFileDescriptor oFD.ReplaceReference(NewFileName & ".iam") DrawingDoc.Update() ' Perform 'Save As' on the drawing DrawingDoc.SaveAs(Path & "\" & NewFileName & ".dwg", False) ' Make the assembly model active again... oDoc.Activate() ' End of iLogic code ---------------------------------------------------------------------------------------------