NEED A ILOGIC CODE TO ASSIGN THE ILOGIC PROPERTY TO ALL PARTS IN AN ASSEMBLY

NEED A ILOGIC CODE TO ASSIGN THE ILOGIC PROPERTY TO ALL PARTS IN AN ASSEMBLY

formobalaji
Enthusiast Enthusiast
213 Views
1 Reply
Message 1 of 2

NEED A ILOGIC CODE TO ASSIGN THE ILOGIC PROPERTY TO ALL PARTS IN AN ASSEMBLY

formobalaji
Enthusiast
Enthusiast

 LIKE, ALL THE PARTS IN THE MAIN ASSEMBLY WILL CREATE THE NEW PROPERTY NAMED "PROJECT PARTNUMBER" AS " MAIN ASSMBLY FILE NAME AND - 1, -2, -3 AS SO ON"

 

 

@Andrii_Humeniuk 

0 Likes
Accepted solutions (1)
214 Views
1 Reply
Reply (1)
Message 2 of 2

WCrihfield
Mentor
Mentor
Accepted solution

Hi @formobalaji.  Have you attempted to create this iLogic rule code yourself yet?  Have you searched within this forum to find similar questions that have already been asked before, or similar solutions that have already been posted before, as a guide to help you with this iLogic rule code?

 

Here is an example of an iLogic rule that can be ran while an assembly is the active document (showing on your screen).  When you run this rule, it will get the file name of that assembly to a variable.  Then it will create an Integer to act as suffix.  Then it will iterate through every referenced document (at all levels of the assembly, not just top level), and try to update or create a custom iProperty within each of them named ""PROJECT PARTNUMBER", and try to set its value as the assembly's file name, plus a dash "-", plus that Integer, which will be incremented by 1 each time.  I hope this is what you were expecting.  Otherwise please include more information when you ask for help with coding challenges like this.

Sub Main
	If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
		MsgBox("An Assembly Document must be active for this rule to work. Exiting.", vbCritical, "")
		Exit Sub
	End If
	Dim oADoc As AssemblyDocument = ThisDoc.Document
	Dim oAllRefDocs As DocumentsEnumerator = oADoc.AllReferencedDocuments
	Dim sCustomPropName As String = "PROJECT PARTNUMBER"
	Dim sADocName As String = System.IO.Path.GetFileNameWithoutExtension(oADoc.FullFileName)
	Dim iSuffix As Integer = 1
	For Each oRefDoc As Document In oAllRefDocs
		If oRefDoc.IsModifiable = False Then Continue For
		Dim oCustomSet As Inventor.PropertySet = oRefDoc.PropertySets.Item(4)
		Dim oCustomProp As Inventor.Property = Nothing
		Dim sNextValue As String = sADocName & "-" & iSuffix.ToString 
		Try 'try to find already existing custom property
			oCustomProp = oCustomSet.Item(sCustomPropName)
			oCustomProp.Value = sNextValue
		Catch 'that failed, so create the custom property
			oCustomProp = oCustomSet.Add(sNextValue, sCustomPropName)
		End Try
		iSuffix = iSuffix + 1
	Next
	If oADoc.RequiresUpdate Then oADoc.Update2(True)
End Sub

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)