modelcreate / model-view

Model View - Share and view models in the browser
https://view.modelcreate.com
GNU Affero General Public License v3.0
21 stars 11 forks source link

How to save model as inp file #54

Closed anniemark271983 closed 1 year ago

anniemark271983 commented 1 year ago

import {Project, Workspace} from 'epanet-js'

const ws = new Workspace(); const model = new Project(ws);

model.init('report.rpt', 'out.bin', 0, 0);

const n1Index = model.addNode('N1', NodeType.Junction); const n2Index = model.addNode('N2', NodeType.Junction); model.setJunctionData(n1Index, 700, 0, ''); model.setJunctionData(n2Index, 400, 0, '');

const l1Index = model.addLink('L1',LinkType.Pipe,'N1','N2')

This code is ok but how can i save model as inp file can you please help me on this

lbutler commented 1 year ago

You need to use the saveInpFile method which will save the INP to the virtual drive/workspace.

You can then extract the INP as a string and save it to your computer if you're using something like node.

model.saveInpFile('newModel.inp')
const inp = ws.readFile('newModel.inp', 'utf8')
console.log(inp)

Assuming you're using Node, you can then use fs.writeFile

https://epanetjs.com/api/project-functions/project/#saveinpfile https://epanetjs.com/api/workspace/