Contenu principal

Modification programmatique du modèle

Utiliser des API pour effectuer des tâches de modélisation de base comme l’ajout, la configuration et la connexion de blocs

Vous pouvez créer, modifier, rechercher et vérifier des modèles Simulink® de manière programmatique. Pour qu’il soit possible d’interagir avec un modèle de manière programmatique, celui-ci doit être chargé. Lorsque vous créez ou ouvrez un modèle, celui-ci est également chargé. Utilisez les fonctions répertoriées sous « Créer des modèles » pour créer, charger ou ouvrir un modèle. Utilisez ensuite les autres fonctions de cette page pour modifier le modèle et son contenu de manière programmatique. Dans les arguments d’entrée de la fonction, spécifiez l’objet que celle-ci doit modifier sous forme de handle, de chemin d’accès ou de nom de fichier. Cet objet cible peut être un modèle, un composant tel qu’un sous-système ou une bibliothèque, ou bien un élément de modèle comme un bloc ou une ligne de signal. Vous pouvez spécifier des objets cibles dont vous connaissez le nom et l’emplacement ou rechercher de manière programmatique ceux qui remplissent certains critères. Pour en savoir plus, consultez la documentation de la fonction et Get Handles and Paths.

Si vous souhaitez partager un modèle avec un tiers sans en révéler la propriété intellectuelle, créez une version protégée du modèle avec la fonction Simulink.ModelReference.protect (Embedded Coder). Pour en savoir plus, consultez Protect Models to Conceal Contents (Embedded Coder).

Pour plus d’informations sur l’exécution programmatique de simulations, consultez Run Simulations Programmatically. Pour créer et modifier des projets de manière programmatique, consultez Create and Edit Projects Programmatically. Pour configurer l’éditeur Simulink de manière programmatique, consultez Programmatic Model Editor Appearance Parameters. Pour débugger des simulations depuis la fenêtre de commande MATLAB®, consultez Débugger les simulations de manière programmatique.

Fonctions

développer tout

getSimulinkBlockHandleGet block handle from block path
getfullnameGet path that identifies block or line
get_paramGet parameter names and values
gcsGet path name of current system
gcbGet path name of current block
gcbhObtenir le handle du bloc actuel
gcbpGet Simulink.BlockPath object for current block
bdrootTop-level model of current system
getCurrentAnnotationGet current annotation object
getCallbackAnnotationGet annotation executing callback

Trouver des éléments de modèle

find_systemFind models, blocks, lines, ports, and annotations
Simulink.findBlocksTrouver des blocs dans les modèles Simulink
Simulink.findBlocksOfTypeTrouver un type de bloc spécifié dans les modèles Simulink
Simulink.FindOptionsSpecify options for finding blocks in models and subsystems
hilite_systemHighlight block, signal line, port, or annotation

Trouver des modèles

find_systemFind models, blocks, lines, ports, and annotations
Simulink.allBlockDiagramsFind loaded Simulink models and libraries
modelfinderSearch and open examples, models, and projects (depuis R2022a)
modelfinder.importDatabaseImport database to Model Finder (depuis R2023b)
modelfinder.createDatabaseCreate new database to index models (depuis R2023b)
modelfinder.setDefaultDatabaseSet default database to index models (depuis R2023b)
modelfinder.setSearchDatabaseSet search scope to find models (depuis R2023b)
modelfinder.searchFilterCreate Model Finder search filter (depuis R2025a)
modelfinder.registerFolderIndex models in Model Finder (depuis R2022a)
modelfinder.unregisterFolderRemove models from Model Finder (depuis R2022a)
modelfinder.deleteDatabaseRemove database from Model Finder (depuis R2023b)

Obtenir les métadonnées du modèle

Simulink.MDLInfoExtract SLX, SLXP, or MDL file information without loading file
Simulink.MDLInfo.getDescriptionExtract SLX, SLXP, or MDL file description without loading file
Simulink.MDLInfo.getMetadataExtract SLX, SLXP, or MDL file metadata without loading file

