//On RhinoDoc.Idle, push previously recorded changes in selection to Illustrator. //Clear all S series .nata files when Illustrator finishes. public static void selectionToIllustrator(int state) { //Reset S00 so that RhinoApp.Idle doesn't repeat this process. string statePath = utils.file_structure.getPathFor("S00"); System.IO.File.WriteAllText(statePath, "0"); //int state = Convert.ToInt32(System.IO.File.ReadAllText(statePath)); //Debug util: record state currently being passed as an argument. string stateDebugPath = utils.file_structure.getPathFor("x00"); File.WriteAllText(stateDebugPath, "Current selection delta state: " + state.ToString()); //Determine filepath for illustrator extendscript processes. string jsxPath = utils.file_structure.getJavascriptPath(); //Determine current document runtime to send to interop. string runtime = utils.file_structure.getDocRuntime(); //Generate copies of current data that Illustrator will read. string S10_Path = utils.file_structure.getPathFor("S10"); string S20_Path = utils.file_structure.getPathFor("S20"); if (File.Exists(S10_Path) == false) { File.WriteAllText(S10_Path, "empty"); } else if (File.Exists(S10_Path) == true && File.ReadAllText(S10_Path) == "") { File.WriteAllText(S10_Path, "empty"); } if (File.Exists(S20_Path) == false) { File.WriteAllText(S20_Path, "empty"); } else if (File.Exists(S20_Path) == true && File.ReadAllText(S20_Path) == "") { File.WriteAllText(S20_Path, "empty"); } string S11_Path = utils.file_structure.getPathFor("S11"); string S21_Path = utils.file_structure.getPathFor("S21"); File.WriteAllText(S11_Path, File.ReadAllText(S10_Path)); File.WriteAllText(S21_Path, File.ReadAllText(S20_Path)); string nataPath = utils.file_structure.getNataPath(); int conversion = utils.units.conversion(); //Clear original .nata file data. clearSelectionNata(); //Tell illustrator to run selection update script, based on state. echo.interop echo = new echo.interop(); echo.selection(state, jsxPath, runtime, nataPath, conversion); }
//Update geometry in illustrator. public static void geometryToIllustrator(int state) { //Reset G00 so that RhinoApp.Idle doesn't repeat this process. string statePath = utils.file_structure.getPathFor("G00"); System.IO.File.WriteAllText(statePath, "0"); //Debug util: record previous state. string debugPath = utils.file_structure.getPathFor("x20"); System.IO.File.WriteAllText(debugPath, "Previous delta state: " + state.ToString()); //Determine filepath for illustrator extendscript processes. string jsxPath = utils.file_structure.getJavascriptPath(); string nataPath = utils.file_structure.getNataPath(); //Determine current document runtime to send to interop. string runtime = utils.file_structure.getDocRuntime(); //Generate copies of current data that Illustrator will read. string G10_Path = utils.file_structure.getPathFor("G10"); string G20_Path = utils.file_structure.getPathFor("G20"); if (File.Exists(G10_Path) == false) { //System.Threading.Thread.Sleep(500); //Weird things happening with initial file creation... File.WriteAllText(G10_Path, "empty"); } else if (File.Exists(G10_Path) == true && File.ReadAllText(G10_Path) == "") { File.WriteAllText(G10_Path, "empty"); } if (File.Exists(G20_Path) == false) { File.WriteAllText(G20_Path, "empty"); } else if (File.Exists(G20_Path) == true && File.ReadAllText(G20_Path) == "") { File.WriteAllText(G20_Path, "empty"); } string G11_Path = utils.file_structure.getPathFor("G11"); string G21_Path = utils.file_structure.getPathFor("G21"); File.WriteAllText(G11_Path, File.ReadAllText(G10_Path)); File.WriteAllText(G21_Path, File.ReadAllText(G20_Path)); int conversion = utils.units.conversion(); //Clear original .nata file data. clearGeometryNata(); //Tell illustrator to run geometry update script, based on state. echo.interop echo = new echo.interop(); echo.geometry(state, jsxPath, runtime, nataPath, conversion); }
//Update illustrator doc bound if docbox changes in rhino. public static void docBoxChanges(Rhino.DocObjects.RhinoObject docBox) { //Parse rectangle from incoming RhinoObject. Guid incomingGuid = docBox.Id; Rhino.Geometry.Curve newCurve = null; Rhino.DocObjects.ObjRef oRef = new Rhino.DocObjects.ObjRef(incomingGuid); newCurve = oRef.Curve(); Rhino.Geometry.BoundingBox newDimsBox = newCurve.GetBoundingBox(false); Rhino.Geometry.Point3d newMinPoint = newDimsBox.Min; Rhino.Geometry.Point3d newMaxPoint = newDimsBox.Max; double newWidth = newMaxPoint.X - newMinPoint.X; double newHeight = newMaxPoint.Y - newMinPoint.Y; int conversion = utils.units.conversion(); //Compare previous size, or record if first run. string D01_Path = utils.file_structure.getPathFor("D01"); string jsxPath = utils.file_structure.getJavascriptPath(); if (System.IO.File.Exists(D01_Path) == false) { string newData = newWidth.ToString() + "|" + newHeight.ToString(); System.IO.File.WriteAllText(D01_Path, newData); } else if (System.IO.File.Exists(D01_Path) == true) { //If file exists, verify bounds changed. (Otherwise, box moved.) string[] oldData = System.IO.File.ReadAllText(D01_Path).Split('|'); double oldWidth = Convert.ToDouble(oldData[0]); double oldHeight = Convert.ToDouble(oldData[1]); //utils.debug.ping(0, "Width change: " + newWidth.ToString() + " - " + oldWidth.ToString()); if (oldWidth == newWidth && oldHeight == newHeight) { //outbound.push.fullReset(); } else { string newData = newWidth.ToString() + "|" + newHeight.ToString(); System.IO.File.WriteAllText(D01_Path, newData); echo.interop echo = new echo.interop(); echo.docBounds(newWidth, newHeight, conversion, jsxPath); //outbound.push.fullReset(); } } }
//Streamlined deselection process triggered on a full deselection or object deletion. public static int selectionReset() { //Set state file S00 to 3: selection reset. string statePath = utils.file_structure.getPathFor("S00"); System.IO.File.WriteAllText(statePath, "3"); string jsxPath = utils.file_structure.getJavascriptPath(); string runtime = utils.file_structure.getDocRuntime(); string nataPath = utils.file_structure.getNataPath(); int conversion = utils.units.conversion(); echo.interop echo = new echo.interop(); echo.selection(3, jsxPath, runtime, nataPath, conversion); return(2); }
public static void alert(string message) { echo.interop echo = new echo.interop(); echo.alert(message); }
public static void ping(int val, string message) { echo.interop echo = new echo.interop(); echo.locate(val, message); }
public static string makeDocBox() { try { //If docBox has not been created, create it and place it on its natalus layer. /* Abandoning layer idea for now. Not working as intended. * Rhino.DocObjects.Layer layer_D10 = new Rhino.DocObjects.Layer(); * int layer_D10_index = -1; * * if (RhinoDoc.ActiveDoc.Layers.FindName("D10").Index < 0) * { * RhinoDoc.ActiveDoc.Layers.Add(layer_D10); * layer_D10_index = layer_D10.Index; * } * else * { * layer_D10 = RhinoDoc.ActiveDoc.Layers.FindName("D10"); * layer_D10_index = layer_D10.Index; * } */ //Set initial dimensions and record to D01 if D01 does not exist. string D01_Path = utils.file_structure.getPathFor("D01"); string D20_Path = utils.file_structure.getPathFor("D20"); double docBox_width = 12; double docBox_height = 12; Rhino.Geometry.Point3d refPoint = new Rhino.Geometry.Point3d(0, 0, 0); //Check if previous dim configuration existed. if (System.IO.File.Exists(D01_Path) == true) { string[] dims = System.IO.File.ReadAllText(D01_Path).Split('|'); docBox_width = Convert.ToDouble(dims[0]); docBox_height = Convert.ToDouble(dims[1]); } else { System.IO.File.WriteAllText(D01_Path, "12|12"); } double adjust = 0; if (System.IO.File.Exists(D20_Path) == true) { string[] coords = System.IO.File.ReadAllText(D20_Path).Split(','); refPoint.X = Convert.ToDouble(coords[0]); refPoint.Y = Convert.ToDouble(coords[1]); adjust = docBox_height; } else if (System.IO.File.Exists(D20_Path) == false) { adjust = 0; } Rhino.Geometry.Plane docBox_plane = Rhino.Geometry.Plane.WorldXY; docBox_plane.OriginX = refPoint.X; docBox_plane.OriginY = refPoint.Y - adjust; Rhino.Geometry.Rectangle3d docBox = new Rhino.Geometry.Rectangle3d(docBox_plane, docBox_width, docBox_height); Rhino.DocObjects.ObjectAttributes docBox_attributes = new Rhino.DocObjects.ObjectAttributes(); //Until layer process resolved, docBox to be on any layer. int activeIndex = RhinoDoc.ActiveDoc.Layers.CurrentLayerIndex; docBox_attributes.LayerIndex = activeIndex; //(Rhino 5) Convert docBox Rectangle3D to polyline curve. Rhino.Geometry.Polyline docBoxPolyline = docBox.ToPolyline(); //Freeze updating while docBox is created. string x10_path = utils.file_structure.getPathFor("x10"); System.IO.File.WriteAllText(x10_path, "false"); //Determine GUID and record to D10. Guid newGuid = RhinoDoc.ActiveDoc.Objects.AddPolyline(docBoxPolyline); Rhino.DocObjects.ObjRef docBoxObj = new Rhino.DocObjects.ObjRef(newGuid); Rhino.DocObjects.CurveObject docBoxCurve = docBoxObj.Object() as Rhino.DocObjects.CurveObject; string docBoxGUID = newGuid.ToString(); string D10_Path = utils.file_structure.getPathFor("D10"); if (System.IO.File.Exists(D10_Path) && System.IO.File.ReadAllText(D10_Path) != "") { string D11_Path = utils.file_structure.getPathFor("D11"); System.IO.File.WriteAllText(D11_Path, System.IO.File.ReadAllText(D10_Path)); } System.IO.File.WriteAllText(D10_Path, docBoxGUID); //Set curve to Illustrator orange. System.Drawing.Color docBoxColor = System.Drawing.Color.FromArgb(240, 120, 6); docBoxCurve.Attributes.ColorSource = Rhino.DocObjects.ObjectColorSource.ColorFromObject; docBoxCurve.Attributes.ObjectColor = docBoxColor; docBoxCurve.Attributes.PlotColorSource = Rhino.DocObjects.ObjectPlotColorSource.PlotColorFromObject; docBoxCurve.Attributes.PlotColor = docBoxColor; docBoxCurve.Attributes.PlotWeightSource = Rhino.DocObjects.ObjectPlotWeightSource.PlotWeightFromObject; docBoxCurve.Attributes.PlotWeight = 1.5; docBoxCurve.CommitChanges(); //Label it! Rhino.Geometry.TextEntity label = new Rhino.Geometry.TextEntity(); label.TextHeight = .4; Rhino.Geometry.Plane label_plane = Rhino.Geometry.Plane.WorldXY; label_plane.OriginX = docBox_plane.OriginX; label_plane.OriginY = docBox_plane.OriginY - .4 - .1; label.Plane = label_plane; label.Text = ("Linked Illustrator Artboard"); Guid docBoxLabel = RhinoDoc.ActiveDoc.Objects.AddText(label); Rhino.DocObjects.ObjRef labelObj = new Rhino.DocObjects.ObjRef(docBoxLabel); Rhino.DocObjects.TextObject labelText = labelObj.Object() as Rhino.DocObjects.TextObject; labelText.Attributes.ColorSource = Rhino.DocObjects.ObjectColorSource.ColorFromObject; labelText.Attributes.ObjectColor = docBoxColor; labelText.Attributes.PlotColorSource = Rhino.DocObjects.ObjectPlotColorSource.PlotColorFromObject; labelText.Attributes.PlotColor = docBoxColor; labelText.CommitChanges(); string docBoxLabelGUID = docBoxLabel.ToString(); string D30_Path = utils.file_structure.getPathFor("D30"); if (System.IO.File.Exists(D30_Path) && System.IO.File.ReadAllText(D30_Path) != "") { string D31_Path = utils.file_structure.getPathFor("D31"); System.IO.File.WriteAllText(D31_Path, System.IO.File.ReadAllText(D30_Path)); } System.IO.File.WriteAllText(D30_Path, docBoxLabelGUID); //Unfreeze updating. System.IO.File.WriteAllText(x10_path, "true"); //Update illustrator boundaries. int conversion = utils.units.conversion(); string jsxPath = utils.file_structure.getJavascriptPath(); echo.interop echo = new echo.interop(); echo.docBounds(docBox_width, System.Math.Abs(docBox_height), conversion, jsxPath); return(docBoxGUID); } catch (Exception e) { debug.alert(e.Message + " | " + e.Source); return("error"); } }