Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
Owner2229
in reply to: Anonymous

Hi, the code for using pre-made drawings as templates is rather easy. The problem is in identifing the part.

When saying they're the same (or almost) you mean in shape, right? But that's not enough.

We need to find the best way to recognize them, so:

1) Do the "same" parts have the same features (type, amount)?

2) Do they have the same amount of edges?

3) Do they share similiar part numbering (that maybe differs from the other part types)?

4) Are there any specific parameters of iProperties that we could look for?

 

You might want to make a library (a folder, maybe somewhere on server, if you're plaing to share this with coleagues) containing all drawings for each of these part types.

 

Using this recognition technique for future parts might be rather simple. You can make your library with part templates for each of these part types. In this template would be specified the drawing from the library, so the rule wont need to match the part type.

 

Here is the code so far:

 

 

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

' Look for the iProperty containing the drawing template Try SearchedDrawing = iProperties.Value("Custom", "tempDrawing") Catch End Try

' Right now we don't have the recognition code, so I've placed here a simple code
' to make the new drawing based on the template drawing file name. If SearchedDrawing = vbNullString Then Dim oPath As String = "C:\PathToTheDrawingLibrary\"
SearchedDrawing = InputBox("Please enter the file name of the drawing you'd like to make this new drawing from." & vblf & vblf & "Without extension.", "Input", "") SearchedDrawing = oPath & SearchedDrawing & ".idw"
End If
If SearchedDrawing = vbNullString Then Exit Sub End If

' Here is the code to create the new drawing
iProperties.Value("Custom", "tempDrawing") = SearchedDrawing
Dim oDrawing As Document Try oDrawing = ThisApplication.Documents.Open(SearchedDrawing, False) Catch
MsgBox("Couldn't open the drawing.")
Exit Sub End Try oDrawing.Update() oDrawing.SaveAs(oNewName, True) oDrawing.Close(True) Dim oNewDrawing As Document = ThisApplication.Documents.Open(oNewName, True)

' Replace all the model references in the new drawing Dim oRefFile As FileDescriptor For Each oRefFile In oNewDrawing.File.ReferencedFileDescriptors oRefFile.ReplaceReference(oDocName) Next oNewDrawing.Save

' Close the new drawing
oNewDrawing.Close(True) End Sub

 

Right now the rule makes new drawing (IDW) for the currenty open part. You have sayd you want it to "insert part drawings from library as a sheet into documentation". Do you mean to "just" insert new sheet in an actual drawing, so you'll have one drawing with one sheet for every part? It won't be as easy that way.

 

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