Yes you can use an XML-RPC script that connects to the PLECS application. Assuming you are using PLECS Standalone, refer to the "XML-RPC Interface in PLECS Standalone" section of the PLECS documentation. The XML-RPC command to generate code is plecs.codegen() and is separately mentioned in the "Code Generation" portion of the manual. The convention is plecs.codegen('path', optStruct, 'outputDir'), where path is a model name or a subsystem path. The parameters optStruct and outputDir are optional.
Below is an example script. There are a few points to note.
- The *.plecs model must be opened first via the plecs.load('mdlFile') command. 'mdlFile' must be an absolute path to the model file.
- Code is generated by the plecs.codegen('path') where 'path' is the path to the desired subsystem. Path is constructed by model_name/subsystem and model_name doesn't include the *.plecs extension.
import xmlrpc.client as xmlrpclib
import os
model_path = "C:/[path]/PLECS_RT_Box/demos/boost_converter/" #absolute path
model_name ="boost_converter_1rtbox"
subsystem_name = "Plant + Controller"
model_file = os.path.join(model_path,model_name+".plecs")
server = xmlrpclib.Server("http://localhost:1080/RPC2")
server.plecs.load(model_file) #absolute path
server.plecs.codegen(model_name+"/"+subsystem_name)