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
0 个评论
回答(1 个)
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:
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 MATLAB Classes 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!