"Where used" info on drawings

"Where used" info on drawings

alexander.duell
Contributor Contributor
1,924 Views
29 Replies
Message 1 of 30

"Where used" info on drawings

alexander.duell
Contributor
Contributor

Hello,

 

I wonder if someone have tried or have an ilogic code to export the infromation of "Where used" on part drawings?

 

What I am looking for is a text on a drawing for part drawings, preferably subassemblies also. To scan the same folder of the part/ subassembly to find in which assemblies the part/subassembly is used.

 

Ex. on drawing for part 1 there is a text on the drawing that says. "Used in assembly: XXX, YYY . For example that is, i guess you get the point.

 

I mean, you can fnd the info in both Vault and Design assisant, there should be a way to get this information on the drawings aswell.

 

Any ideas?

 

Best Regards

Alexander

1,925 Views
29 Replies
Replies (29)
Message 2 of 30

Michael.Navara
Advisor
Advisor

This information is not stored anywhere in files. Only one way is to open file by file in folder and look into for information which files are referenced and compare this with your original one.

And one question for you. What do you expect when you:

  1. Create drawing
  2. Place information of usage of Part1.ipt
  3. Close drawing
  4. Create new assembly
  5. Insert Part1.ipt into
  6. Save and Close
  7. Open original drawing again?

 

0 Likes
Message 3 of 30

alexander.duell
Contributor
Contributor

Hello,

 

The main reason for this is that we used linked drawings using PDF readers that scan for drawings numbers. So for assembly drawings with the BOM we are able to click on the drawing number and the part PDF will open. And I would like for us to be able to use it also the other way around.

 

If you open a  partdrawing (PDF) you will get information on what assembly this part belongs to, and click on the drawing number and the assembly will open.  The links between the files are solved, so information on the part drawings with dwg number of assemblies is the thing I am missing. 

 

To answer you question: Perferably i would like the information of the usage of Part1 will be updated. (in the best of worlds)

 

I hope i make myself understandable.

 

But i mean, the info is there both in the Design Manager and the Vault. 

Isnt there a way to extract this information and use  it to put on drawings? 


Or like scan the assemblies in the same  folder as the part for occurenceses and get the paramaeter "Part number" or something like that using Ilogic?

 

I tried to do a simple sketch of 2 Assembles both containing the same part.

 

alexanderduell_0-1637732815303.png

 

Best Regards
Alexander

 

0 Likes
Message 4 of 30

WCrihfield
Mentor
Mentor

Hi @alexander.duell.  I don't currently know how to extract that information from Design Assistant or Vault by code (I am not currently using Vault either), but I could definitely envision an iLogic rule that could scan a directory for assemblies, then check if each assembly has a reference to a specific part, then return those assembly part numbers.  Of course this type of thing may not be ideal, and may take a while to process (bogging down Inventor while it runs), depending on how many files it will be scanning through, but sounds doable.  I have created solutions before using an iLogic rule that would process all files of a certain type (and other possible filters) within a directory to work with things like iProperties, etc.  Does that sound like something you would want to try then?  Should we assume that the drawing document for the part will be open and the 'active' document when the rule starts?  The bulk of the code for this task could be put into a Function of its own too, so it could then be referenced or called by another larger code, if needed.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 30

alexander.duell
Contributor
Contributor

Hello,

 

Thank you for getting back to me.

 

It denfinitly sounds like something i would like to try.

 

We can definitly say that it should make the "scan" for the current/active drawing,

 

I guess it is possible to make the scan work for assemblies also then? For instance if you have an subassembly drawing opened, the code uses the part number for that subassembly to scan for it in other assemblies?

 

Or perhaps that is something completly different.  I see the most usage for it for the part drawings, but also benifits for it when for subassemblies.

 

Best Regards

Alexander

0 Likes
Message 6 of 30

WCrihfield
Mentor
Mentor

