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!