Skip to content

Commit

Permalink
add paraameters to the openscad
Browse files Browse the repository at this point in the history
  • Loading branch information
madhephaestus committed Nov 2, 2024
1 parent 776ad69 commit 034d5a3
Showing 1 changed file with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.io.IOException;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;

import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.InvalidRemoteException;
Expand All @@ -23,7 +24,15 @@ public class OpenSCADLoader implements IScriptingLanguage {
public Object inlineScriptRun(File code, ArrayList<Object> args) throws Exception {
File stl = File.createTempFile(sanitizeString(code.getName()), ".stl");
stl.deleteOnExit();
toSTLFile(code,stl);
HashMap<String,Double> params=new HashMap<String, Double>();
if(args!=null) {
Object o = args.get(0);
if(HashMap.class.isInstance(o)) {
params=(HashMap<String,Double>)o;
}
}

toSTLFile(code,stl,params);
CSG back = Vitamins.get(stl,true);
back.setColor(Color.YELLOW);
return back;
Expand Down Expand Up @@ -51,22 +60,27 @@ public ArrayList<String> getFileExtenetion() {



public static void toSTLFile(File openscadfile,File stlout) throws InvalidRemoteException, TransportException, GitAPIException, IOException, InterruptedException {
public static void toSTLFile(File openscadfile,File stlout, HashMap<String,Double> params) throws InvalidRemoteException, TransportException, GitAPIException, IOException, InterruptedException {
File exe = getConfigExecutable("openscad", null);

if(params==null)
params=new HashMap<String, Double>();
ArrayList<String> args = new ArrayList<>();

if(stlout.exists())
stlout.delete();
args.add(exe.getAbsolutePath());
for(String key:params.keySet()) {
args.add("-D");
args.add(key+"="+params.get(key));
}
args.add("-o");
args.add(stlout.getAbsolutePath());
args.add(openscadfile.getAbsolutePath());
legacySystemRun(null, stlout.getAbsoluteFile().getParentFile(), System.out, args);
}
@Override
public String getDefaultContents() {
return "cube([3, 2, 1]);";
return "cube([30, 20, 10]);";
}

@Override
Expand All @@ -81,7 +95,8 @@ public static void main(String[] args) throws InvalidRemoteException, TransportE
File testblend = new File("test.scad");
if(!testblend.exists())
loader.getDefaultContents(testblend);
toSTLFile(testblend, new File("testscad.stl"));
HashMap<String,Double> params = new HashMap<String, Double>();
toSTLFile(testblend, new File("testscad.stl"),params);
}

}

0 comments on commit 034d5a3

Please sign in to comment.