Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Creating a iProperty Loop Function

amarinXG8V6
Advocate

Creating a iProperty Loop Function

amarinXG8V6
Advocate
Advocate

Hi everyone,

I'm trying to figure out how to write an external rule that will look at the top level assembly from which the rule is launched and gather the value that is entered in the Project: Project iproperty field. I want that value fed down to the sub-assembly/ part level Project: Project iproperty field. I assume it will be some sort of loop style function since I won't know exactly how many parts/sub-assemblies will be present in the top level assembly.

 

amarinXG8V6_0-1647985673257.png

 

 

0 Likes
Reply
Accepted solutions (1)
973 Views
3 Replies
Replies (3)

A.Acheson
Mentor
Mentor
Accepted solution

For the iproperties I would use All Referenced Documents (1) This targets only the single file even if used in multiple sub assemblies so is the shortest route to target each documents. Then next is to loop through the  documents and then actually retrieve the iproperties (2)I have left a document filter in there in case you want to filter for part/assembly documents using "kPartDocumentObject" / "kAssemblyDocumentObject".

 

 

Dim oAssyDoc As AssemblyDocument
 oAssyDoc = ThisApplication.ActiveDocument 
 ' Get the Design Tracking property set.
Dim AssyDesignPropSet As PropertySet
AssyDesignPropSet = oAssyDoc.PropertySets.Item("Design Tracking Properties") 

' Get the Description property.
Dim AssyProj As Inventor.Property
AssyProj = AssyDesignPropSet.Item("Project")

'Get all of the referenced documents.
Dim oRefDocs As DocumentsEnumerator
oRefDocs = oAssyDoc.AllReferencedDocuments

'Iterate through the list of documents.
Dim oRefDoc As Document
For Each oRefDoc In oRefDocs
	' If oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
'		Logger.Info("DisplayName: "& oRefDoc.DisplayName)'FileName
'		Logger.Info("FullFileName: "& oRefDoc.FullFileName)'FilePath

        ' Get the Design Tracking property set.
         Dim DesignTrackPropSet As PropertySet
         DesignTrackPropSet = oRefDoc.PropertySets.Item("Design Tracking Properties") 

       ' Get the Description property.
                Dim RefProj As Inventor.Property
         RefProj = DesignTrackPropSet.Item("Project")
   		Try
			RefProj.Value = AssyProj.Value
		Catch
			Logger.Info("Read Only - "& oRefDoc.DisplayName )
		End Try
    'End If
Next

Also you can use a function with Vb.Net to reduce extra lines required and to also work with other iproperties easily. 

 

Sub Main

Dim oAssyDoc As AssemblyDocument
oAssyDoc = ThisApplication.ActiveDocument 
 
Dim oAssyProj As [Property]
oAssyProj= GetiProp(oAssyDoc,"Project")
Logger.Info(oAssyProj.Value)


'Get all of the referenced documents.
Dim oRefDocs As DocumentsEnumerator
oRefDocs = oAssyDoc.AllReferencedDocuments

'Iterate through the list of documents.
Dim oRefDoc As Document
For Each oRefDoc In oRefDocs
	' If oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
		'Logger.Info("DisplayName: "& oRefDoc.DisplayName)'FileName
		'Logger.Info("FullDocumentName: "& oRefDoc.FullDocumentName)'FilePath
 
		Dim oRefProjNo As [Property]
		oRefProjNo = GetiProp(oRefDoc,"Project")

		Try				 
		oRefProjNo.Value = oAssyProj.Value
		Catch
		Logger.Info("Read Only - "& oRefDoc.DisplayName )
		End Try
      'End If
Next


End Sub

Function GetiProp(oDoc As Document,iPropName As String)As [Property]
	
	 ' Get the Design Tracking property set.
     Dim DesignTrackPropSet As PropertySet
     DesignTrackPropSet = oDoc.PropertySets.Item("Design Tracking Properties") 

     ' Get the Description property.
     Dim oProjProp As Inventor.Property
     oProjProp = DesignTrackPropSet.Item(iPropName)
	 Return oProjProp
End Function

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes

amarinXG8V6
Advocate
Advocate
Hi @A.Acheson,

I tried the first portion of code the you provided and it worked great! Thank you for the support. Have a good day.
0 Likes

c.bloedorn
Enthusiast
Enthusiast

Hi,

Is it also possible to change the iproperty of the fist level children only. So if there is a subassembly within the main assembly to not alter the iproperties of parts within it?