How to create a module with Mendix SDK

Hello,  I want to create a script that generates a module. How can I do this? I've tried following the instructions at  but I wasn't able to print the module to the console, or even the project.   
1 answers

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); = "Administrator";

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

const entity = domainmodels.Entity.createIn(domainModel); = "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); = "MyStringAttribute";
attribute.type = type;
attribute.value = value;

Hope that helps to get your on your way!