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 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Arnab Sen
el 31 de Dic. de 2015
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:
Ver también
Categorías
Más información sobre MATLAB Classes en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!