文档

Automate Label Management in a Simulink Project

此示例显示了如何进行Simulink®项目功能来管理标签。万博1manbetx

Open the Airframe Example Project

Run the following commands to create and open a working copy of the "sldemo_slproject_airframe" example.

万博1manbetxsimulink.modelmanagement.project.projectDemo('机体');rebuild_s_functions('no_progress_dialog');
初始化:项目路径设置工作文件夹,以“ GCC”识别阴影的项目文件构建。MEX成功完成。

获取一个项目对象。

使用Simuli万博1manbetxnkProject函数获取项目对象,以操纵命令行的当前打开的Simulink项目。

project = 万博1manbetxsimulinkProject;

查看文件的标签

Examine the Files property of the project. The Files property contains an array of file objects, one for each file in the project.

文件= project.files;disp(files);
1x31带有属性的ProjectFile阵列:路径标签修订版SourceControlStatus

您可以使用索引访问此数组中的文件。以下命令获取文件编号2。每个文件都有两个属性描述其路径和附加标签。

afile =文件(2);disp(afile);
ProjectFile with properties: Path: '/tmp/BR2018ad_802882_51908/publish_examples0/bml.batserve.242784/work/MATLAB/projects/slexamples/airframe5/custom_tasks/analyzeModelFiles.m' Labels: [1x1 slproject.Label] Revision: '' SourceControlStatus:Notundersourcecontrol

Find information about a file's attached labels by indexing into the file object's Labels property. The following command gets the first label attached to this particular file.

标签= afile.Labels(1);disp(标签);
带有属性的标签:文件:'/tmp/BR2018AD_802882_51908/PUBLISH_EXAMPLES0/BML.BATSERVE.242784/WORK/MATLAB/MMATLAB/MMATLAB/MMATLAB/MMATLAB/PROMESTS/SLEXEXILS/SLEXAMPLASE/SLEXELPMAMPLASE/AIRFRAME5/AIRFRAME5/COUSTOM_TASKSSSS/ANALALYZEMODELFIELS.MMENALEN NAMALENAL NAMANENALYZEMODELFIELS.MMMM类别名称:“分类”

将标签附加到文件子集。

以下代码将“分类”类别中的标签“设计”附加到项目中的所有文件,并使用.m文件扩展名。

First get the list of files:

文件= project.files;

Then loop through each file and attach the label 'Design' from the 'Classification' category if the file has the extension .m.

为了fileIdx = 1:numel(file)file = file(fileidx);[〜,〜,fileextension] = fileparts(file.path);如果strcmp(fileExtension,'.m')addlabel(文件,'Classification',,,,'设计');结尾结尾

找到一个命名标签

You can set and query data on a label that is attached to a file. To do this, you first need to find the file object. You can do this by looping through all files in the project, as shown in the previous step. Alternatively, you can use the findFile function on the project.

以下代码找到了文件“ UTITIOR/REBUILD_S_FUCTIONS.M'的文件对象。

pathToLocate = fullfile(“公用事业”,,,,'rebuild_s_functions.m');file = findfile(project,pathtolocate);

检查标签属性获取数组的实验室el objects, one for each label attached to the file.

标签= file.labels;disp(标签);
带有属性的标签:文件:'/tmp/BR2018AD_802882_51908/PUBLISH_EXAMPLES0/BML.BATSEVE.242784/类别名称:“分类”

要通过名称找到标签,请在文件对象上使用FindLabel。

标签= FindLabel(文件,'Classification',,,,'设计');

Create a New Category

You must create new labels before you can attach them to a file. You define labels in categories, giving each category a name and supported data type.

以下代码创建了一个名为工程师的标签类别,可用于表示项目中的文件所有权。这些标签具有用于附加字符串数据的CHAR数据类型。

createCategory(项目,'Engineers',,,,'char');EngineersCategory = FindCategory(项目,'Engineers');createLabel(engineersCategory,'Sam');createLabel(engineersCategory,'拍');createLabel(engineersCategory,'Alex');

现在,您可以将“工程师”类别的SAM标签附加到项目中的文件中。

addlabel(文件,'Engineers',,,,'Sam');标签= FindLabel(文件,'Engineers',,,,'Sam');

设置标签数据

以下命令设置附件标签的数据。

label.data =“维护责任”; disp(label)
带有属性的标签:文件:'/tmp/BR2018AD_802882_51908/PUBLISH_EXAMPLES0/BML.BATSEVE.242784/Sam'CatporyName:“工程师”

更多信息

万博1manbetxSimulink项目文档

Was this topic helpful?