public static bool SetView(Rhino_Wrapper rhino_wrapper, String viewName) { int intRes = rhino_wrapper.rhino_app.RunScript("-SetActiveViewport " + viewName, 1); return (intRes == 1); }
public static bool Set_GH_Params(Rhino_Wrapper rhino_wrapper, Dictionary<String, Object> parameters) { log("Starting Set_GH_Params()"); DateTime beforeTime = DateTime.Now; String logLine; int fromStart = (int)((DateTime.Now - beforeTime).TotalMilliseconds); foreach (String paramName in parameters.Keys) { Object value = parameters[paramName]; if (!rhino_wrapper.grasshopper.AssignDataToParameter(paramName, value)) { fromStart = (int)((DateTime.Now - beforeTime).TotalMilliseconds); logLine = "grasshopper.AssignDataToParameter(paramName=" + paramName + ", value=" + value + ") returned false After " + fromStart + " milliseconds"; log(logLine); //return false; } fromStart = (int)((DateTime.Now - beforeTime).TotalMilliseconds); logLine = "After assigning param:" + paramName + " the value=" + value + " After " + fromStart + " milliseconds"; log(logLine); } return true; }
public static bool scaleAll(Rhino_Wrapper rhino_wrapper, double scaleRatio) { RhinoScript4.RhinoScript scripter = rhino_wrapper.rhino_app.GetScriptObject(); scripter.AllObjects(true, false, false); //rhino_wrapper.rhino_app.RunScript("SelAll",1); rhino_wrapper.rhino_app.RunScript("-Scale 0,0,0 " + scaleRatio.ToString(), 1); return true; }
public static bool setDefaultLayer(Rhino_Wrapper rhino_wrapper, string layerName) { String setLayerCommand = "_EZ3DSilentChangeLayerCommand " + layerName; int setLayerCommandRes = rhino_wrapper.rhino_app.RunScript(setLayerCommand, 1); return true; }
public static int count_objects(Rhino_Wrapper rhino_wrapper) { RhinoScript4.RhinoScript scripter = rhino_wrapper.rhino_app.GetScriptObject(); Object[] objs = scripter.AllObjects(); return objs.Length; }
public static bool save_stl(Rhino_Wrapper rhino_wrapper, string filePath) { //String command = "-SaveAs " + filePath + " Enter Enter"; String command = "-SelLayer Default"; rhino_wrapper.rhino_app.RunScript(command, 1); command = "-Export _GeometryOnly=Yes " + filePath; rhino_wrapper.rhino_app.RunScript(command, 1); return true; }
public static bool Run_Script(Rhino_Wrapper rhino_wrapper, String scriptName, Dictionary<String, Object> parameters) { DateTime beforeTime = DateTime.Now; try { String commParams = ""; List<String> stringValues = new List<string>(); foreach (String paramName in parameters.Keys) { Object propValue = parameters[paramName]; Type propValueType = propValue.GetType(); if (propValueType == typeof(Double) || propValueType == typeof(Decimal)) { commParams = commParams + " " + paramName + "=" + parameters[paramName].ToString(); } else if (propValue.GetType() == typeof(String)) { stringValues.Add((String)propValue); } } //String runCommand = "vase1 rad1=0.2 rad2=0.42 rad3=0.6 rad4=0.5 Enter"; String runCommand = scriptName + " " + commParams + " Enter"; foreach (String value in stringValues) { runCommand += " \"" + value + "\" Enter"; } rhino_wrapper.rhino_app.RunScript(runCommand, 1); } catch (Exception e) { log("Exception in Run_Script_And_Render(). e.Message=" + e.Message); return false; } int fromStart = (int)((DateTime.Now - beforeTime).TotalMilliseconds); log("Script ran After " + fromStart + " milliseconds"); return true; }
public static void stam(Rhino_Wrapper rhino_wrapper) { RhinoScript4.RhinoScript scripter = rhino_wrapper.rhino_app.GetScriptObject(); dynamic dyn = scripter.AllObjects(); String[] objStrings = (String[])dyn; //scripter.GetObject( }
public static bool ReduceMesh(Rhino_Wrapper rhino_wrapper, int factor, String reduceBy) { try { DateTime beforeTime = DateTime.Now; String selCommand = "-SelMesh"; int selCommandRes = rhino_wrapper.rhino_app.RunScript(selCommand, 1); String reduceCommand = "-ReduceMesh "; if (reduceBy == Constants.REDUCE_BY_PERCENTAGE) { reduceCommand += "_ReductionPercentage=" + factor.ToString() + " Enter Enter"; } else if (reduceBy == Constants.REDUCE_BY_FACES) { reduceCommand += "_FaceCount=" + factor.ToString() + " Enter Enter"; } else { log("ReduceMesh() failes because reduceBY=" + reduceBy); return false; } int reduceCommandRes = rhino_wrapper.rhino_app.RunScript(reduceCommand, 1); int fromStart = (int)((DateTime.Now - beforeTime).TotalMilliseconds); log("After reducing by: " + reduceCommand+" returned " + reduceCommandRes.ToString() + " After " + fromStart + " milliseconds"); } catch (Exception e) { log("Excpetion in reduceMesh(" +factor.ToString()+ ") , e.Message=" + e.Message); return false; } return true; }
public static bool Render(Rhino_Wrapper rhino_wrapper, Size size, string resultingImagePath) { try { DateTime beforeTime = DateTime.Now; String captureCommand = "-FlamingoRenderTo f " + resultingImagePath + " " + size.Width + " " + size.Height; int captureCommandRes = rhino_wrapper.rhino_app.RunScript(captureCommand, 1); int fromStart = (int)((DateTime.Now - beforeTime).TotalMilliseconds); log("After rendering by: " + captureCommand + " into" + resultingImagePath + " After " + fromStart + " milliseconds"); } catch (Exception e) { log("Excpetion in Render(imageData=" + resultingImagePath + ", String outputPath=" + resultingImagePath + ", e.Message=" + e.Message); return false; } return true; }
public static bool Open_GH_File(Rhino_Wrapper rhino_wrapper, string filePath) { log("Starting Open_GH_File(*,filePath=" + filePath); DateTime before = DateTime.Now; try { FileInfo fif = new FileInfo(filePath); if (!fif.Exists) { log("Open_GH_File() failed because file:" + fif.FullName + " does not exists!!"); } String autoSaveFile = @"C:\Users\Administrator\AppData\Roaming\Grasshopper\AutoSave\" + fif.Name; if (File.Exists(autoSaveFile)) { File.Delete(autoSaveFile); } //rhino_wrapper.grasshopper.CloseAllDocuments(); rhino_wrapper.grasshopper.OpenDocument(filePath); Thread.Sleep(300); } catch (Exception e) { log("Exception=" + e.Message); return false; } log("Finished succefully Open_GH_File(*,filePath=" + filePath + ((int)(DateTime.Now - before).TotalMilliseconds) + " miliseconds after Starting"); return true; }
public static bool Load_STL(Rhino_Wrapper rhino_wrapper, string filePath) { log("Starting Load_STL(*,filePath=" + filePath); DateTime before = DateTime.Now; int tries = 3; while (tries > 0) { tries--; try { if (!File.Exists(filePath)) { Console.WriteLine("ERROR!!: filePath=" + filePath + " does not exists"); return false; } String importCommand = "-Import " + filePath + " Enter"; log(" before runing script line : " + importCommand); int importCommandRes = rhino_wrapper.rhino_app.RunScript(importCommand, 1); log("after runing script line : " + importCommand); rhino_wrapper.rhino_app.RunScript("ChangeToCurrentLayer", 1); log("Finished succefully Load_STL(*,filePath=" + filePath + ((int)(DateTime.Now - before).TotalMilliseconds) + " miliseconds after Starting"); return true; } catch (Exception e) { log("Exception=" + e.Message); Thread.Sleep(1000); continue; } } log("3 tries failed for Load_STL(*,filePath=" + filePath + ((int)(DateTime.Now - before).TotalMilliseconds) + " miliseconds after Starting"); return false; }
public static bool DeleteAll(Rhino_Wrapper rhino_wrapper) { DateTime beforeTime = DateTime.Now; String logLine; int fromStart = (int)((DateTime.Now - beforeTime).TotalMilliseconds); logLine = "Starting DeleteAll()"; log(logLine); // Delete all String deleteAllCommand = "EZ3DDellAllCommand"; int deleteAllCommanddRes = rhino_wrapper.rhino_app.RunScript(deleteAllCommand, 1); fromStart = (int)((DateTime.Now - beforeTime).TotalMilliseconds); logLine = "deleteAllCommanddRes=" + deleteAllCommanddRes + " After " + fromStart + " milliseconds"; log(logLine); return true; }
public static bool Set_GH_Params_To_TXT_File(Rhino_Wrapper rhino_wrapper, Dictionary<String, Object> parameters) { for (int tries = 0; tries < 5; tries++) { try { using (StreamWriter sw = new StreamWriter(UtilsDLL.Dirs.GH_DirPath + Path.DirectorySeparatorChar + "args_" + rhino_wrapper.rhino_pid + ".txt")) { String[] keys = new String[parameters.Count]; parameters.Keys.CopyTo(keys, 0); Array.Sort(keys); for (int i = 0; i < keys.Length; i++) { String key = keys[i]; Object val = parameters[key]; sw.WriteLine(val); } } return true; } catch (Exception e) { log("Exception in Set_GH_Params_To_TXT_File(). e.Message=" + e.Message); } } return false; }
public static bool save_3dm(Rhino_Wrapper rhino_wrapper, string filePath) { String command = "-SaveAs " + filePath; rhino_wrapper.rhino_app.RunScript(command, 1); return true; }
/* public static bool Solve_And_Bake(Rhino_Wrapper rhino_wrapper, String bake) { Object obj1 = rhino_wrapper.grasshopper.RunSolver(true); Object objRes = rhino_wrapper.grasshopper.BakeDataInObject(bake); return true; } */ public static bool Solve_GH(Rhino_Wrapper rhino_wrapper) { Object obj1 = rhino_wrapper.grasshopper.RunSolver(true); return true; }
public static bool Save_GH_File(Rhino_Wrapper rhino_wrapper, string filePath) { log("Starting Save_GH_File(*,filePath=" + filePath); DateTime before = DateTime.Now; try { rhino_wrapper.grasshopper.SaveDocumentAs(filePath); } catch (Exception e) { log("Exception=" + e.Message); return false; } log("Finished succefully Save_GH_File(*,filePath=" + filePath + ((int)(DateTime.Now - before).TotalMilliseconds) + " miliseconds after Starting"); return true; }
/* public static bool Open_3dm_file(Rhino_Wrapper rhino_wrapper, String tdm_filePath) { save_3dm(rhino_wrapper, "C:\\Temp\\stam.3dm"); rhino_wrapper.rhino_app.RunScript("-Open " + tdm_filePath, 1); return true; } */ public static bool Unify_1(Rhino_Wrapper rhino_wrapper) { int res; res = rhino_wrapper.rhino_app.RunScript("SelPolysrf", 1); res = rhino_wrapper.rhino_app.RunScript("BooleanUnion", 1); if (res != 1) return false; if (count_objects(rhino_wrapper) == 1) return true; res = rhino_wrapper.rhino_app.RunScript("SelSrf", 1); res = rhino_wrapper.rhino_app.RunScript("BooleanUnion", 1); if (res != 1) return false; if (count_objects(rhino_wrapper) == 1) return true; res = rhino_wrapper.rhino_app.RunScript("SelPolysrf", 1); res = rhino_wrapper.rhino_app.RunScript("BooleanUnion", 1); if (count_objects(rhino_wrapper) == 1) return true; return false; }
public static bool Bake_GH(Rhino_Wrapper rhino_wrapper, String bake) { Object objRes = rhino_wrapper.grasshopper.BakeDataInObject(bake); return true; }