# Build plecs file in python

**URL:** <https://forum.plexim.com/t/build-plecs-file-in-python/965>\
**Category:** PLECS\
**Tags:** plecs, python, xml-rpc\
**Created:** [February 19, 2021, 5:35am UTC](https://forum.plexim.com/t/build-plecs-file-in-python/965 "2021-02-19T05:35:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![k123123](https://avatars.discourse-cdn.com/v4/letter/k/e9c0ed/32.png) [@k123123](https://forum.plexim.com/u/k123123)\
**Post date:** [February 19, 2021, 5:35am UTC](https://forum.plexim.com/t/build-plecs-file-in-python/965/1 "2021-02-19T05:35:23Z")

</div>

Hi,

Is it possible to create .elf file for a plecs model using python, instead of opening the model in plecs and using coder options?

---

<div class="post-metadata">

**Author:** ![Bryan\_Lieblick](https://dub1.discourse-cdn.com/flex006/user_avatar/forum.plexim.com/bryan_lieblick/32/10_2.png) [@Bryan\_Lieblick](https://forum.plexim.com/u/Bryan_Lieblick)\
**Post date:** [February 19, 2021, 3:18pm UTC](https://forum.plexim.com/t/build-plecs-file-in-python/965/2 "2021-02-19T15:18:10Z")

</div>

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.

```auto
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

```

```auto
server.plecs.codegen(model_name+"/"+subsystem_name)

```
