Message Boards Message Boards

0
|
8381 Views
|
3 Replies
|
3 Total Likes
View groups...
Share
Share this post:

[?] Use WSMSetValues for setting records and replaceable packages?

My model has a parameter field that expects a record, but when I try to use WSMLink to set it e.g.

WSMSetValues[model,{"component.recordParam" -> DotName["myPackage","myRecord()"]

I get the error

WSMSetValues::irl: The list of rules is not on the form {"variable" -> numericValue, ...}.

If I don't use DotName and pass it as a string, it shows up as a string in the model, which will fail to compile/verify.

In addition to setting this record parameter, I will also want to be able to set the Medium of a model using WSMSetValues. Is there a generic way of setting a parameter that handles any type via WSMLink? Thanks.

POSTED BY: Eric Smith
3 Replies

Unfortunately there is currently no way to set values from WSMLink to an expression. WSMSetValues only takes literals (numbers, booleans and strings). There is also currently no way to redeclare things (which I assume is what you want for the Medium).

We'd like to add this in a future version, but haven't designed how it would work yet.

Today I recommend that you use Model Center for changes like these.

A really bad workaround would be to fetch the Modelica string, make the modifications yourself using string manipulation, and then evaluate the Modelica string. I don't recommend it, but below are the pieces you would need.

Be careful, you can easily destroy your models using this.

str = WSMModelData[model, "ModelicaString"]
(* Do string manipulation here *)
newstr = ...
(* If your model is not on top level you need to prepend a "within A.B.C;" to newstr,
  where the A.B.C is the path to the package the model is placed *)
WSMLink`Library`EvaluateModelicaInput[newstr]
POSTED BY: Malte Lenz

Awesome, I figured I'd have to do some text editing, but I didn't know about WSMLink'Library'EvaluateModelicaInput. Just now I was just able to script about 30 records and use within to put them where I needed them. Thanks!

POSTED BY: Eric Smith

Glad it helped.

As usual, the functions in the WSMLink`Library` context are undocumented and therefore unsupported, so they might stop working in future releases.

POSTED BY: Malte Lenz
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract