How to create a module with Mendix SDK

0
Hello,  I want to create a script that generates a module. How can I do this? I've tried following the instructions at https://docs.mendix.com/apidocs-mxsdk/mxsdk/generating-code-from-the-model  but I wasn't able to print the module to the console, or even the project.   
asked
1 answers
5

Hi Daniel

You can create an module using the following code:

// create your working copy and then...

const model = workingCopy.model();
const modelProject : projects.IProject = model.allProjects()[0];
const module = projects.Module.createIn(modelProject);
const moduleSecurity = security.ModuleSecurity.createIn(module);
const domainModel = domainmodels.DomainModel.createIn(module);

If you want to add module roles:

const moduleRole = security.ModuleRole.createIn(moduleSecurity);
moduleRole.name = "Administrator";

If you want to add an entity into your domain model:

const entity = domainmodels.Entity.createIn(domainModel);
entity.name = "MyNewEntity";
entity.location = { 50, 50 }; 

Adding a string attribute to your entity:

const type = domainmodels.StringAttributeType.create(model);
type.length = 200;

const value = domainmodels.StoredValue.create(model);
value.defaultValue = "Hello!";

const attribute = domainmodels.Attribute.create(model);
attribute.name = "MyStringAttribute";
attribute.type = type;
attribute.value = value;
        
entity.attributes.push(attribute);

Hope that helps to get your on your way!

Cheers

iain

answered