OK.  I just created this iLogic rule for you to try.  I tested this myself first, on a folder with about 115 items in it (some folders, and some other types of files), and I have it set to only search within the same folder where the drawing's model document is saved.  My test returned 4 part numbers of assemblies that were referencing the model in the active drawing, then it put a drawing note at the origin point of the active drawing sheet, as expected.  Give this a try, and see how it works for you.  If other changes may need to be made, we may be able to deal with that later.

Sub Main
	If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
		MsgBox("A Drawing Document must be active for this rule to work. Exiting.", vbCritical, "iLogic")
		Exit Sub
	End If
	Dim oDDoc As DrawingDocument = ThisApplication.ActiveDocument
	Dim oMDoc As Document = GetDrawingModel(oDDoc)
	If IsNothing(oMDoc) Then
		MsgBox("No 'Model' document found in Drawing. Exiting rule.", vbCritical, "iLogic")
		Exit Sub
	End If
	Dim oPNsRefdBy As List(Of String) = GetWhereUsed(oMDoc)
	If oPNsRefdBy.Count = 0 Then
		MsgBox("No assemblies found with reference to the 'Model' document.", vbInformation, "iLogic")
		Exit Sub
	End If
	Dim oReport As String = "USED IN:  "
	For Each oPNRefdBy In oPNsRefdBy
		oReport = oReport & vbCrLf & oPNRefdBy
	Next
	oPos = ThisApplication.TransientGeometry.CreatePoint2d(0,0)
	Dim oNote As GeneralNote = oDDoc.ActiveSheet.DrawingNotes.GeneralNotes.AddFitted(oPos, oReport)
End Sub

Function GetDrawingModel(oDrawing As DrawingDocument) As Document
	If oDrawing.AllReferencedDocuments.Count = 0 Then Return Nothing
	For Each oRefDoc As Document In oDrawing.AllReferencedDocuments
		If oRefDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Or _
			oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
			Return oRefDoc
			Exit For
		End If
	Next
	'just in case there were referenced documents,
	'but none were a Part or Assembly (very rare)
	Return Nothing
End Function

Function GetWhereUsed(oDoc As Document) As List(Of String)
	Dim oPNs As New List(Of String)
	'get the folder where the input document is currently saved
	oPath = System.IO.Path.GetDirectoryName(oDoc.FullFileName)
	'search within that folder for assemblies that reference the input document
	
	Dim oFileNames() As String = System.IO.Directory.GetFiles(oPath, "*.iam", System.IO.SearchOption.TopDirectoryOnly)
	'if no assemblies were found, were done here
	If oFileNames.Length = 0 Then
		'MsgBox("No assemblies found.",,"")
		Return oFileNames.ToList  'returns an empty List
	End If
	For Each oFileName In oFileNames
		oOptions = ThisApplication.TransientObjects.CreateNameValueMap
		oOptions.Add("ExpressModeBehavior", "OpenExpress")
		oOptions.Add("SkipAllUnresolvedFiles", True)
		Dim oADoc As AssemblyDocument = ThisApplication.Documents.OpenWithOptions(oFileName, oOptions, False)
		If oADoc.AllReferencedDocuments.Count > 0 Then
			For Each oRefDoc As Document In oADoc.AllReferencedDocuments
				If oRefDoc.FullFileName = oDoc.FullFileName Then
					Dim oPN As String = String.Empty 'just a cautionary reset
					oPN = oADoc.PropertySets.Item(3).Item("Part Number").Value
					If String.IsNullOrEmpty(oPN) Then oPN = ""
					oPNs.Add(oPN)
					Exit For 'exit the loop of oRefDoc's
				End If
			Next
		End If
		oADoc.ReleaseReference
	Next
	ThisApplication.Documents.CloseAll(True) 'close all 'unreferenced' documents only
	Return oPNs
End Function

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡 or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 7 of 30

alexander.duell
Contributor
Contributor
Thank you.

I dont know if i am doing something wrong. But i tried for an old project to paste the ilogic code in one of the old drawings. But i recive this error code.

Error in rule: Test, in document: 207758-03-1002.dwg
The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

