Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Auto insert of an earlier done drawing

5 REPLIES 5
Reply
Message 1 of 6
Anonymous
445 Views, 5 Replies

Auto insert of an earlier done drawing

Good afternoon,

 

is there any function or tool implemented in Inventor that would automatically insert part drawings from library as a sheet into documentation? I mean, for example, I am to make technical drawings for about 100 machines. Each has 200 parts, however plenty of them are the same or almost the same. After making 5 of machines I have a lot of parts' drawings. Now I would like to make work clever and create library which would contain drawings of parts, then with help of iLogic, VBA etc. I want Inventor to recognize every similar part and to put it's drawing from the library. Could You help me, please, with finding such an utility?

 

best regards

Mikey

5 REPLIES 5
Message 2 of 6
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
Message 3 of 6
Anonymous
in reply to: Owner2229

Good afternoon,

 

Thank You very much for giving a matter Your's attention. For some reason notification about reply was delayed. Anyway, the parts are the same and have the same name, so it cannot be more easier ; ). The code You have proposed is not what I fully meant, though. It should, rather, search for given machine (assembly) within previously drawn documentation. Here goes an example:

 

Machine #1:

parts' names:

"A1"

"B3"

"C5"

"F7"

let's assume I had drawings for this parts already done

 

Then I start making documentation for machine #2:

consisting parts:

"B3"

"C5"

"D19"

"E6"

"F7"

 

In overall I would have 5 sheets with drawing of each part. 3 of them are the same, thus code should find it in "library" and paste into *.IDW drawing project.

 

Best Regards

Mike 

Message 4 of 6
Owner2229
in reply to: Anonymous

Alright then, so there're (atleast) two possible ways of doing this:

 

1) You can save the current drawing location in the part file when you save your drawing. Ussing OnSaveEvent in the drawing document. And then when you'll re-use these parts, you can simply read the iProperty with the drawing location and copy it from there.

 

Or if the "library" as you speak of, is in one place (eighter in one folder or a group of folders) you can use one of these:

 

If the part file maches, but the drawing name doesn't: Solution 1)

 

If the part file maches and so does the drawing name:

2) Look for the drawing in the library (e.g. by the part name), copy the drawing.

 

 

Let me know which would suit to you and I'll take a look at the coding part.

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
Message 5 of 6
Anonymous
in reply to: Owner2229

Hi,

 

It seems for me that option with the iProperty is more flexible - in this case I can have only one *.IDW file with plenty of drawings as a library. In case of solution no. 2 I would have to have every IDW file for every drawn part. So, I choose the first one : )

 

Best Regards

Mike

Message 6 of 6
Owner2229
in reply to: Anonymous

Very well, just a couple more question:

 

1) Where would you like to store these new drawings and with which name?

        In the same folder and with the same name as the new part?

        Or in an specific folder, like the library?

 

2) I hope you understand that this solution would only work on parts which have this iProperty, so only on parts derived from parts which's drawing will be made after these iLogic rules takes place. Note: You can still copy the rule to these older drawings to make it work.

 

3) Do you know how to set up the OnSaveEvent, or you want me to guide you?

 

4) Another option would be making a list of the partnames and according drawings, but it'll be a real pain, if you have A LOT of parts. Smiley Happy

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report