Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Apprentice Model States

Spoiwk
Advocate

Apprentice Model States

Spoiwk
Advocate
Advocate

Hi Forum Users,

 

I wrote a copy-design tool which copies our ilogic parts and places them into the active assembly. I have issues with the referenced assemblies. Whenever they have a modelstate the set properties function does not work. Most likley because it has more propertysets.

 

Can someone explain to me how I can fix this issue?

 

With kind regards,

 

Robert

Reply
666 Views
7 Replies
Replies (7)

WCrihfield
Mentor
Mentor

Hi @Spoiwk.  When there is more than just the one original model state in a model type document, this can complicate the step of making sure you are working with the right Document object reference.  When there are is only the one original model state present in a document, there is no such thing as a 'factory' or 'member' version of that document, just the one, main document reference.  But when there is more than one, suddenly that distinction of knowing which one is which, and how to make sure you are working with the right one becomes important.  The 'factory' version of the document is the one that is currently under the influence of the model state that is currently 'active' in that document.  And conversely, a 'member' version of that document one that is under the influence of any other model state that is not the 'active' model state.  You can only read data from member versions, but the factory version is the only version you can read & write (edit).  If you are used to using the simple iLogic shortcut snippet 'iProperties.Value()' to access the properties of documents, you need to know that this  tool does not yet include a clear way of dictating which model state version of the 'target' document it will be accessing.  Right now, when model states are involved, it may allow you more control to use the API route to access the properties of documents instead of using that iLogic shortcut snippet.  The API route is simply stepping down the object structure of the document to get to the actual property objects, then using their built-in methods/properties to read their values, set new values, create new properties, and so on.  (Document.PropertySets.PropertySet.Property.Value)

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Spoiwk
Advocate
Advocate

Hi,

 

Thank you for your reply! I was aware of the factory file but i dont know how I can manage this. Especially in the apprentice environment. I have the following code. Can you tell me where I need some adjustments?

 

Public Sub SetProperty(CurrentDoc As Inventor.ApprenticeServerDocument, ByVal oproperty As String, ovalue As String)
        Dim invCustomPropertySet As Inventor.PropertySet = CurrentDoc.PropertySets.Item("Design Tracking Properties")
        Try
            Dim invVolumeProperty As Inventor.Property = invCustomPropertySet.Item(oproperty)
            invVolumeProperty.Value = ovalue
        Catch
            MsgBox("Could not get value", MsgBoxStyle.Critical, "SetProperty")
        End Try
    End Sub
0 Likes

WCrihfield
Mentor
Mentor

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

EESignature

(Not an Autodesk Employee)

Spoiwk
Advocate
Advocate
Hi,

Thank you for your detailled explanation. However the function and also the dynamic for each didnt give me the outcome. The Factory component definition gave me an error also, maybe because its not available in the apprenticeserver environment. The oProp.Value = ovalue gave me also an error. Which was the same as before. The weird thing is, both values are a string. So I guess it could be set as a string. So indeed maybe it is the decleration of the documentobject, which I cannot set to factory. (maybe if i can set it somehow to factory it will give me a itemlist instead of a string format)

Thanks anyways, I didn't knew how to change the component definition. But I think i'm a step further right now.
0 Likes

WCrihfield
Mentor
Mentor

Just in case the ApprenticeServer is more strict or critical than regular iLogic, maybe we should try one additional step.  After the document type check for if it is a Part, if it is a part, create a variable for a PartComponentDefinition and set CurrentDoc.ComponentDefinition as its value, then try using that variable to check if it 'IsModelStateMember' and if so, use that variable for getting 'FactoryDocument'.  Same for if it is an assembly, use a variable defined as an AssemblyComponentDefinition, then set its value the same way, then use it the same way.  That may bypass the unrecognized property of the generic ComponentDefinition object returned from the CurrentDoc directly.  Do you understand this idea?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

WCrihfield
Mentor
Mentor

Here is an alternate version of the last code I posted, with the modifications I mentioned above, just to see if they make any difference.  It may also be that the value returned from the FactoryDocument property (currently defined as '_Document', which is even more 'generic' than the standard Document object), may simply not be compatible with the ApprenticeServerDocument object that the variable is defined as.  I don't know.  If this still does not work, could you maybe post more specifically what the error messages are saying, so we can get a better idea about which parts of the code are failing and may be why.

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 Then
		Dim oPDef As PartComponentDefinition = CurrentDoc.ComponentDefinition
		If oPDef.IsModelStateMember Then
			CurrentDoc = oPDef.FactoryDocument
		End If
	ElseIf CurrentDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
		Dim oADef As AssemblyComponentDefinition = CurrentDoc.ComponentDefinition
		If oADef.IsModelStateMember Then
			CurrentDoc = oADef.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

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Spoiwk
Advocate
Advocate

Thank you for making the code and also the effort. Unfortunately it doesn't work. I also tried the way you said in the previous message. But with the same outcome. With declaring the object definition of the component definition gives an error. I think it has to do with the apprentice object not having the same references as the inventor componentdefinition object. So I think there is no solution to this problem. I can reach the IsModelStateMember and also the IsFactorymember but it does not give me the item outcome I need in the PropertySet. Thanks for your efford I really apreciate it!

0 Likes