Hi @Spoiwk. I am honestly not that familiar with Apprentice, but I know that it is in a process outside of Inventor, and uses a sub-set of Inventor's API features, and I know that a lot of things accessed through Apprentice are ReadOnly, but that it is good for working with file references and iProperties. So, I am not sure if it has the ability to deal with ModelStates. I know how to get the 'factory' version of a given model document, but in this situation, we can not be sure if that is really the version of the document that you want to set the iProperty value to, because it does not include any sort of 'target' ModelState intention. For instance, if we were working with components in an assembly, we could read the ModelState that the component is currently set to, then use that as a guide for which ModelState to write the property to, but when a document is supplied, all we can do is assume that we should write the value to which ever ModelState is currently active in that document.
Also, I noticed that in the code you posted, the variable name being used for the PropertySet indicates that you were expecting to be working with a 'custom' iProperty, but then you are setting its value to the Design Tracking Properties set. Then you named your variable for the Property as though you were expecting to be accessing its Volume property. If that is the case, I am not sure that would work. Many of the iProperties are actually ReadOnly, and I believe the Volume property is one of them (Link). Since I was not sure which PropertySet or Property you may be wanting to use this SetProperty Sub routine for, I decided to make it a bit more dynamic, so that it will simply try to find the first Property with the supplied name in any PropertySet, then attempt to set its value.
Here is what I came up with:
Public Sub SetProperty(CurrentDoc As Inventor.ApprenticeServerDocument, ByVal oproperty As String, ovalue As String)
'make sure we are working with the ModelState 'factory' version of the document, if one is available
If CurrentDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Or _
CurrentDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
If CurrentDoc.ComponentDefinition.IsModelStateMember Then
CurrentDoc = CurrentDoc.ComponentDefinition.FactoryDocument
End If
End If
Dim bFound As Boolean = False
For Each oPSet As PropertySet In CurrentDoc.PropertySets
For Each oProp As Inventor.Property In oPSet
If oProp.Name = oproperty Then
bFound = True
Try
oProp.Value = ovalue
Catch
MsgBox("Could not set value of iProperty named " & oproperty, MsgBoxStyle.Critical, "SetProperty")
End Try
End If
Next 'oProp
Next 'oPSet
If bFound = False Then
MsgBox("Could not find iProperty named " & oproperty, MsgBoxStyle.Exclamation, "SetProperty")
End If
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

(Not an Autodesk Employee)