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

Posted 7 months ago
624 Views
|
3 Replies
|
3 Total Likes
|
 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.
3 Replies
Sort By:
Posted 7 months ago
 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 *) WSMLinkLibraryEvaluateModelicaInput[newstr] 
 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!
 Glad it helped.As usual, the functions in the WSMLinkLibrary context are undocumented and therefore unsupported, so they might stop working in future releases.