"Where used" info on drawings

"Where used" info on drawings

alexander.duell
Contributor Contributor
1,976 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,977 Views
29 Replies
Replies (29)
Message 21 of 30

maxim.teleguz
Advocate
Advocate

Question: Why would you only allow it to lookup assembly files? wouldnt it be beneficial to look up everything the document is referencing?

This way you can get rid of all the complexity code and just focus on a sniper shot of where-used. 

 

We need to determine the assembly it is used in, that is the whole point of this right?

I tried your code and i still cant get an example to work, this code doesnt give me any errors just a popup "cant find model reference".

0 Likes
Message 22 of 30

WCrihfield
Mentor
Mentor

I focus on Assembly documents only because they are the main source of referencing other documents as their components.  Drawings also reference other documents, but we are starting from the main drawing that references this part, and I don't expect that there would be any other drawings in the same directory that reference this part directly.  If you expect there to be, that can be changed.  The only way another Part document in the same directory would be referencing this part is if it were derived into it, which in my opinion would be rare.  But that too can be changed, if you expect that scenario.  I was mostly trying to avoid processing tons of extra files that did not need to be processed, because this type of routine can be pretty taxing on system resources, or possibly even freeze up your computer, if not handled properly.

 

Also, the code I posted only searches within the one directory (same directory as drawing's model), and does not step down into sub-directories.  That can easily be changed though, by changing the option at the end of the 'GetFiles() method, within the 'GetWhereUsed' function, from 'TopDirectoryOnly' to 'AllDirectories'.  Again my choice there was to limit the process, so it would not overwhelm my system while performing the tests.

 

My code also assumes there is just one 'model' being represented by the 'active' drawing.  That's how we always do our drawings, but I realize that's not how everyone does it.  I have other Functions or getting drawing model(s), depending on the need/situation.  Other variations assume multiple models, and may return an ObjectCollection (or similar) of all the 'model' documents found (or filtered to one type of 'model').

 

Of course it can all be modified in any ways needed to suit your individual needs.  I was just offering one idea and possible process that seemed logical to me, in my situation, and that works just fine for me.  In my example tests, I have a drawing of a part in a folder where I have lots of files for testing.  That part was also used within 4 other assemblies in that folder.  When I run this rule, the mouse pointer swirls for a few seconds, then it inserts a text note at the lower left corner of my drawing sheet that starts with "USED IN:" on the first line, then lists the 4 part numbers in the following lines below that, for the other 4 assemblies that are referencing that part, within that directory.  Since it seemed to work OK for me, I thought it would at least be a good starting point for others to start from there and modify the code as need to suit their individual needs.  If you or anyone else needs to modify any part of the functionality of that code, but are not sure how to modify it, you can always request different functionality, and if I have time, I will attempt to modify it that way for you, if it is possible, and if I know how.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 23 of 30

maxim.teleguz
Advocate
Advocate

can you share your idw or dwg template so i can see how the ilogic code puts that data there?

I am really fascinated by this and want to simplify this to make it work for us too. 

0 Likes
Message 24 of 30

pball
Mentor
Mentor

@alexander.duellI played around with some code I found for getting properties from Vault. The code below takes a file name and returns the part number property. I just cut this code down from a larger example linked below with some tweaks, such as using my vault search function.

https://adndevblog.typepad.com/manufacturing/2013/11/vault-2014-api-example-getting-property-values-...

 

Imports VDF = Autodesk.DataManagement.Client.Framework 
Imports VB = Connectivity.Application.VaultBase
Imports ACW = Autodesk.Connectivity.WebServices
AddReference "Autodesk.DataManagement.Client.Framework.Vault.dll"
AddReference "Connectivity.Application.VaultBase.dll"
AddReference "Autodesk.Connectivity.WebServices.dll"
Imports Autodesk.DataManagement.Client.Framework.Vault.Currency.Properties
Class VaultFileProperties
Sub Main
	Dim m_conn As VDF.Vault.Currency.Connections.Connection = VB.ConnectionManager.Instance.Connection
	Dim props As PropertyDefinitionDictionary = m_conn.PropertyManager.GetPropertyDefinitions(VDF.Vault.Currency.Entities.EntityClassIds.Files, Nothing, PropertyDefinitionFilter.IncludeAll)
	Dim MyProperty As PropertyDefinition = Nothing
	Dim propDef As PropertyDefinition

	For Each myKeyValPair As KeyValuePair(Of String, PropertyDefinition) In props
		propDef = myKeyValPair.Value()

		If propDef.DisplayName = "Part Number" Then
			MyProperty = propDef
			Exit For
		End If
	Next

	Dim fileIter As VDF.Vault.Currency.Entities.FileIteration = Nothing

	fileIter = New VDF.Vault.Currency.Entities.FileIteration(m_conn, Search_Vault_by_FileName(IO.Path.GetFileName(ThisApplication.ActiveEditDocument.FullDocumentName))(0))

	If Not MyProperty Is Nothing Then
		Dim strPropertyVal As String = m_conn.PropertyManager.GetPropertyValue(fileIter, MyProperty, Nothing)
		MsgBox("Value of custom prop " & MyProperty.DisplayName.ToString() & " = " & strPropertyVal)
	End If
End Sub

    Public Function Search_Vault_by_FileName(Fname As String) As ACW.File()
        'Access the Vault-Connection and exit if necessary 
        Dim mVltCon As VDF.Vault.Currency.Connections.Connection = VB.ConnectionManager.Instance.Connection
        If mVltCon Is Nothing Then Return Nothing

        Dim FilePropsDef As ACW.PropDef() = mVltCon.WebServiceManager.PropertyService.GetPropertyDefinitionsByEntityClassId("FILE")

        Dim ACWNamePropDef As ACW.PropDef = FilePropsDef.[Single](Function(n) n.SysName = "Name")

        'Set search options, opereator 3 is exact
        Dim NameSearch As New ACW.SrchCond() With { _
            .PropDefId = ACWNamePropDef.Id, _
            .PropTyp = ACW.PropertySearchType.SingleProperty, _
            .SrchOper = 3, _
            .SrchRule = ACW.SearchRuleType.Must, _
            .SrchTxt = Fname _
        }

        Dim bookmark As String = String.Empty
        Dim status As ACW.SrchStatus = Nothing
        Dim results As ACW.File() = mVltCon.WebServiceManager.DocumentService.FindFilesBySearchConditions(New ACW.SrchCond() {NameSearch}, Nothing, Nothing, False, True, bookmark, status)

        Return results
    End Function
End Class
Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
Message 25 of 30

WCrihfield
Mentor
Mentor

I am not starting this rule from a 'template' drawing file, I'm starting it from an IDW type drawing document that already has views & dimensions, and has been saved with its new file name (which matches the model's file name, except for file extension).  There is nothing special about the template that the drawing was based on, other than it is A-size, landscape oriented, has our company's border & title block, and has a few of its settings set the way we like them.

 

There are certainly several lines of comments (and you may prefer more or less of them), and lines that are simply checking for potential error prone situations, that may not always be necessary, which make the code seem longer or more complicated than it really is.  I was trying to make the code be fairly robust (plenty of checks to avoid errors), but I'm apparently not accounting for every possible potential issue that anyone may have.  Breaking portions of the code out into sub routines can sometimes make it appear a bit more complicated too, when you're not familiar with how that all works.  Sub routines are usually most advantageous when that block of code needs to be ran multiple times, so you don't have to have that same code appear in a longer code multiple times, but in this case they are only being called to run once, so their code could technically be merged back into the main routine (with a few modifications).  Sometimes it's just nice to separate a routine or task out into that separate area to keep the main code cleaner looking and easier to follow.

 

To recreate a test scenario similar to mine, I would probably:

  1. Create a new folder
  2. Create several new simple part files, just for testing, and save them into that folder.
    1. Make sure to put something into its Part Number iProperty field, before saving/closing it.
  3. Create a few new simple assembly files, using those new simple parts, just for testing, and save them into that folder.
    1. Make sure to put something into its Part Number iProperty field, before saving/closing it.
    2. Make sure the one part is present as a component in each of these assemblies.
  4. Create a new simple drawing file for one of the parts in that folder, and save that drawing into that same folder.
    1. It can just contain a single model view, with no dimensions or annotations.
  5. With that drawing document open and active, either copy the rule code into a new local rule within that drawing document, or have it ready within an external rule, then run the rule.
    1. It should find the part document being represented within the drawing, get what folder it is saved within, open (invisibly) each assembly found in that folder, check its references for that part, if found, get the assembly's Part Number, so we can record it for the report, then close the assembly.  When finished processing all assemblies in that folder, it should then assemble the report, then create the note to place at the corner of the sheet that contains the text of the report.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 26 of 30

maxim.teleguz
Advocate
Advocate

If i never downloaded the assembly from Vault, will this find the assembly in Vault and let me know the where used on it? 

 

For instance if i just opened the part and did a where-used on it. 

0 Likes
Message 27 of 30

WCrihfield
Mentor
Mentor

Hi @maxim.teleguz.  I honestly do not know.  Like I said, I currently do not have Vault installed and am not currently using Vault, and I have not used Vault in the past, so I'm not sure how having Vault installed or using Vault might change things.  I have no way of knowing or testing how the code I posted would work in that situation.  If you currently have Vault, and are using it, I would suggest that you pursue making use of that resource as best you can, because it will most likely be a much more efficient solution for you.  If the code that @pball posted is not working for you, I would not be able to help develop that further right now, because I am not familiar with most of the code he is using yet, and I can not test in on my computer.  I'm sure there are others here on this forum who do have Vault, and can help further develop a working solution for those who also have Vault.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 28 of 30

maxim.teleguz
Advocate
Advocate

I was able to accomplish a couple of things with getting Where Used from Vault, here is my thread i started: I have successfully pulled information from Where - Used need help perfecting this code - Autodesk C...

 

But then I was able to find functions that are built into Inventor that could be beneficial to us. I just don't have any examples and it seems like I am the first one on the internet to ask about it. I cannot find any examples anywhere, I have no idea how to use them. Could you help me with the below?

Function FindWhereUsed(FullFileName As String) As ApprenticeServerDocuments
    Member of Inventor.ApprenticeServerDocument
    Obtains the set of documents that reference the given file within this document

Sub GetLocationFoundIn(LocationName As String, Type As LocationTypeEnum)
    Member of Inventor.ApprenticeServerDocument
    Obtains the name of the Location this file was found in

-

Function FindWhereUsed(FullFileName As String) As ApprenticeServerDocuments
    Member of Inventor.ApprenticeServerDrawingDocument
    Obtains the set of documents that reference the given file within this document

Sub GetLocationFoundIn(LocationName As String, Type As LocationTypeEnum)
    Member of Inventor.ApprenticeServerDrawingDocument
    Obtains the name of the Location this file was found in

-

Function FindWhereUsed(FullFileName As String) As DocumentsEnumerator
    Member of Inventor.AssemblyDocument
    Obtains the set of documents that reference the given file within this document

Sub GetLocationFoundIn(LocationName As String, LocationType As LocationTypeEnum)
    Member of Inventor.AssemblyDocument
    Obtains the name of the Location this file was found in

-

Function FindWhereUsed(FullFileName As String) As DocumentsEnumerator
    Member of Inventor.Document
    Obtains the set of documents that reference the given file within this document

Sub GetLocationFoundIn(LocationName As String, LocationType As LocationTypeEnum)
    Member of Inventor.Document
    Obtains the name of the Location this file was found in

-

Function FindWhereUsed(FullFileName As String) As DocumentsEnumerator
    Member of Inventor.DrawingDocument
    Obtains the set of documents that reference the given file within this document

Sub GetLocationFoundIn(LocationName As String, LocationType As LocationTypeEnum)
    Member of Inventor.DrawingDocument
    Obtains the name of the Location this file was found in

-

Function FindWhereUsed(FullFileName As String) As DocumentsEnumerator
    Member of Inventor.PartDocument
    Obtains the set of documents that reference the given file within this document

Sub GetLocationFoundIn(LocationName As String, LocationType As LocationTypeEnum)
    Member of Inventor.PartDocument
    Obtains the name of the Location this file was found in

-

Function FindWhereUsed(FullFileName As String) As DocumentsEnumerator
    Member of Inventor.PresentationDocument
    Obtains the set of documents that reference the given file within this document

Sub GetLocationFoundIn(LocationName As String, LocationType As LocationTypeEnum)
    Member of Inventor.PresentationDocument
    Obtains the name of the Location this file was found in

 

0 Likes
Message 29 of 30

WCrihfield
Mentor
Mentor

Hi @maxim.teleguz.  I have actually used that before, but it has very limited functionality for me, since I don't have Vault.  For me, it will only return some other documents, if those other documents are also open at that time (or at least loaded into memory).  Hopefully it will work better for you, since you do have Vault.  Here is some code you can use to try it out.

Dim oActiveDoc As Document = ThisApplication.ActiveDocument
oFullFileName = oActiveDoc.FullFileName
Dim oFoundDocuments As DocumentsEnumerator = oActiveDoc.FindWhereUsed(oFullFileName)
MsgBox("Found " & oFoundDocuments.Count & " documents where the specified file is used in.", vbInformation, "Where Used")
Dim oList As New List(Of String)
If oFoundDocuments.Count > 0 Then
	For Each oDoc As Document In oFoundDocuments
		oList.Add(oDoc.FullFileName)
	Next
	a = InputListBox("", oList, "", "Documents Where Used", "List Of Documents Used In")
End If

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 30 of 30

maxim.teleguz
Advocate
Advocate

Thank you for sharing that, I will try to play around with it. 

0 Likes