And more info:

System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.Documents.OpenWithOptions(String FullDocumentName, NameValueMap Options, Boolean OpenVisible)
at ThisRule.GetWhereUsed(Document oDoc)
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule

Any idea what that cna be, i am using Inventor 2020 at this moment.

I guess im doing something completly wrong here.

Best Regards
Alexander
0 Likes
Message 8 of 30

WCrihfield
Mentor
Mentor

OK. I can tell from the second part of the error message that it is not liking the Documents.OpenWithOptions code I'm using to open the assembly documents within the 'GetWhereUsed' function.  That method has been around since 'version 11', according to its online help page, but I do know for a fact that the listed available 'Options' shown on that page have changed over the years.  You can review that online help page for yourself if you want.  The one option I'm using (ExpressModeBehavior) is specifically for when attempting to open an Assembly only.  The other option I'm using (SkipAllUnresolvedFiles) says it can be used for when opening any document type.  So I'm not sure why they would be causing any problems.  The oFileName variable I'm using as the first input variable should contain the 'FullFileName' of the assembly file (as found in the file system).  You could try replacing those 4 lines of code with a simple Documents.Open() method instead, and see if that works better for you.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 9 of 30

pball
Mentor
Mentor

You mentioned Vault so here is an iLogic script I manged to get working with some help from old forum posts and some trial and error.

 

The big part that caught me was the ID used to get parents and children is different. If you have any questions on the code just ask and I'll explain best I can.

 

Imports ACW = Autodesk.Connectivity.WebServices
Imports VDF = Autodesk.DataManagement.Client.Framework 
Imports VB = Connectivity.Application.VaultBase
AddReference "Autodesk.Connectivity.WebServices.dll"
AddReference "Autodesk.DataManagement.Client.Framework.Vault.dll"
AddReference "Connectivity.Application.VaultBase.dll"
Class LocalWorkspaceCheck
Shared WorkingDir As String = "C:\_Vault\"

Sub Main
	Dim mVltCon As VDF.Vault.Currency.Connections.Connection = VB.ConnectionManager.Instance.Connection
	If mVltCon Is Nothing Then Exit Sub
	
	Dim Filename As String = ThisApplication.ActiveEditDocument.fullfilename

	Dim Item As ACW.File() = Search_Vault_by_FilePath(Filename, WorkingDir)

		Dim myFileRelationshipSettings As VDF.Vault.Settings.FileRelationshipGatheringSettings = New VDF.Vault.Settings.FileRelationshipGatheringSettings
		myFileRelationshipSettings.IncludeParents = True

		Dim relatedfileassoc = mVltCon.FileManager.GetFileAssociationLites(New Long() {Item(0).Id}, myFileRelationshipSettings)

		Dim whereused As New List(Of String)
		Dim fileassoc As acw.FileAssocLite
		For Each fileassoc In relatedfileassoc
			Dim relatedfile As ACW.File = mVltCon.WebServiceManager.DocumentService.GetFileById(fileassoc.ParFileId)
			whereused.Add(relatedfile.Name)
		Next

		MsgBox(Filename & vbNewLine & "Parents " & vbNewLine & vbNewLine & Strings.Join(whereused.ToArray, vbNewLine))

		Dim myFileRelationshipSettings2 As VDF.Vault.Settings.FileRelationshipGatheringSettings = New VDF.Vault.Settings.FileRelationshipGatheringSettings
		myFileRelationshipSettings2.IncludeChildren = True
		myFileRelationshipSettings2.IncludeLibraryContents = True

		Dim relatedfileassoc2 = mVltCon.FileManager.GetFileAssociationLites(New Long() {Item(0).Id}, myFileRelationshipSettings2)

		Dim children As New List(Of String)

		For Each fileassoc In relatedfileassoc2
			Dim relatedfile As ACW.File = mVltCon.WebServiceManager.DocumentService.GetFileById(fileassoc.CldFileId)
			children.Add(relatedfile.Name)
		Next

		MsgBox(Filename & vbNewLine & "Children " & vbNewLine & vbNewLine & Strings.Join(children.ToArray, vbNewLine))
