How to buy
Privacy | Do not sell or share my personal information | Cookie preferences | Report noncompliance | Terms of use | Legal | © 2025 Autodesk Inc. All rights reserved
Hi,
Normally I put idw files in same location as ipt/iam source files.
But in some cases idw files is not located in the same of ipt/iam source files. But if I want to use "Open Drawing" from model tree of ipt/iam files Inventor can find the idw file and open.
I want to do same thing from my BOM tree code. Normally I can iterate BOM tree and find fileLocation of ipt/iam fil then change ipt/iam to idw and I can open file easily.
But if the file locations are not same then it's impossible to open idw files?
How can I find idw locations with VB.NET?
Regards,
Mucip:)
Solved! Go to Solution.
Hi @mucip. If your code is iterating through an assembly's BOM, then not only is the assembly open, but all the files that the assembly is actively referencing have also been 'initiated'. What that means is, they have been partially loaded into Inventor's session memory, but not fully or visibly opened yet, so no document tabs for them. If you have Inventor's 'status bar' showing, then you will see two numbers showing within its right side. One (furthest right) is the number of open documents in session, while the other is the total number of occurrences in the active document.
With that in mind, there is a property of all Document type objects called ReferencingDocuments that may help. It will only be able to find/include the other Documents that are currently loaded in Inventor's memory, and are currently referencing that Document. So, if the drawing for that model document was already open, or somehow invisibly loaded into Inventor's memory, then from that model document, you may be able to find that drawing within that collection. However, the assembly will also be referencing that model file, and any other sub assemblies that it is in will be in there also. So, if it is in there, it may not be the only one in there. Plus, if there are any drawings open for the whole/main assembly, then that drawing will also be referencing that model document, because it is referencing the assembly, and it is referenced by the assembly. But if the drawing is not already open, then this property would not be able to help any. Maybe if you had something like Vault installed and were using that, and all these files were currently being 'managed' by it, then there may be a way to use Vault to find the drawing file that references that model file, because it keeps all file references in an active database.
The Document.FindWhereUsed method works about the same way. It will only search within the other documents that are currently loaded in the active session of Inventor, and won't search your entire file system. There is a standalone tool that gets installed with Inventor named "Design Assistant", which has some functionality for 'Where Used', and that will actually search throughout your entire project space, of file system, if you want it to, but if that area contains tons of files (like mind), then may take a really long time to do.
I do not know of any other property on the model file side that will point to any drawing that may have a reference to it. If that were the case, then every time you create a drawing, and add that part, or an assembly containing that part into it as a view, it would have to 'modify' that model file, to add something into it about the reference to it that was just made. Managing those associations in both directions, to support functionality like 'Where Used' is large part of what Vault does for us. I do not yet have Vault, but I believe we will be getting it soon.
Wesley Crihfield
(Not an Autodesk Employee)
Hi,
You can achive this two ways, and second in my opinion is better because it will be faster and it will work even if idw filename is different than model.
1. Use folder.GetFiles for example to find drawing for each file
Dim Folder As New IO.DirectoryInfo(oPath) 'pfolder)
Dim i As Integer = 0
For Each File As IO.FileInfo In Folder.GetFiles(name & ".idw", IO.SearchOption.AllDirectories)
Next
2. make simple code to create/update custom property in your model to store drawing location and run it on idw save then just use it to open file use idw.ReferencedDocuments(1) to find idw referencing model.
Hi,
But name and location of the idw file may be different than ipt file.
In this case your code will not get result ı affaraid.
But your second chice looks good. But in this case we need to update all files.
Regards,
Mucip:)
you can write code to iterate trough all idw files and update iproperties.
Hi,
Long way but it's solution.
By the way how can Inventor knows this? I can right click with the mouse on model tree than it can open the idw file. This mean that This idw path written in somewhere? Am I wrong?
Regards,
Mucip:)
Nope, it opens idw if it is in the same location and with the same name as model.
For the solution you can adapt this rule to update properties in model referencing to idw, just change property name in line 55
. :
Imports System.Windows.Forms
Class ThisRule
Public FSO As Object
Sub Main()
Dim FolderBrowserDialog1 = New FolderBrowserDialog()
Dim folderpath
Dim objFolder As Object
Dim strStartPath As String
Dim oPath As String = ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath
' FolderBrowserDialog1.RootFolder = oPath
FolderBrowserDialog1.SelectedPath = oPath
If FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then
folderpath = FolderBrowserDialog1.SelectedPath
FSO = CreateObject("Scripting.FileSystemObject")
Dim fld = FSO.GetFolder(folderpath)
If Not fld Is Nothing Then
ThisApplication.UserInterfaceManager.UserInteractionDisabled = True
ThisApplication.SilentOperation = True
On Error Resume Next
Dim Folder As New IO.DirectoryInfo(folderpath) 'pfolder)
Dim i As Integer = 0
'Chr(34) & name & "*" & Chr(34)
Dim resp As MsgBoxResult = vbYes
ifi = UBound(Folder.GetFiles("*.idw", IO.SearchOption.AllDirectories))
If ifi > 500 Then
resp = MsgBox("Found " & ifi & " IDW files in given directrory, Do you want to continue?", vbYesNo)
End If
If resp = vbYes Then
ifi = 0
Call ListFolders(folderpath)
End If
ThisApplication.UserInterfaceManager.UserInteractionDisabled = False
ThisApplication.SilentOperation = False
End If
End If
End Sub
Sub ListFolders(folder As String)
On Error Resume Next
Dim doc As Document
Dim FSO_Folder As Object
Dim oFolder As Object
Dim fld As Object
If FSO.FolderExists(folder) Then
fld = FSO.GetFolder(folder)
End If
For Each file In fld.Files
If Microsoft.VisualBasic.Right(File.name, 4) = ".idw" Then
Dim drawdoc As DrawingDocument = ThisApplication.Documents.Open(fld.path & "\" & File.name, False)
ThisApplication.StatusBarText = "updating iproperty for " & drawdoc.FullFileName
Dim oref As Document = drawdoc.ReferencedDocuments.Item(1)
UpdateCustomiProperty(oref, "Property name", drawdoc.FullFileName)
oref.Save()
drawdoc.Close(True)
End If
Next
For Each subfolder In fld.SubFolders
If Microsoft.VisualBasic.Right(subfolder.path, 11) <> "OldVersions" And Microsoft.VisualBasic.Right(subfolder.path, 2) <> "_V" Then
ListFolders(subfolder.path)
End If
Next
End Sub
Private Sub UpdateCustomiProperty(ByRef Doc As Inventor.Document, ByRef PropertyName As String, ByRef PropertyValue As Object)
On Error Resume Next
Dim customPropSet As Inventor.PropertySet = Doc.PropertySets.Item("Inventor User Defined Properties")
' Get the existing property, if it exists.
Dim prop As Inventor.Property = Nothing
Dim propExists As Boolean
propExists = False
For Each prop In customPropSet
If prop.Name.ToLower = PropertyName.ToLower Then
propExists = True
Exit For
End If
Next
' Check to see if the property was successfully obtained.
If Not propExists Then
' Failed to get the existing property so create a new one.
prop = customPropSet.Add((PropertyValue), PropertyName)
Doc.Save()
Else
If prop.Value <> PropertyValue Then
prop.Expression = (PropertyValue)
Doc.Save()
End If
End If
End Sub
End Class
Hi @mucip. I am certainly not a robot and not controlled by artificial intelligence. In fact, I find the idea of artificial intelligence a bit creepy, so I have chosen to not (knowingly) interact with any form of it thus far. If that were the case, I would be on here 24 hours a day, 7 days a week, and I would not have so many typo's in my responses from typing too quickly. I am only active on this forum during the hours that I am at work. And while I am at work, I also have many other work related tasks to get done, and many other things on my mind, because I am always multi-tasking on multiple projects. I choose to monitor this forum and help others when I can, because automating Inventor has been one of my main interests for years now, and I have gotten to be quite good at it, primarily through my own research, trial & error experience over the years, and being present on this forum for years helping others with their complex challenges. If I choose to take the time out of my work day to type up a large, informational article about a topic being asked about, complete with links to relevant online help documentation, and visual aids, that does not make me a robot, it makes me someone who cares enough about helping others to make that sacrifice on the behalf of others whom I have never met before. Unfortunately that time and effort does not get recognized or appreciated by some that I attempt to help.
Some questions can not be answered to the satisfaction of the asker within one or two lines of typed text. Some questions either do not contain enough information to go by, or are far to broad for a precise/specific/short answer to satisfy.
You wanted to know how to find the drawing files which reference the models in your assembly, and mentioned that they are not always located in the same folder as the model file that they reference, and mentioned opening drawings directly from model files. I knew that so far, there does not appear to be any property on the model file's side which records the drawing file's location, its name, or even its existence. If there is such a property, then it would seem that only the folks at Autodesk who wrote the source code for Inventor may now about it, and have chosen to not reveal that detail to us yet. So, I stated what I know about the situation of trying to find drawing files from model files. And now that I have read in some of your later responses that even the name of the drawing file may be different than the model file, that makes this task even more complicated. The code to find the drawing files you are looking for may need to include information that only you know about, such as information about where you may have saved those drawing files in relation to the model files, and how you may have named those drawing files differently than the model files. And if those associations can not be easily accounted for or tested for by logic based code, then every drawing type file in your entire project space may need to be iterated through, invisibly opened, and its referenced documents scanned to check if they include any of the model files referenced by your assembly. This could be an incredibly time consuming process, and could even freeze-up Inventor, if there are lots of files in that space for the code to process. I know this because I have encountered situations like this myself in the past and have attempted to run code on our file storage area and had to 'end task' them or had Inventor crash on us, and have encountered several other inquiries similar to this in on this forum before.
Wesley Crihfield
(Not an Autodesk Employee)
Inventor just search for the drawings inside Workspace defined in Project.
Nothing fancy. No AI required.
How to buy
Privacy | Do not sell or share my personal information | Cookie preferences | Report noncompliance | Terms of use | Legal | © 2025 Autodesk Inc. All rights reserved
Type a product name