Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Creating a iProperty Loop Function

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
amarinXG8V6
874 Views, 3 Replies

Creating a iProperty Loop Function

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

 

 

Labels (3)
3 REPLIES 3
Message 2 of 4
A.Acheson
in reply to: amarinXG8V6

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
Message 3 of 4
amarinXG8V6
in reply to: A.Acheson

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.
Message 4 of 4
c.bloedorn
in reply to: amarinXG8V6

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?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report