Greetings,
Anyone here have a code available that can be added to populate a parts list with a "Y" or "N" to verify if a part in an assembly has an existing drawing in the current project folder?
Typically, we have drawings for our manufactured parts (but not all of them currently), and no drawings for purchased parts.
My parts list contains the typical columns like "Item", "Part #", "Qty", "Description", etc, but I'd like to have an automated "DWG" column that self-populates when Inventor determines that a drawing exists for the individual parts in that parts list like shown in the picture.
Thanks, Harvey
Solved! Go to Solution.
Solved by Curtis_Waguespack. Go to Solution.
The only way to find drawings is search EVERY folders in Workspace.
EVERY time the drawing is updated.
Still it won't know if the drawing is deleted after.
Hi @harvey3ELEA. If all your drawings are in the same exact folder as the model file they are documenting, and the drawing file is named exactly the same as the model file, just with the different file extension, then that would make a process like this much easier to manage. However, it can still be a pretty inaccurate process. There is no 'link' added to a model file that says it has had a drawing made for it. Only the drawing document will know which model files are being referenced within it.
With that in mind, a better long term process might be to have some code that runs when you save any drawings, and in that code, have it inspect the model documents being referenced within the views of the drawing, then write something into those model documents, such as a custom iProperty, about the drawing. This code could be an external rule, or some other type of external tool, so that it could be ran on older drawings too, at some point. Then all new drawings, and all drawings that get edited and saved, will be writing this wanted data back into the models. Then those models will contain something (possibly a custom iProperty) that can be used for your PartsList column. It would take a while to build up that system though.
Wesley Crihfield
(Not an Autodesk Employee)
Another thought that comes to mind is that if you use Vault, then you may be able to use that somehow to find if a model has a drawing. I have not used Vault yet myself though, so I would not know how to get that information from Vault by code. A potential problem with using Vault for this, is that it may only find every drawing that references that model, at any level. So, if the model is a part, and it is being used in 25 assemblies, and those 25 assemblies all have drawings, it may find all those in its search. Not sure if Vault can limit a search like that to only 'directly references', and not referencing indirectly. Just another thought that might be explored.
Wesley Crihfield
(Not an Autodesk Employee)
Frederick, while I won't say never, we likely won't delete any drawings, just change or obsolete them into a separate folder.
Wesley, we don't use Vault here at work (I'm not sad about that), and I simply don't know where to take this issue going forward. If you have any ilogic coding that could start me off in the right direction, I'm willing to take a crack at tweaking it to the best of my ability to see what results I can achieve. If not, no problem....I'd resort to just doing the manual entry to have something available for the shop guys.
Since you know which part should have drawing, set it up on the model.
The property "DWG" should be in the part/assembly.
Whoever make drawing will update the model with "Y".
Drawing partlist will update with the model.
Frederick, that will work, but we have a lot of legacy parts that never had drawings made for a variety of reasons.
Setting it up in the model is workable, but it's still a manual process. I'd rather see if Inventor can determine if a drawing already exists, and if not, place an "N" on the parts list.......which would also notify me that a drawing needs to be made.
Hi @harvey3ELEA
Can the path to your drawings be deduced from the model path?
If you can predict the path, then we could write a routine to process the assembly that the parts list is pointing to and write a custom iProperty to each component that records the Y or N, and then that iprop can be shown in the parts list.
Meaning something like this where we can know that changing the extension points us to the drawing:
Or something like this where we can know that changing the extension and looking in a known, standard folder points us to the drawing:
Curtis,
Yes to your question. We keep parts, assemblies, sub-assemblies, and their respective drawings pathed to the same folder. Some sort of ilogic routine to look for an .idw in the same project folder would work very well in this case, in my opinion.
Unfortunately, I am not a competent ilogic code creator, but I have had some success modifying them to suit my needs.
If you're willing, I'd love to see what you come up with...
Thanks, Harvey
Hi @harvey3ELEA
Give this example a try. It doesn't actually write down to the models, but maybe writing to the parts list is all that is needed?
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Sub Main Dim oDrawDoc As Document = ThisApplication.ActiveDocument Dim oSheet As Sheet = oDrawDoc.ActiveSheet Dim oPartList As PartsList Try oPartList = oDrawDoc.ActiveSheet.PartsLists.Item(1) Catch MsgBox("no parts list found on active sheet", , "iLogic") Exit Sub End Try For Each oPartListRow In oPartList.PartsListRows Dim hasDWG As String = "N" 'set default If oPartListRow.Visible = False Then Continue For Dim oBomRow As DrawingBOMRow = oPartListRow.ReferencedRows.Item(1) Dim oRefDoc As Document = oBomRow.BOMRow.ComponentDefinitions.Item(1).Document Dim oCell As PartsListCell oFilePath = oRefDoc.FullFileName() oDrawingFilePath = Left(oFilePath, Len(oFilePath) -3) & "idw" If System.IO.File.Exists(oDrawingFilePath) = True Then hasDWG = "Y" 'find the cell using the row and the column name Try oCell = oPartListRow.Item("DWG") Catch MsgBox("Parts list does not contain a column called DWG", , "iLogic") Exit Sub End Try oCell.value = hasDWG Next End Sub
Curtis, that little gem runs beautifully! Thank you very much for that little trick which will now tell me and my shop guys what drawings are missing, need to be made for legacy parts, and which drawing they'll know they can pull up on their tablets during production.
One suggestion if you feel like tweaking it: is there a way for this code to add a "DWG" column automatically? If not, it's no big deal to manually add that in prior to running the code.
Thanks again! Harvey
Hi @harvey3ELEA ,
Glad that worked. I meant to look into adding the column, but got distracted earlier and forgot.
See this version, it will always add it to the end of the parts lists columns.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Sub Main Dim oDrawDoc As Document = ThisApplication.ActiveDocument Dim oSheet As Sheet = oDrawDoc.ActiveSheet Dim oRefDoc As Document Dim oPartList As PartsList Try oPartList = oDrawDoc.ActiveSheet.PartsLists.Item(1) Catch MsgBox("no parts list found on active sheet", , "iLogic") Exit Sub End Try For Each oPartListRow In oPartList.PartsListRows Dim hasDWG As String = "N" 'set default Dim oBomRow As DrawingBOMRow = oPartListRow.ReferencedRows.Item(1) Try oRefDoc = oBomRow.BOMRow.ComponentDefinitions.Item(1).Document Catch Continue For End Try Dim oCell As PartsListCell oFilePath = oRefDoc.FullFileName() oDrawingFilePath = Left(oFilePath, Len(oFilePath) -3) & "idw" If System.IO.File.Exists(oDrawingFilePath) = True Then hasDWG = "Y" 'find the cell using the row and the column name Try oCell = oPartListRow.Item("DWG") Catch oColumn = oPartList.PartsListColumns.Add(PropertyTypeEnum.kCustomProperty, , "DWG", 0) oCell = oPartListRow.Item("DWG") End Try oCell.Value = hasDWG Next End Sub
Curtis, that's a homerun! A truly useful routine that helps to streamline our files and shop processes.
I simply run a column adjuster code after yours to get the best fit on the drawing.
Thanks again! Harvey
Can't find what you're looking for? Ask the community or share your knowledge.