PropertySet

PropertySet

WIRMNS
Enthusiast Enthusiast
920 Views
3 Replies
Message 1 of 4

PropertySet

WIRMNS
Enthusiast
Enthusiast

Hi,

 

I want to write the same propertySet in two Assembly documents.

Is there a shorter way to do it? Make a loop?

 

'Set property in Assembly
Dim oPropertySet As PropertySet
oPropertySet = _Assembly.PropertySets.Item("User Defined Properties")
oPropertySet.Item("Size").Value = cbSize.Text
oPropertySet.Item("Standaard").Value = CStr(oTable(2, 1))
oPropertySet.Item("Language").Value = cbLanguage.Text


oPropertySet = _ReferencedDocument.PropertySets.Item("User Defined Properties")
oPropertySet.Item("Size").Value = cbSize.Text
oPropertySet.Item("Standaard").Value = CStr(oTable(2, 1))
oPropertySet.Item("Language").Value = cbLanguage.Text

0 Likes
921 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor

Hi @WIRMNS.  Yes, there is a much faster way to do it.  However, the ones that get created in the 'other' document will not stay 'Linked' to the ones in the 'source' document, so they could easily become not accurate if changes are made in the 'source' document afterwards.  For instance, some custom iProperties are created and kept accurate automatically for us, because they get created when we check the checkbox in the Export Parameter column of the Parameters dialog box.  Doing that instantly creates a custom iProperty with the same name and value as the Parameter object, and when that parameter changes, that also changes the custom iProperty.  But changing the custom iProperty does not automatically change the Parameter.

 

Anyways, to do this task the way I am suggesting, you would have to access the iProperties using Inventor API code, instead of iLogic snippets.  The Inventor API way to access iProperties is through the Document.PropertySets property (which gives us a PropertySets object), and so on down the API object model to get to individual PropertySet objects, then on to Property objects, and on to their names, values, and such.  In this case, we will need to get a reference to the actual source PropertySet object.  From there, we can use one of its methods  (PropertySet.GetPropertyInfo) to gather all the Property data from that PropertySet into 3 Arrays.  Then we can use those 3 Arrays to 'set' all that information to the 'target' PropertySet in another Document, using the PropertySet.SetPropertyValues method of the 'target' PropertySet object in the other document, and supplying those same 3 Arrays as input (in the correct order).  To use the 'get' method, you must first declare and initialize those 3 Arrays (of the specified object Types), with no initial size specified, and with no initial values.  Then when you supply those 3 Arrays (in the proper order) they will get values added into them by that method.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 4

WIRMNS
Enthusiast
Enthusiast

thanks for the explanation.

0 Likes
Message 4 of 4

WCrihfield
Mentor
Mentor

Hi @WIRMNS.  Below is an example iLogic rule which includes a custom Sub routine just for the task of copying the 'Custom' PropertySet from one document to another document.  It is currently opening another document, then copying the custom properties from that document to the current document, then updating and saving the current document, but that part can be changed as needed.  This is also a fairly basic example routine, and would likely need to be developed further for dealing with more complex scenarios, such as with referenced documents within a large assembly where multiple ModelStates are being used within the components.

 

If any of the properties in the source PropertySet is not already present in the destination PropertySet, it will be created, and if it already exists, its value will be changed.  However, this method will not delete any already existing properties in the destination PropertySet that have different names than the ones in the source PropertySet.  If that deletion functionality is needed, we would need to delete all existing properties from the destination PropertySet before copying the properties to it from the source.

Sub Main
	Dim oThisDoc As Document = ThisDoc.Document
	Dim oOtherDoc As Document = ThisApplication.Documents.Open("C:\Temp\OtherDoc.ipt")
	CopyCustomPropertySet(oOtherDoc, oThisDoc)
	If oThisDoc.RequiresUpdate Then oThisDoc.Update2(True)
	If oThisDoc.Dirty Then oThisDoc.Save
	oOtherDoc.Close(True) 'True = skip save
End Sub

Sub CopyCustomPropertySet(oFromDoc As Document, oToDoc As Document)
	If oFromDoc Is Nothing OrElse oToDoc Is Nothing OrElse oToDoc.IsModifiable = False Then Return
	Dim oFromSet As PropertySet = oFromDoc.PropertySets.Item(4)
	If oFromSet.Count = 0 Then Return
	Dim oIDs() As Integer = {}
	Dim oNames() As String = {}
	Dim oValues() As Object = {}
	Try : oFromSet.GetPropertyInfo(oIDs, oNames, oValues) : Catch : End Try
	If oNames Is Nothing OrElse oNames.Length = 0 Then Return
	Dim oToSet As PropertySet = oToDoc.PropertySets.Item(4)
	Try
		oToSet.SetPropertyValues(oNames, oValues)
	Catch oEx As Exception
		Logger.Error("Error copying 'Custom' PropertySet from: " & vbCrLf & _
		oFromDoc.FullDocumentName & vbCrLf & _
		"To: " & vbCrLf & _
		oToDoc.FullDocumentName)
	End Try
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes