Set Property for Component
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have a model with several nested levels (i.e. - spacecraft > payload > payload component). I am having trouble updating the property of such a payload component via the command line. The component has been made a Simulink model as I want to be able to re-use it in other architectures and models and produce the same behavior. The component also has a component stereotype applied with 3 properties: mass, power and volume. I am trying to update the mass value of the particular instantiation of the payload component in my current model using the "setProperty" command. Here's some of my code:
% Load the model and create object for System Composer architecture model
model = systemcomposer.loadModel(<payload component Simulink model>);
arch = get(model,'Architecture');
% Create object for the component that needs to be updated
comp = get(arch,'Components');
% Update component property
setProperty(comp,'<profile>.<stereotype>.mass','7','kg')
However, I get the following error:
No method 'setProperty' with matching signature found for class 'systemcomposer.arch.Element'.
Error in systemcomposer.arch.Component/setProperty
Strangely, "comp" is empty - a 0x0 Component. If instead I export the model using:
systemcomposer.exportModel(<payload component Simulink model>)
I get a 1x1 struct where the first element is a 1x8 table of "components", one of which is the mass property I am trying to update. What am I missing?
1 Commento
Aimee Khan
il 18 Giu 2021
Modificato: Aimee Khan
il 18 Giu 2021
The error message is not helpful to diagnose the problem. It would be easier if we could see your code without the chevrons <> replacing your inputs. What version of MATLAB are you using?
Risposta accettata
AstroJon
il 18 Giu 2021
1 Commento
Aimee Khan
il 18 Giu 2021
Modificato: Aimee Khan
il 18 Giu 2021
The difference could be that you already defined the stereotypes so instead of having to create them from scratch using the API, you just loaded your profile. The getStereotype line isn't needed here.
If you intended to add your property to the architecture of your model, then the solution works. Creating a new component requires addComponent. Finding an existing component requires lookup.
Più risposte (1)
Aimee Khan
il 18 Giu 2021
Modificato: Aimee Khan
il 18 Giu 2021
To set property for a component means that a stereotype with properties is applied on the component. In order to have a stereotype and profile to define, go into the Profile Editor and create a stereotype with properties to apply to components. For more information, see Define Profiles and Stereotypes and then, Use Stereotypes and Profiles. For a code example, see the example for setProperty. To find a component in the model to set a property for, see lookup.
Here is an example with an existing model:
Launch the keyless entry system project.
scKeylessEntrySystem
Load the model and find the FOB Locator System component.
model = systemcomposer.loadModel('KeylessEntryArchitecture');
comp = lookup(model,'Path','KeylessEntryArchitecture/FOB Locator System');
Set the Cost property on the component.
setProperty(comp,'AutoProfile.System.Cost','200','USD')
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!