Hi, here is a code I used to create new drawings from existing drawings, when the drawing views and dimensions are the same in both old and new drawing. You might need to modify it, but I hope it might help you. Run it from the part/assembly you want to create the drawing for.
1) It will first promt you to enter the name of the original drawing
2) It will search for what you've entered in the folder where the current model is
3) Then it will promt you to find the folder, if it can't find the drawing in the folder of the model.
Sub Main()
Dim oDoc As Document = ThisApplication.ActiveDocument
Dim oDocName As String = oDoc.FullFileName
Dim oNewName As String = ThisDoc.Path & "\" & ThisDoc.FileName(False) & ".idw"
Dim SearchedDrawing As String
SearchedDrawing = ThisDoc.FileName(False)
SearchedDrawing = InputBox("Please enter the full name of the drawing that you want to derive the new one from." & vblf & vblf & "Without extension.", "Input", SearchedDrawing)
If SearchedDrawing = vbNullString Then
Exit Sub
End If
Dim oDrawing As Document
Try
oDrawing = ThisApplication.Documents.Open(ThisDoc.Path & "\" & SearchedDrawing & ".idw", False)
Catch
Dim oPath As String = ThisDoc.Path
Dim dialog = New System.Windows.Forms.FolderBrowserDialog()
dialog.SelectedPath = oPath
dialog.ShowNewFolderButton = True
If System.Windows.Forms.DialogResult.OK = dialog.ShowDialog() Then
oPath = dialog.SelectedPath
oDrawing = ThisApplication.Documents.Open(oPath & "\" & SearchedDrawing & ".idw", False)
Else
Exit Sub
End If
End Try
oDrawing.Update()
oDrawing.SaveAs(oNewName, True)
oDrawing.Close(True)
Dim oNewDrawing As Document = ThisApplication.Documents.Open(oNewName, True)
Dim oRefFile As FileDescriptor
For Each oRefFile In oNewDrawing.File.ReferencedFileDescriptors
oRefFile.ReplaceReference(oDocName)
Next
oNewDrawing.Save
End Sub
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike
"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods