필터 지우기
필터 지우기

Set Property for Component

조회 수: 4 (최근 30일)
AstroJon
AstroJon 2021년 3월 23일
편집: Aimee Khan 2021년 6월 18일
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
Aimee Khan
Aimee Khan 2021년 6월 18일
편집: Aimee Khan 2021년 6월 18일
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?

댓글을 달려면 로그인하십시오.

채택된 답변

AstroJon
AstroJon 2021년 6월 18일
I would say better late than never, but we already solved this issue ourselves a couple of months ago. I forgot about this question, or else would have closed it sooner. Here's the original code:
% Load the model and create object for System Composer architecture model
model = systemcomposer.loadModel('LiDAR');
arch = get(model,'Architecture');
% Create object for the component that needs to be updated
comp = get(arch,'Components');
% Load the profile
prof = systemcomposer.loadProfile('Spacecraft_Architecture');
type = getStereotype(prof,'LiDAR');
% Update component property
setProperty(comp,'Spacecraft_Architecture.LiDAR.mass','7','kg')
The problem was trying to use "comp" in the setProperty command. Here's the code that works:
% Load the model and create object for System Composer architecture model
model = systemcomposer.loadModel('LiDAR');
arch = get(model,'Architecture');
% Load the profile
prof = systemcomposer.loadProfile('Spacecraft_Architecture');
type = getStereotype(prof,'LiDAR');
% Update component property
setProperty(arch,'Spacecraft_Architecture.LiDAR.mass','7','kg');
Our solution is different than what the setProperty doc page has as an example. Not sure where the disconnect is.
  댓글 수: 1
Aimee Khan
Aimee Khan 2021년 6월 18일
편집: Aimee Khan 2021년 6월 18일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Aimee Khan
Aimee Khan 2021년 6월 18일
편집: Aimee Khan 2021년 6월 18일
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')

카테고리

Help CenterFile Exchange에서 System Composer에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by