Is there anyway to change the code generation options(Storage class, HeaderFile attribute) automatically based on name given to the new object in model explorer?

조회 수: 4 (최근 30일)
Hi all, I need some help with automation. I have created a few custom data classes for Simulink models. Now, if the user creates a new data object using those custom data classes in Model Explorer, is there anyway to automatically change the code generation options for that object based on the name assigned to that object by the user. Ideally, I would like to have the code generation options to change dynamically upon detecting a change in the name field.
Some Code:
classdef my_Parameter < Simulink.Parameter
methods
function setupCoderInfo(obj)
useLocalCustomStorageClasses(obj, 'mypkg');
obj.CoderInfo.StorageClass = 'Custom';
obj.CoderInfo.CustomStorageClass = 'Define';
obj.CoderInfo.CustomAttributes.HeaderFile = 'xyz.h';
end
end % methods
end % classdef

답변 (1개)

Arnab Sen
Arnab Sen 2015년 12월 31일
I understand that you would like to set the 'Code Generation Options' based on the name of the Data Object of a Data Class.
This is possible you allow the user to rename the Data Objects with a method in the Data Class itself and in the same method you can make the appropriate changes in the 'Code Generation Options'.
For example, you may include the following method in your 'my_parameter' class definition.
function Rename(dataObj,oldName,newName)
% Update the Code generation option for the data object. a mapping can be used here to
%map 'newname' to particular option value
dataObj.CoderInfo.StorageClass='FileScope'
% Get the handle of the appropriate workspace
hws = get_param('myModel','modelworkspace');
% Create a new reference to the data object with name as 'newName'
hws.assignin(newName,dataObj);
% Remove the old reference from the particular workspace
expr=strcat('clear','oldName');
evalin(hws,expr);
end
Now User should rename the object by execution following command in MATLAB command window
>>Rename(dataObject,'oldName','newName')
Refer to the following link for more details about the functions used in above method:
  댓글 수: 1
SP
SP 2016년 1월 1일
Thank you for your help, but unfortunately this is not quite what I am looking for.
What I am looking for is a way to automatically set the code generation options based on the name assigned to the variable. So, when a developer creates a new variable/data type for a model or changes the name of one of the already existing variable in the DD using the model explorer window, I want to set/change the code generation options for that variable accordingly.
I was thinking about this alternative approach. I can write a matlab script that parses through each object in the DD and updates the code generation options. The script would have to be called before building the model.

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

카테고리

Help CenterFile Exchange에서 MATLAB Classes에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by