Has anyone stored a custom datatype in poCmd.mpoExtra using [serializable()]

I’m new to Solidworks and PDM, first server was started up just under 2 years ago. Since then I had to write a fair bit of API for SW and PDM. I’m not new to APIs, did Solid Edge stuff before, but new to Solidworks and PDM. I had some task variables I wanted to store and wanted them encapsulated in a datatype. So I chose to decorate the class with [Serializable()] then put that in a single mpoExtra variable.

Have others done this? Is it considered a safe method?

I had a longer post with more details, but decided to trim it down to start the conversation.

1 Like

I’m not sure I understand you entirely. Which hook are you talking about EdmCmd_TaskDetails or EdmCmd_TaskLaunch ?

the mpoExtra normal only gets you an instance of IEdmTaskInstance or IEdmTaskProperties which are only used to allow to save either variables or your own-defined data in the task itself (Through SetValEx or GetValEx)

I don’t think you should be setting mpoExtra.

I was too vague, and I still don’t have all the correct names/terms at the top of my head. What you say is pretty much what I’m doing. Using SetValEx and GetValEx, but instead of having a bunch of them I just have one. I don’t have much real, guided, experience but I don’t like casting from System.object all the time. I think they call it strongly typed code, I prefer that, it’s just easier to read and follow. Anyway instead of having a bunch of values stored with string names (can can be defined as const, I know) and casting, I made a struct of the data I needed to store and decorated it Serializable() then store that string as the one and only user variable. This way when I deserialize the stored string all the types are there and I access them as Properties.

Just wondering if anyone else is using this method. What I have seems to be working, but frankly, I don’t know if I implemented it right or the best way.

The process is outlined in the Remarks of the SW PDM API Help:

Call IEdmTaskProperties::SetValEx to store variable data entered by the user in the task definition setup page on the client machine. The task definition setup page displays during the processing of the EdmCmdType.EdmCmd_TaskSetup hook when the task add-in calls IEdmAddIn5::OnCmd.

Custom data types and objects must have been serialized to a string, numeric type, or date before calling IEdmTaskProperites::SetValEx. For example:

Serialize the object data to XML or JSON using StringBuilder, XmlWriter, XmlSerializer, etc.
Call IEdmTaskProperites::SetValEx to store the resulting string.
Call IEdmTaskProperites::GetValEx to retrieve the stored string.
Initialize the new instance of the object from XML/JSON using StringReader, XmlReader, XmlSerializer, etc.
To get the values when the task is executing on the server, call IEdmTaskInstance::GetValEx during the processing of the EdmCmdType.EdmCmd_TaskRun hook.

NOTE: User-defined variables are not related to the card variables created using the administration tool. To access card variables for this task definition, call IEdmTaskProperties::GetVar and IEdmTaskProperties::SetVar.

1 Like