public static Rhino.Commands.Result EditText(Rhino.RhinoDoc doc) { Rhino.DocObjects.ObjRef objref; Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetOneObject("Select text", false, Rhino.DocObjects.ObjectType.Annotation, out objref); if (rc != Rhino.Commands.Result.Success || objref == null) { return(rc); } Rhino.DocObjects.TextObject textobj = objref.Object() as Rhino.DocObjects.TextObject; if (textobj == null) { return(Rhino.Commands.Result.Failure); } Rhino.Geometry.TextEntity textentity = textobj.Geometry as Rhino.Geometry.TextEntity; if (textentity == null) { return(Rhino.Commands.Result.Failure); } string str = textentity.Text; rc = Rhino.Input.RhinoGet.GetString("New text", false, ref str); if (rc != Rhino.Commands.Result.Success) { return(rc); } textentity.Text = str; textobj.CommitChanges(); doc.Views.Redraw(); return(Rhino.Commands.Result.Success); }
/// <summary> /// Constructor /// </summary> /// <param name="doc">Document used to create the new point</param> public TextViewModel(RhinoDoc doc, Rhino.Geometry.TextEntity textEntity) { _doc = doc; _textEntity = textEntity; _text = textEntity.TextFormula; if (string.IsNullOrWhiteSpace(_text)) _text = textEntity.Text; // Mask type combo box list _maskTypeList.Add(Rhino.UI.LOC.STR("None")); _maskTypeList.Add(Rhino.UI.LOC.STR("Background")); _maskTypeList.Add(Rhino.UI.LOC.STR("Solid Color")); #if ON_OS_WINDOWS ShowMaskColorDialogCommand = new RhinoWindows.Input.DelegateCommand(ShowMaskColorDialog, null); ShowSelectTextFontCommand = new RhinoWindows.Input.DelegateCommand(ShowSelectTextFont, null); ShowTextFieldsFormCommand = new RhinoWindows.Input.DelegateCommand(ShowTextFieldsForm, null); ImportTextFileCommand = new RhinoWindows.Input.DelegateCommand(ImportTextFile, null); #endif }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // Get a startpoint for the text Rhino.Geometry.Point3d startpoint; var rc = Rhino.Input.RhinoGet.GetPoint(Rhino.UI.LOC.STR("Start point"), false, out startpoint); if (rc != Rhino.Commands.Result.Success) return rc; if (m_default_entity == null) { m_default_entity = new Rhino.Geometry.TextEntity(); double val = DefaultTextHeight; if( val>0 ) m_default_entity.TextHeight = val; m_default_entity.FontIndex = doc.Fonts.CurrentIndex; } var plane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane(); plane.Origin = startpoint; m_default_entity.Plane = plane; var test_font = doc.Fonts[m_default_entity.FontIndex]; if (test_font == null) //can happen when a new doc is created and the saved font index is invalid m_default_entity.FontIndex = 0; // View Model to associate with this instance of RunCommand, this // View Model is used by both the scripting and interactive versions // of the command. var model = new TextViewModel(doc, m_default_entity); // Run the scripting or GUI methods to gather data in the View Model. var result = (mode == RunMode.Scripted ? RunScript(model) : RunInteractive(model)); if (result != Result.Success) return result; result = model.AddTextEntityToDocument(); return result; }
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"); } }