Démarrer Simulink

simulinkOuvrir la page de démarrage de Simulink
start_simulinkStart Simulink without opening any windows
isSimulinkStartedCheck whether Simulink is started
slLibraryBrowserOpen, load, and close Simulink Library Browser, create and get handle of Library Browser object

Créer, charger, ouvrir, enregistrer et fermer des modèles

new_systemCreate Simulink model or library in memory
load_systemCharger un modèle Simulink en mémoire
open_systemOpen model, library, subsystem, or block dialog box
save_systemSave Simulink model
close_systemClose Simulink model window or block dialog box
bdcloseClose any or all Simulink model windows unconditionally

Ajouter, remplacer et supprimer des blocs

add_blockAjouter des blocs à un modèle
addtermsAdd terminators to unconnected ports in model
replace_blockReplace blocks in Simulink model
delete_blockDelete blocks from Simulink system
Simulink.BlockDiagram.deleteContentsDelete graphical contents of model
Simulink.SubSystem.deleteContentsDelete contents of subsystem

Connecter les blocs

Simulink.connectBlocksConnect blocks with signal lines (depuis R2024b)
add_lineAdd line to Simulink model
delete_lineDelete line from Simulink model

Modifier les paramètres

get_paramGet parameter names and values
set_paramSet Simulink parameter value
add_paramAdd parameter to Simulink model
delete_paramDelete model parameter added with add_param function
docblockGet or set editor invoked by Simulink DocBlock block

Configurer la disposition du modèle

Simulink.BlockDiagram.arrangeSystemImprove layout of block diagram
Simulink.BlockDiagram.routeLineRoute existing lines of model
Simulink.BlockDiagram.resizeBlocksToFitContentAdjust block size to fit displayed value (depuis R2024b)

Regrouper les éléments de modèle en sous-systèmes

Simulink.BlockDiagram.createSubsystemCreate subsystem containing specified set of blocks
Simulink.BlockDiagram.expandSubsystemReplace subsystem with subsystem contents
Simulink.SubSystem.copyContentsToBlockDiagramCopy graphical contents from subsystem to another model
Simulink.SubSystem.deleteContentsDelete contents of subsystem
bdIsSubsystemDetermine whether model is subsystem
isSimulinkStartedCheck whether Simulink is started
bdIsLoadedDetermine whether model, subsystem, or library is loaded
bdIsDirtyDetermine whether model, subsystem, or library has unsaved changes
slIsFileChangedOnDiskDetermine whether model has changed since it was loaded
bdIsLibraryDetermine whether model is library
bdIsSubsystemDetermine whether model is subsystem
edittime.getDisplayIssuesCheck whether model design warnings and errors are on
edittime.setDisplayIssuesDetect model design errors and warnings

Utiliser des templates de modèle

Simulink.exportToTemplateCreate template from model or project
Simulink.createFromTemplateCreate model or project from template
Simulink.findTemplatesFind model or project templates with specified properties
Simulink.defaultModelTemplateSet or get default model template

Exporter des modèles

Simulink.ModelReference.protectObscure referenced model contents to hide intellectual property
Simulink.exportToVersionExport model, library, or project for use in previous version of Simulink
Simulink.exportToTemplateCreate template from model or project
slCharacterEncodingSpecify encoding to use in code generated from Simulink models

Imprimer des modèles

frameeditOpen PrintFrame Editor to edit print frames for Simulink and Stateflow block diagrams
orientPaper orientation for printing or saving
printPrint figure or save to specific file format

Objets

ModelFinderFilterModel Finder search filter (depuis R2025a)
Simulink.AnnotationCreate and specify properties of text, image, and area annotations

Rubriques

Spécifier des objets à modifier de manière programmatique

Créer des modèles

Formater les modèles

Partager des modèles