End Sub

    Function Search_Vault_by_FilePath(filePath As String, LocalWorkspace As String) As ACW.File()
        Dim mVltCon As VDF.Vault.Currency.Connections.Connection = VB.ConnectionManager.Instance.Connection
        If mVltCon Is Nothing Then Return Nothing

        Dim VaultPath As String = filePath.Replace(LocalWorkspace, "$/").Replace("\", "/")

        Dim Results As ACW.File() = mVltCon.WebServiceManager.DocumentService.FindLatestFilesByPaths(New String() {VaultPath})

        If (Results(0).Id = -1) Then Return Nothing

        Return Results
    End Function
End Class

 

In my VB.net addin I use the following line to get the currently working directory, but iLogic doesn't seem to like it so I have it hard coded in the code above.

 

Dim WorkingDir As String = mVltCon.WorkingFoldersManager.GetWorkingFolder("$").ToString
Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
0 Likes
Message 10 of 30

alexander.duell
Contributor
Contributor
Hello,

I cant really understand your anwer regarding how to change the code, and what not. Do you mind helping me out?

Best Regards
Alexander
0 Likes
Message 11 of 30

alexander.duell
Contributor
Contributor
Hello,

Thank you for getting back to me. Im so grateful.

This works and does almost what i was looking for 🙂

Instead of getting the filename, it would like it show the "Part number", Im having a bit of trouble to find the line where this is managed.

Also, It returns the drwaing number of its own drawing, as a parent. Do you think there is way to work around that this isnt the case? It is probably because the drawing is seen as a parent to the assembly.

Best Regards
Alexander

Best Regards
0 Likes
Message 12 of 30

alexander.duell
Contributor
Contributor

@pball 

Hello @pball 

 

What do you think about the posibility so get Part number instead of file name?

 

See my previous post

 

Best Regards

Alexander

0 Likes
Message 13 of 30

pball
Mentor
Mentor

@alexander.duellI'm not familiar with the Vault API yet as I just started using it. So I do not know a quick method for getting the part number and I do not have the time to look into it now. I'll see about looking into it later or maybe someone else could chime in.

Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
0 Likes
Message 14 of 30

maxim.teleguz
Advocate
Advocate

I am getting an error running this code, can you guide us on how you use it?

 

Object reference not set to an instance of an object.


System.NullReferenceException: Object reference not set to an instance of an object.
at LocalWorkspaceCheck.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

 

0 Likes
Message 15 of 30

pball
Mentor
Mentor

Unfortunately that error message is too generic to help much.

 

This script should be ran when a part/assembly is open that is in Vault. Make sure you change the line below to have your Vault working directory. This code was provided as an example and only gives two message boxes with parents and children listed, to make it do more will require changes.

 

Shared WorkingDir As String = "C:\_Vault\"

 

Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
Message 16 of 30

maxim.teleguz
Advocate
Advocate

you mentioned vb net addin, can this be run directly from an external rule? 

0 Likes
Message 17 of 30

maxim.teleguz
Advocate
Advocate

I was able to pull up the information using this:

Call ThisApplication.CommandManager.ControlDefinitions.Item("VaultShowDetailsTop").Execute
0 Likes
Message 18 of 30

alexander.duell
Contributor
Contributor

Hello,

 

@WCrihfield , Do you mind helping me out to figure out how change the code to avoid the error message?

 

Best Regards

Alexander 

0 Likes
Message 19 of 30

alexander.duell
Contributor
Contributor

@JelteDeJong 

 

Hello Mr.

 

I took a look at your homepage( and your contacts and i thoght I would try to get you involved in my question regarding getting info onto drawings about "where used" /parents of part/subassemblies.

 

What do you think? Take a look at my questions and the rest of the comments .

 

Best Regards

Alexander

 

 

0 Likes
Message 20 of 30

WCrihfield
Mentor
Mentor

Hi @alexander.duell.  I'm not sure if this will fix the error you were having with my first code, but I modified the code to use a regular Documents.Open() line to open the assembly files, instead of the Documents.OpenWithOptions() line, because that is what the error seemed to be pointing to at the time.  This code still works for me, but see if this works any better for you.

Sub Main
	If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
		MsgBox("A Drawing Document must be active for this rule to work. Exiting.", vbCritical, "iLogic")
		Exit Sub
	End If
	Dim oDDoc As DrawingDocument = ThisApplication.ActiveDocument
	Dim oMDoc As Document = GetDrawingModel(oDDoc)
	If IsNothing(oMDoc) Then
		MsgBox("No 'Model' document found in Drawing. Exiting rule.", vbCritical, "iLogic")
		Exit Sub
	End If
	Dim oPNsRefdBy As List(Of String) = GetWhereUsed(oMDoc)
	If oPNsRefdBy.Count = 0 Then
		MsgBox("No assemblies found with reference to the 'Model' document.", vbInformation, "iLogic")
		Exit Sub
	End If
	Dim oReport As String = "USED IN:  "
	For Each oPNRefdBy In oPNsRefdBy
		oReport = oReport & vbCrLf & oPNRefdBy
	Next
	oPos = ThisApplication.TransientGeometry.CreatePoint2d(0,0)
	Dim oNote As GeneralNote = oDDoc.ActiveSheet.DrawingNotes.GeneralNotes.AddFitted(oPos, oReport)
End Sub

Function GetDrawingModel(oDrawing As DrawingDocument) As Document
	If oDrawing.AllReferencedDocuments.Count = 0 Then Return Nothing
	For Each oRefDoc As Document In oDrawing.AllReferencedDocuments
		If oRefDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Or _
			oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
			Return oRefDoc
			Exit For
		End If
	Next
	'just in case there were referenced documents,
	'but none were a Part or Assembly (very rare)
	Return Nothing
End Function

Function GetWhereUsed(oDoc As Document) As List(Of String)
	Dim oPNs As New List(Of String)
	'get the folder where the input document is currently saved
	oPath = System.IO.Path.GetDirectoryName(oDoc.FullFileName)
	'search within that folder for assemblies that reference the input document
	
	Dim oFileNames() As String = System.IO.Directory.GetFiles(oPath, "*.iam", System.IO.SearchOption.TopDirectoryOnly)
	'if no assemblies were found, were done here
	If oFileNames.Length = 0 Then
		'MsgBox("No assemblies found.",,"")
		Return oFileNames.ToList  'returns an empty List
	End If
	For Each oFileName In oFileNames
		Dim oADoc As AssemblyDocument = ThisApplication.Documents.Open(oFileName, False)
		If oADoc.AllReferencedDocuments.Count > 0 Then
			For Each oRefDoc As Document In oADoc.AllReferencedDocuments
				If oRefDoc.FullFileName = oDoc.FullFileName Then
					Dim oPN As String = String.Empty 'just a cautionary reset
					oPN = oADoc.PropertySets.Item(3).Item("Part Number").Value
					If String.IsNullOrEmpty(oPN) Then oPN = ""
					oPNs.Add(oPN)
					Exit For 'exit the loop of oRefDoc's
				End If
			Next
		End If
		oADoc.ReleaseReference
	Next
	ThisApplication.Documents.CloseAll(True) 'close all 'unreferenced' documents only
	Return oPNs
End Function

I also sympathize with @pball here, because I may be in that same position soon.  Because we too may be starting to use Vault in the near future, and I'm very apprehensive about it.  I don't know hardly anything about coding for Vault right now, and I'm worried about the many hundreds (if not thousands) of iLogic rules (and VBA macros, and fully automated configuration templates) I already have, and if they may become practically useless after the change.  And the 'where used' functionality was the first/main attraction for us, because many of our parts are used in many places, and those other places may often need to be updated (of fixed) after certain changes to parts.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes