How to get Properties of sub document

How to get Properties of sub document

re.delacruz
Observer Observer
271 Views
2 Replies
Message 1 of 3

How to get Properties of sub document

re.delacruz
Observer
Observer
 

I wish to find if the iproperties of a children exist.
Here's my progress so far. It only shows the property of the parent even under "For each"

 

Dim oDoc As Document = ThisDoc.Document
Dim oRefDocs As DocumentsEnumerator = oDoc.AllReferencedDocuments
Dim partDoc As Document
Dim Path As String = System.IO.Path.GetDirectoryName(oDoc.FullDocumentName)
'Dim FileName As String = System.IO.Path.GetFileNameWithoutExtension(partDoc.FullDocumentName)				
Dim rDisp As String
Dim rDispL As String



For Each partDoc In oRefDocs 
	Dim FileName As String = System.IO.Path.GetFileNameWithoutExtension(partDoc.FullDocumentName)	
	rDisp = FileName 
	rDispL = Len(rDisp)
	If rDisp.Substring(rDispL - 6, 4) = "mat0"  Or rDisp.Substring(rDispL -6, 4) = "MAT0"  Then
    partDoc.ComponentDefinition.BOMStructure = BOMStructureEnum.kNormalBOMStructure

	Else If rDisp.Substring(rDispL - 6, 6) = "PRT_SA" And iProperties.Value("Custom","DRAWING_NO")  <> "" Then
	'Else If iProperties.Value("Custom","DRAWING_NO")  = "123" Then
	partDoc.ComponentDefinition.BOMStructure = BOMStructureEnum.kInseparableBOMStructure
      MessageBox.Show(Filename, "Title")

	End If
Next
	

 

0 Likes
272 Views
2 Replies
Replies (2)
Message 2 of 3

Dev_rim
Advocate
Advocate

Hi There,
First of all you can view all properties by reaching the document object.
It can be something like this,

Dim doc As Document
Set doc = ThisApplication.ActiveDocument

So you have document object right now.

To reach every property that document have you can use PropertySet object. And it contained by PropertySets object.

So 'PropertySets' object contains 'PropertySet' objects, and they contains 'Property' objects.

 

There is 4 different PropertySet in PropertySets:

-Inventor Summary Information / 1

-Inventor Document Summary Information / 2

-Design Tracking Properties  / 3

-Inventor User Defined Properties / 4

 

To reach them you can use indexes or you can just use foreach. If you want to do it with for each that's the code you need:

Sub Main()
Dim doc As Document
Set doc = ThisApplication.ActiveDocument
Dim ps As PropertySet
  For Each ps In doc.PropertySets
    Dim p As Property
    For Each p In ps
      Debug.Print p.Name
    Next
  Next
End Sub

 

Or if you want to look for specific kind of property set -for example 'Inventor User Defined Properties' (indexed as 4) - so you have to use indexes. Just like this:

 

Sub Main()
Dim doc As Document
Set doc = ThisApplication.ActiveDocument
Dim ps As PropertySet
Set ps = doc.PropertySets.Item(4)
Dim p As Property
    For Each p In ps
      Debug.Print p.Name
    Next
End Sub

 

If you want to do it for a subdocument you can just create an 'Document' object for that sub document and use that code.

 

If you have a trouble about accessing documents there is a wonderful solution made by @JelteDeJong 

You can find the rest on that solution:

https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/accessing-all-referenced-documents-i...

 

Thanks

Devrim

If my answer is solved your problem, please mark it as Solution

Freundliche Grüße / Kind Regards
Message 3 of 3

WCrihfield
Mentor
Mentor

Hi @re.delacruz.  What @Dev_rim is talking about is accessing the iProperties of those referenced documents using the Inventor API route, which I also usually recommend too.  But if you want to stick with using the iLogic shortcut snippet, similar to the following example from the code you posted:

iProperties.Value("Custom","DRAWING_NO")

...you will need to make some changes to it, before it will be accessing the correct document.  You can see by looking at that line of code that there is no indication of what document it is accessing the specified iProperty from.  When used that way, it is usually accessing the iProperties of the 'active' document, which in this case is the top level assembly or drawing document that the code was initially started from.  If you want that line of code to target a specific referenced document, you must input the 'name' of the document you want it to target as the first of three inputs within the ( & ) symbols.  That document name generally needs to be the file's name, without the file's path, but with the file's extension.  Sometimes you can use the Document.DisplayName for that value, but that may not be stable, because it is a Read/Write property of the document, and it can be changed.  I usually use the System.IO.Path.GetFileName() method, and input the Document.FullFileName into that GetFileName method to obtain the proper String I need for use in the iProperties.Value() snippet for accessing a referenced document.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)