donalffons / opencascade.js

Port of the OpenCascade CAD library to JavaScript and WebAssembly via Emscripten.
https://ocjs.org/
GNU Lesser General Public License v2.1
617 stars 88 forks source link

How to access data from .write() #222

Open stefanFuess opened 1 year ago

stefanFuess commented 1 year ago

I'm trying to access my data from my exported step file.

var writer = new openCascade.STEPControl_Writer_1(); var progressRange = new openCascade.Message_ProgressRange_1(); writer.Transfer(reader.OneShape(), openCascade.STEPControl_StepModelType.STEPControl_AsIs, true, progressRange); writer.Write("test.step")

no errors are thrown, but I dont know how to access the data now.

How to write my step file?

FANZHUJIONG commented 1 year ago

We also have problem like this. We use opencascade.js to write BREP. Now the question is : though BRepTools.Write_3 return "true", we don't know whether the file "a.brep" is created or not, since we didn't find "a.brep" in the specified file path. The code is below:

var shape = createSquare(this.openCascade, 10, 10, 10, 360, 1);
var brepStr = "a.brep";
var theProgress = new this.openCascade.Message_ProgressRange_1();
var result = this.openCascade.BRepTools.Write_3(shape,brepStr,theProgress)
console.log(result)

We don't know how to write brep file.

FANZHUJIONG commented 1 year ago

We found solution. Maybe js doesn't offer methods to write file to disk, and the file that occ.js created is storaged in occ.js buffer or something else, so we can't find file in our disk. But we can read the file and get the String like below:

var theProgress = new this.openCascade.Message_ProgressRange_1();
var result = this.openCascade.BRepTools.Write_3(shape,"test",theProgress)
let brep = this.openCascade.FS.readFile("/" + "test", { encoding:"utf8" });
this.openCascade.FS.unlink("/" + "test");
console.log(result)
console.log(brep)

Also, when you send a absolute path to BRepTools.Write_3(), it will return false, since js may not write file to you disk path.