/// <summary> RunCommandPickPlane is a helper method for picking an existing surface to draw on </summary> /// <param name="mRhinoDoc"></param> /// <param name="mode"></param> /// <returns></returns> protected Result RunCommandPickPlane(RhinoDoc mRhinoDoc, RunMode mode) { //routine for picking an existing surface to draw on //please select a plane Rhino.DocObjects.ObjectType filter = Rhino.DocObjects.ObjectType.Surface; Rhino.DocObjects.ObjRef objref = null; Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetOneObject("Select surface", false, filter, out objref); if (rc != Rhino.Commands.Result.Success || objref == null) { return(rc); } Rhino.Geometry.Surface refSrf = objref.Surface(); refSrf.FrameAt(.5, .5, out plane1); Point3d pOrigin = refSrf.PointAt(1, 1); Point3d pY = refSrf.PointAt(0.5, 1); Point3d pX = refSrf.PointAt(1, 0.75); Vector3d vX = Rhino.Geometry.Point3d.Subtract(pX, pOrigin); Vector3d vY = Rhino.Geometry.Point3d.Subtract(pY, pOrigin); plane1 = new Plane(pOrigin, vX, vY); Rhino.DocObjects.RhinoObject rhobj = objref.Object(); rhobj.Select(false); mRhinoDoc.Objects.AddPoint(pOrigin); mRhinoDoc.Objects.AddPoint(pX); mRhinoDoc.Objects.AddPoint(pY); mRhinoDoc.Views.Redraw(); return(Result.Success); }
public static Rhino.Commands.Result DupBorder(Rhino.RhinoDoc doc) { const ObjectType filter = Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.PolysrfFilter; Rhino.DocObjects.ObjRef objref; Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetOneObject("Select surface or polysurface", false, filter, out objref); if (rc != Rhino.Commands.Result.Success || objref == null) { return(rc); } Rhino.DocObjects.RhinoObject rhobj = objref.Object(); Rhino.Geometry.Brep brep = objref.Brep(); if (rhobj == null || brep == null) { return(Rhino.Commands.Result.Failure); } rhobj.Select(false); Rhino.Geometry.Curve[] curves = brep.DuplicateEdgeCurves(true); double tol = doc.ModelAbsoluteTolerance * 2.1; curves = Rhino.Geometry.Curve.JoinCurves(curves, tol); for (int i = 0; i < curves.Length; i++) { Guid id = doc.Objects.AddCurve(curves[i]); doc.Objects.Select(id); } doc.Views.Redraw(); return(Rhino.Commands.Result.Success); }
protected override void UpdateVertexColors(Rhino.DocObjects.RhinoObject obj, Mesh[] meshes) { // A "mapping tag" is used to determine if the colors need to be set Rhino.Render.MappingTag mt = GetMappingTag(obj.RuntimeSerialNumber); for (int mi = 0; mi < meshes.Length; mi++) { var mesh = meshes[mi]; if (mesh.VertexColors.Tag.Id != this.Id) { // The mesh's mapping tag is different from ours. Either the mesh has // no false colors, has false colors set by another analysis mode, has // false colors set using different m_z_range[]/m_hue_range[] values, or // the mesh has been moved. In any case, we need to set the false // colors to the ones we want. System.Drawing.Color[] colors = new System.Drawing.Color[mesh.Vertices.Count]; for (int i = 0; i < mesh.Vertices.Count; i++) { double z = mesh.Vertices[i].Z; colors[i] = FalseColor(z); } mesh.VertexColors.SetColors(colors); // set the mesh's color tag mesh.VertexColors.Tag = mt; } } }
public override bool ObjectSupportsAnalysisMode(Rhino.DocObjects.RhinoObject obj) { if (obj is Rhino.DocObjects.MeshObject || obj is Rhino.DocObjects.BrepObject) { return(true); } return(false); }
private bool CircleWithRadiusOf10GeometryFilter(Rhino.DocObjects.RhinoObject rhObject, GeometryBase geometry, ComponentIndex componentIndex) { bool is_circle_with_radius_of10 = false; Circle circle; if (geometry is Curve && (geometry as Curve).TryGetCircle(out circle)) { is_circle_with_radius_of10 = circle.Radius <= 10.0 + m_tolerance && circle.Radius >= 10.0 - m_tolerance; } return(is_circle_with_radius_of10); }
internal override IntPtr _InternalGetConstPointer() { if (null != m_shallow_parent) { return(m_shallow_parent.ConstPointer()); } #if RHINO_SDK Rhino.DocObjects.ObjRef obj_ref = m__parent as Rhino.DocObjects.ObjRef; if (null != obj_ref) { return(obj_ref.GetGeometryConstPointer(this)); } Rhino.DocObjects.RhinoObject parent_object = ParentRhinoObject(); if (parent_object == null) { Rhino.FileIO.File3dmObject fileobject = m__parent as Rhino.FileIO.File3dmObject; if (null != fileobject) { return(fileobject.GetGeometryConstPointer()); } } uint serial_number = 0; IntPtr pParentRhinoObject = IntPtr.Zero; if (null != parent_object) { serial_number = parent_object.m_rhinoobject_serial_number; pParentRhinoObject = parent_object.m_pRhinoObject; } ComponentIndex ci = new ComponentIndex(); // There are a few cases (like in ReplaceObject callback) where the parent // rhino object temporarily holds onto the CRhinoObject* because the object // is not officially in the document yet. if (pParentRhinoObject != IntPtr.Zero) { return(UnsafeNativeMethods.CRhinoObject_Geometry(pParentRhinoObject, ci)); } return(UnsafeNativeMethods.CRhinoObject_Geometry2(serial_number, ci)); #else Rhino.FileIO.File3dmObject fileobject = m__parent as Rhino.FileIO.File3dmObject; if (null != fileobject) { return(fileobject.GetGeometryConstPointer()); } return(IntPtr.Zero); #endif }
public void ImplicitSelectionDecrease(object sender, RhinoObjectEventArgs ea, bool sendBool) { sendBool = utils.properties.getSelPushState(); if (sendBool == false) { //Do nothing. } else if (sendBool == true) { Rhino.DocObjects.RhinoObject[] newObj = new Rhino.DocObjects.RhinoObject[1]; newObj[0] = ea.TheObject; outbound.push.selectionDecrease(newObj); } }
/// <summary> /// Delegate function used to turn custom grips on /// </summary> public void TurnOnGrips(RhinoObject rhObject) { if (rhObject == null) return; var polyline_curve = rhObject.Geometry as PolylineCurve; if (polyline_curve == null) return; if (!SampleCsRectangleHelper.IsRectangle(polyline_curve)) return; var rectangle_grips = new SampleCsRectangleGrips(); if (!rectangle_grips.CreateGrips(polyline_curve)) return; rhObject.EnableCustomGrips(rectangle_grips); }
private RenderMaterial GetObjectMaterial(Rhino.DocObjects.RhinoObject rhinoObject) { ObjectMaterialSource source = rhinoObject.Attributes.MaterialSource; Rhino.Render.RenderMaterial renderMaterial = null; if (source == ObjectMaterialSource.MaterialFromObject) { renderMaterial = rhinoObject.RenderMaterial; } else if (source == ObjectMaterialSource.MaterialFromLayer) { int layerIndex = rhinoObject.Attributes.LayerIndex; renderMaterial = GetLayerMaterial(layerIndex); } return(renderMaterial); }
static void RhinoUpdateObjectGroups(ref RhinoObject obj, ref Dictionary<int, int> group_map) { if (obj == null) return; int attrib_group_count = obj.Attributes.GroupCount; if (attrib_group_count == 0) return; var doc = obj.Document; if (doc == null) return; var groups = doc.Groups; int group_count = groups.Count; if (group_count == 0) return; if (group_map.Count == 0) for (int i = 0; i < group_count; i++) group_map.Add(i, -1); var attributes = obj.Attributes; var group_list = attributes.GetGroupList(); if (group_list == null) return; attrib_group_count = group_list.Length; for (int i = 0; i < attrib_group_count; i++) { int old_group_index = group_list[i]; int new_group_index = group_map[old_group_index]; if (new_group_index == -1) { new_group_index = doc.Groups.Add(); group_map[old_group_index] = new_group_index; } group_list[i] = new_group_index; } attributes.RemoveFromAllGroups(); for (int i = 0; i < attrib_group_count; i++) attributes.AddToGroup(group_list[i]); obj.CommitChanges(); }
/// <summary> /// Aligned Boundingbox solver. Gets the world axis aligned boundingbox for the transformed geometry. /// </summary> /// <param name="xform">Transformation to apply to object prior to the BoundingBox computation. /// The geometry itself is not modified.</param> /// <returns>The accurate boundingbox of the transformed geometry in world coordinates /// or BoundingBox.Empty if not bounding box could be found.</returns> public BoundingBox GetBoundingBox(Transform xform) { BoundingBox bbox = BoundingBox.Empty; #if RHINO_SDK // In cases like breps and curves, the CRhinoBrepObject and CRhinoCurveObject // can compute a better tight bounding box Rhino.DocObjects.RhinoObject parent_object = ParentRhinoObject(); if (parent_object != null) { IntPtr pParent = parent_object.ConstPointer(); if (UnsafeNativeMethods.CRhinoObject_GetTightBoundingBox(pParent, ref bbox, ref xform, true)) { return(bbox); } } #endif IntPtr ptr = ConstPointer(); return(UnsafeNativeMethods.ON_Geometry_GetTightBoundingBox(ptr, ref bbox, ref xform, true) ? bbox : BoundingBox.Empty); }
public override void InitializeControls(RhinoObject rhObj) { var rc = false; m_control.ClearRadius(); var circle = new Circle(); if (null != rhObj) { rc = GetCircle(rhObj, ref circle); if (rc) m_control.Radius = circle.Radius; } else { var radius = Rhino.RhinoMath.UnsetValue; var varies = false; foreach (var rh_obj in SelectedObjects) { if (GetCircle(rh_obj, ref circle)) { if (Rhino.RhinoMath.IsValidDouble(radius)) { if (System.Math.Abs(radius - circle.Radius) > Rhino.RhinoMath.SqrtEpsilon) { radius = Rhino.RhinoMath.UnsetValue; varies = true; break; } } else { radius = circle.Radius; } } } if (!varies && Rhino.RhinoMath.IsValidDouble(radius)) { m_control.Radius = radius; } } }
/// <summary> /// Boundingbox solver. Gets the world axis aligned boundingbox for the geometry. /// </summary> /// <param name="accurate">If true, a physically accurate boundingbox will be computed. /// If not, a boundingbox estimate will be computed. For some geometry types there is no /// difference between the estimate and the accurate boundingbox. Estimated boundingboxes /// can be computed much (much) faster than accurate (or "tight") bounding boxes. /// Estimated bounding boxes are always similar to or larger than accurate bounding boxes.</param> /// <returns> /// The boundingbox of the geometry in world coordinates or BoundingBox.Empty /// if not bounding box could be found. /// </returns> /// <example> /// <code source='examples\vbnet\ex_curveboundingbox.vb' lang='vbnet'/> /// <code source='examples\cs\ex_curveboundingbox.cs' lang='cs'/> /// <code source='examples\py\ex_curveboundingbox.py' lang='py'/> /// </example> public BoundingBox GetBoundingBox(bool accurate) { #if RHINO_SDK Rhino.DocObjects.RhinoObject parent_object = ParentRhinoObject(); #endif if (accurate) { BoundingBox bbox = new BoundingBox(); Transform xf = new Transform(); #if RHINO_SDK if (null != parent_object) { IntPtr pParentObject = parent_object.ConstPointer(); if (UnsafeNativeMethods.CRhinoObject_GetTightBoundingBox(pParentObject, ref bbox, ref xf, false)) { return(bbox); } } #endif IntPtr ptr = ConstPointer(); return(UnsafeNativeMethods.ON_Geometry_GetTightBoundingBox(ptr, ref bbox, ref xf, false) ? bbox : BoundingBox.Empty); } else { BoundingBox rc = new BoundingBox(); #if RHINO_SDK if (null != parent_object) { IntPtr pParentObject = parent_object.ConstPointer(); if (UnsafeNativeMethods.CRhinoObject_BoundingBox(pParentObject, ref rc)) { return(rc); } } #endif IntPtr ptr = ConstPointer(); UnsafeNativeMethods.ON_Geometry_BoundingBox(ptr, ref rc); return(rc); } }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // TODO: complete command. MyRhino5rs11project8PlugIn p = MyRhino5rs11project8PlugIn.Instance; if (p.if_painted_object_set_ == false) { RhinoApp.WriteLine("No mesh"); return(Result.Failure); } Mesh my_mesh = p.painted_object_; DijkstraGraph my_graph = p.graph; GetObject gbrep1 = new GetObject(); gbrep1.SetCommandPrompt("get the brep"); gbrep1.GeometryFilter = Rhino.DocObjects.ObjectType.Brep; gbrep1.SubObjectSelect = false; gbrep1.Get(); if (gbrep1.CommandResult() != Rhino.Commands.Result.Success) { return(gbrep1.CommandResult()); } Rhino.DocObjects.ObjRef my_objref1 = gbrep1.Object(0); Rhino.DocObjects.RhinoObject my_obj1 = my_objref1.Object(); if (my_obj1 == null) { return(Rhino.Commands.Result.Failure); } Brep brep1 = my_objref1.Brep(); if (brep1 == null) { return(Result.Failure); } my_obj1.Select(false); for (int i = 0; i < p.my_objects_list.Count; i++) { Guid brep1_id = My_object_functions.GetComponentID(brep1); Guid my_object_id = My_object_functions.GetComponentID(p.my_objects_list[i]); if (brep1_id == my_object_id) { p.my_objects_list.RemoveAt(i); } } IEnumerable <RhinoObject> path_objref = doc.Objects.GetObjectList(ObjectType.Curve); foreach (RhinoObject path in path_objref) { doc.Objects.Delete(path, true); } List <NurbsCurve> new_path_list = new List <NurbsCurve>(); int pin_number = My_object_functions.GetPinQuantity(brep1); for (int i = 0; i < pin_number; i++) { Guid pin_id = My_object_functions.GetPinGuid(brep1, i); new_path_list = p.graph.DijkstraPath_DeletePin(pin_id); } ObjectAttributes my_attributes = new ObjectAttributes(); my_attributes.ObjectColor = Color.Yellow; my_attributes.ColorSource = ObjectColorSource.ColorFromObject; my_attributes.PlotWeightSource = ObjectPlotWeightSource.PlotWeightFromObject; my_attributes.PlotWeight = 2.0; doc.Objects.Delete(my_objref1, true); for (int i = 0; i < new_path_list.Count; i++) { Guid path_id = new_path_list[i].UserDictionary.GetGuid("PathID"); my_attributes.ObjectId = path_id; doc.Objects.Add(new_path_list[i], my_attributes); } doc.Views.Redraw(); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // TODO: complete command. MyRhino5rs11project8PlugIn p = MyRhino5rs11project8PlugIn.Instance; if (p.if_painted_object_set_ == false) { RhinoApp.WriteLine("No mesh"); return(Result.Failure); } Mesh my_mesh = p.painted_object_; DijkstraGraph my_graph = p.graph; GetObject gbrep1 = new GetObject(); gbrep1.SetCommandPrompt("get the brep"); gbrep1.GeometryFilter = Rhino.DocObjects.ObjectType.Brep; gbrep1.SubObjectSelect = false; gbrep1.Get(); if (gbrep1.CommandResult() != Rhino.Commands.Result.Success) { return(gbrep1.CommandResult()); } Rhino.DocObjects.ObjRef my_objref1 = gbrep1.Object(0); Rhino.DocObjects.RhinoObject my_obj1 = my_objref1.Object(); if (my_obj1 == null) { return(Rhino.Commands.Result.Failure); } Brep brep1 = my_objref1.Brep(); if (brep1 == null) { return(Result.Failure); } my_obj1.Select(false); GetObject gbrep2 = new GetObject(); gbrep2.SetCommandPrompt("get the brep"); gbrep2.GeometryFilter = Rhino.DocObjects.ObjectType.Brep; gbrep2.SubObjectSelect = false; gbrep2.Get(); if (gbrep2.CommandResult() != Rhino.Commands.Result.Success) { return(gbrep2.CommandResult()); } Rhino.DocObjects.ObjRef my_objref2 = gbrep2.Object(0); Rhino.DocObjects.RhinoObject my_obj2 = my_objref2.Object(); if (my_obj2 == null) { return(Rhino.Commands.Result.Failure); } Brep brep2 = my_objref2.Brep(); if (brep2 == null) { return(Result.Failure); } my_obj2.Select(false); Point3d pin_1_position = brep1.UserDictionary.GetPoint3d("CurrentPosition"); Point3d pin_2_position = brep2.UserDictionary.GetPoint3d("CurrentPosition"); Guid pin_1_id = brep1.UserDictionary.GetGuid("PinID"); Guid pin_2_id = brep2.UserDictionary.GetGuid("PinID"); MeshPoint pin_1_meshpoint = my_mesh.ClosestMeshPoint(pin_1_position, 0); MeshPoint pin_2_meshpoint = my_mesh.ClosestMeshPoint(pin_2_position, 0); Stopwatch watch = new Stopwatch(); watch.Start(); NurbsCurve d_path = my_graph.DijkstraPath_Add(pin_1_meshpoint, pin_1_id, pin_2_meshpoint, pin_2_id); watch.Stop(); if (d_path == null) { return(Result.Success); } RhinoApp.WriteLine("link time: {0}", watch.Elapsed); ObjectAttributes my_attributes = new ObjectAttributes(); my_attributes.ObjectColor = Color.Yellow; my_attributes.ColorSource = ObjectColorSource.ColorFromObject; my_attributes.PlotWeightSource = ObjectPlotWeightSource.PlotWeightFromObject; my_attributes.PlotWeight = 2.0; doc.Objects.AddCurve(d_path, my_attributes); doc.Views.Redraw(); return(Result.Success); }
/// <summary> /// Determines if custom render meshes will be built for a particular object. /// </summary> /// <param name="vp">The viewport being rendered.</param> /// <param name="obj">The Rhino object of interest.</param> /// <param name="requestingPlugIn">UUID of the RDK plug-in requesting the meshes.</param> /// <param name="preview">Type of mesh to build.</param> /// <returns>true if custom meshes will be built.</returns> public abstract bool WillBuildCustomMeshes(ViewportInfo vp, RhinoObject obj, Guid requestingPlugIn, bool preview);
private bool IsCircle(RhinoObject rhObj) { var rc = false; if (null != rhObj) { var curve_obj = rhObj as CurveObject; if (null != curve_obj) { var arc_curve = curve_obj.CurveGeometry as ArcCurve; if (null != arc_curve && arc_curve.IsCompleteCircle) rc = true; } } return rc; }
public override bool ShouldDisplay(RhinoObject obj) { if (Source_Props == null) Source_Props = new Pach_SourceControl(); List<RhinoObject> Selected = GetSelected(); if (Selected.Count > 0) { Source_Props.Load_Doc(Selected); return true; } //default case is not to support the selected object type return false; }
//Dynamic Object Draw void RefObjDraw(object sender, Rhino.Input.Custom.GetPointDrawEventArgs e) { double factorTemp = (scaleCenter.DistanceTo(e.CurrentPoint)) / (scaleCenter.DistanceTo(scaleRefPoint)); //Translate 3d if (dimensionIndex == 0) { for (int i = 0; i < dynRef.Count; i++) { Rhino.DocObjects.ObjRef objref = dynRef[i] as Rhino.DocObjects.ObjRef; var xform = Transform.Scale(centers[i], factorTemp); Brep brep = objref.Brep(); var index = objref.GeometryComponentIndex.Index; if (index > 0) { brep.TransformComponent(new[] { objref.GeometryComponentIndex }, xform, 0.01, 0, true); //doc.Objects.Replace(objref.ObjectId, brep); e.Display.DrawBrepWires(brep, System.Drawing.Color.Gray); } else { Rhino.DocObjects.RhinoObject rhobj = objref.Object(); e.Display.DrawObject(rhobj, xform); } } } //Translate 2d else if (dimensionIndex == 1) { for (int i = 0; i < dynRef.Count; i++) { Rhino.DocObjects.ObjRef objref = dynRef[i] as Rhino.DocObjects.ObjRef; plane2D.Origin = centers[i]; var xform = Rhino.Geometry.Transform.Scale(plane2D, factorTemp, factorTemp, 1); Brep brep = objref.Brep(); var index = objref.GeometryComponentIndex.Index; if (index > 0) { brep.TransformComponent(new[] { objref.GeometryComponentIndex }, xform, 0.01, 0, true); //doc.Objects.Replace(objref.ObjectId, brep); e.Display.DrawBrepWires(brep, System.Drawing.Color.Gray); } else { Rhino.DocObjects.RhinoObject rhobj = objref.Object(); e.Display.DrawObject(rhobj, xform); } } } //Translate 1d else if (dimensionIndex == 2) { for (int i = 0; i < dynRef.Count; i++) { Vector3d vec = (scaleRefPoint - scaleCenter); Plane scalePlane = new Plane(centers[i], vec); var xform = Transform.Scale(scalePlane, 1, 1, factorTemp); Rhino.DocObjects.ObjRef objref = dynRef[i] as Rhino.DocObjects.ObjRef; Brep brep = objref.Brep(); var index = objref.GeometryComponentIndex.Index; if (index > 0) { brep.TransformComponent(new[] { objref.GeometryComponentIndex }, xform, 0.01, 0, true); //doc.Objects.Replace(objref.ObjectId, brep); e.Display.DrawBrepWires(brep, System.Drawing.Color.Gray); } else { Rhino.DocObjects.RhinoObject rhobj = objref.Object(); e.Display.DrawObject(rhobj, xform); } } } }
public static Rhino.Commands.Result AddTexture(Rhino.RhinoDoc doc) { // Select object to add texture const ObjectType filter = Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.PolysrfFilter | Rhino.DocObjects.ObjectType.Mesh; Rhino.DocObjects.ObjRef objref; Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetOneObject("Select object to add texture", false, filter, out objref); if (rc != Rhino.Commands.Result.Success) { return(rc); } Rhino.DocObjects.RhinoObject rhino_object = objref.Object(); if (rhino_object == null) { return(Rhino.Commands.Result.Failure); } // Select texture Rhino.UI.OpenFileDialog fd = new Rhino.UI.OpenFileDialog(); fd.Filter = "Image Files (*.bmp;*.png;*.jpg)|*.bmp;*.png;*.jpg"; if (fd.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return(Rhino.Commands.Result.Cancel); } // Verify texture string bitmap_filename = fd.FileName; if (string.IsNullOrEmpty(bitmap_filename) || !System.IO.File.Exists(bitmap_filename)) { return(Rhino.Commands.Result.Nothing); } // Make sure the object has it's material source set to "material_from_object" rhino_object.Attributes.MaterialSource = Rhino.DocObjects.ObjectMaterialSource.MaterialFromObject; // Make sure the object has a material assigned int material_index = rhino_object.Attributes.MaterialIndex; if (material_index < 0) { // Create a new material based on Rhino's default material material_index = doc.Materials.Add(); // Assign the new material (index) to the object. rhino_object.Attributes.MaterialIndex = material_index; } if (material_index >= 0) { Rhino.DocObjects.Material mat = doc.Materials[material_index]; mat.SetBumpTexture(bitmap_filename); mat.CommitChanges(); //Don't forget to update the object, if necessary rhino_object.CommitChanges(); doc.Views.Redraw(); return(Rhino.Commands.Result.Success); } return(Rhino.Commands.Result.Failure); }
public override bool ShouldDisplay(RhinoObject obj) { if (obj_Props == null) obj_Props = new Pach_objProps(); List<RhinoObject> Selected = this.GetSelected(); if (Selected.Count > 0) { obj_Props.Load_Doc(Selected); return true; } return false; }
public override bool ShouldDisplay(RhinoObject rhObj) { var rc = false; if (null != rhObj) { rc = IsCircle(rhObj); } else { foreach (var rh_obj in SelectedObjects) { if (IsCircle(rh_obj)) { rc = true; break; } } } return rc; }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // TODO: complete command. MyRhino5rs11project8PlugIn p = MyRhino5rs11project8PlugIn.Instance; if (p.if_painted_object_set_ == false) { RhinoApp.WriteLine("No mesh"); return(Result.Failure); } Mesh my_mesh = p.painted_object_; DijkstraGraph my_graph = p.graph; GetObject gbrep = new GetObject(); gbrep.SetCommandPrompt("get the brep"); gbrep.GeometryFilter = Rhino.DocObjects.ObjectType.Brep; gbrep.SubObjectSelect = false; gbrep.Get(); if (gbrep.CommandResult() != Rhino.Commands.Result.Success) { return(gbrep.CommandResult()); } Rhino.DocObjects.ObjRef my_objref = gbrep.Object(0); Rhino.DocObjects.RhinoObject my_obj = my_objref.Object(); if (my_obj == null) { return(Rhino.Commands.Result.Failure); } Brep brep = my_objref.Brep(); if (brep == null) { return(Result.Failure); } my_obj.Select(false); int pin_number_1 = My_object_functions.GetPinQuantity(brep); List <Guid> pin_ball_guid_list_1 = new List <Guid>(); for (int i = 0; i < pin_number_1; i++) { ObjectAttributes green_ball_attributes = new ObjectAttributes(); green_ball_attributes.ObjectColor = Color.Green; green_ball_attributes.ColorSource = ObjectColorSource.ColorFromObject; Point3d pin_position = My_object_functions.GetPinPosition(brep, i); Guid pin_id = My_object_functions.GetPinGuid(brep, i); green_ball_attributes.ObjectId = pin_id; green_ball_attributes.UserDictionary.Set("isPin", true); Sphere pin_ball = new Sphere(pin_position, 2); //Brep pin_ball_brep = pin_ball.ToBrep(); doc.Objects.AddSphere(pin_ball, green_ball_attributes); pin_ball_guid_list_1.Add(pin_id); } doc.Views.Redraw(); GetObject g_pinball = new GetObject(); g_pinball.SetCommandPrompt("choose the pin"); g_pinball.GeometryFilter = ObjectType.Surface; //g_pinball.SetCustomGeometryFilter(PinBallGeometryFilter); //g_pinball.DisablePreSelect(); g_pinball.SubObjectSelect = false; g_pinball.Get(); if (g_pinball.CommandResult() != Result.Success) { return(g_pinball.CommandResult()); } if (g_pinball.Object(0).Brep() == null) { return(Result.Failure); } RhinoObject selected_pin_ball = g_pinball.Object(0).Object(); Guid selected_pin_ball_id = selected_pin_ball.Id; for (int i = 0; i < pin_ball_guid_list_1.Count; i++) { doc.Objects.Delete(pin_ball_guid_list_1[i], true); } ObjectAttributes greenyellow_ball_attributes = new ObjectAttributes(); greenyellow_ball_attributes.ObjectColor = Color.GreenYellow; greenyellow_ball_attributes.ColorSource = ObjectColorSource.ColorFromObject; greenyellow_ball_attributes.ObjectId = selected_pin_ball_id; greenyellow_ball_attributes.UserDictionary.Set("isPin", true); int pin_number = My_object_functions.FindPinNumber(brep, selected_pin_ball_id); Point3d selected_pin_position = My_object_functions.GetPinPosition(brep, pin_number); Sphere pin_ball_new = new Sphere(selected_pin_position, 2); doc.Objects.AddSphere(pin_ball_new, greenyellow_ball_attributes); doc.Views.Redraw(); //MyRhino5rs11project8PlugIn p = MyRhino5rs11project8PlugIn.Instance; if (p.my_objects_list.Count <= 1) { RhinoApp.WriteLine("not enough objects"); return(Result.Failure); } List <Guid> pin_ball_guid_list_2 = new List <Guid>(); for (int i = 0; i < p.my_objects_list.Count; i++) { Brep an_object = p.my_objects_list[i]; if (My_object_functions.GetComponentID(brep) != My_object_functions.GetComponentID(an_object)) { int pin_quantity = My_object_functions.GetPinQuantity(an_object); for (int j = 0; j < pin_quantity; j++) { ObjectAttributes green_ball_attributes = new ObjectAttributes(); green_ball_attributes.ObjectColor = Color.Green; green_ball_attributes.ColorSource = ObjectColorSource.ColorFromObject; Point3d pin_position = My_object_functions.GetPinPosition(an_object, j); Guid pin_id = My_object_functions.GetPinGuid(an_object, j); green_ball_attributes.ObjectId = pin_id; green_ball_attributes.UserDictionary.Set("isPin", true); Sphere pin_ball = new Sphere(pin_position, 2); doc.Objects.AddSphere(pin_ball, green_ball_attributes); pin_ball_guid_list_2.Add(pin_id); } } } doc.Views.Redraw(); GetObject g_pinball_2 = new GetObject(); g_pinball_2.SetCommandPrompt("choose the pin"); g_pinball_2.GeometryFilter = ObjectType.Surface; //g_pinball.SetCustomGeometryFilter(PinBallGeometryFilter); //g_pinball.DisablePreSelect(); g_pinball_2.SubObjectSelect = false; g_pinball_2.Get(); if (g_pinball_2.CommandResult() != Result.Success) { return(g_pinball_2.CommandResult()); } if (g_pinball_2.Object(0).Brep() == null) { return(Result.Failure); } RhinoObject selected_pin_ball_2 = g_pinball_2.Object(0).Object(); Guid selected_pin_ball_id_2 = selected_pin_ball_2.Id; Brep brep_2 = null; for (int i = 0; i < p.my_objects_list.Count; i++) { Brep an_object = p.my_objects_list[i]; int pin_quantity = My_object_functions.GetPinQuantity(an_object); bool mark = false; for (int j = 0; j < pin_quantity; j++) { if (My_object_functions.GetPinGuid(an_object, j) == selected_pin_ball_id_2) { mark = true; break; } } if (mark) { brep_2 = an_object; break; } } if (brep_2 == null) { return(Result.Failure); } int selected_pin_number_2 = My_object_functions.FindPinNumber(brep_2, selected_pin_ball_id_2); for (int i = 0; i < pin_ball_guid_list_2.Count; i++) { doc.Objects.Delete(pin_ball_guid_list_2[i], true); } Point3d selected_pin_position_2 = My_object_functions.GetPinPosition(brep_2, selected_pin_number_2); Sphere pin_ball_new_2 = new Sphere(selected_pin_position_2, 2); greenyellow_ball_attributes.ObjectId = selected_pin_ball_id_2; doc.Objects.AddSphere(pin_ball_new_2, greenyellow_ball_attributes); doc.Views.Redraw(); MeshPoint pin_1_meshpoint = my_mesh.ClosestMeshPoint(selected_pin_position, 0); MeshPoint pin_2_meshpoint = my_mesh.ClosestMeshPoint(selected_pin_position_2, 0); NurbsCurve d_path = my_graph.DijkstraPath_Add(pin_1_meshpoint, selected_pin_ball_id, pin_2_meshpoint, selected_pin_ball_id_2); if (d_path != null) { ObjectAttributes path_attributes = new ObjectAttributes(); path_attributes.ObjectColor = Color.Yellow; path_attributes.ColorSource = ObjectColorSource.ColorFromObject; path_attributes.PlotWeightSource = ObjectPlotWeightSource.PlotWeightFromObject; path_attributes.PlotWeight = 2.0; path_attributes.ObjectId = d_path.UserDictionary.GetGuid("PathID"); doc.Objects.AddCurve(d_path, path_attributes); } doc.Objects.Delete(selected_pin_ball_id, true); doc.Objects.Delete(selected_pin_ball_id_2, true); doc.Views.Redraw(); return(Result.Success); }
/// <summary> /// Checks geometry to see if it can be selected. /// Override to provide fancy filtering. /// </summary> /// <param name="rhObject">parent object being considered.</param> /// <param name="geometry">geometry being considered.</param> /// <param name="componentIndex"> /// if >= 0, geometry is a proper sub-part of object->Geometry() with componentIndex. /// </param> /// <returns> /// The default returns true unless you've set a custom geometry filter. If a custom /// filter has been set, that delegate is called /// </returns> public virtual bool CustomGeometryFilter( RhinoObject rhObject, GeometryBase geometry, ComponentIndex componentIndex ) { if (m_filter != null) return m_filter(rhObject, geometry, componentIndex); return true; }
/// <summary> /// Checks geometry to see if it passes the basic GeometryAttributeFilter. /// </summary> /// <param name="rhObject">parent object being considered.</param> /// <param name="geometry">geometry being considered.</param> /// <param name="componentIndex">if >= 0, geometry is a proper sub-part of object->Geometry() with componentIndex.</param> /// <returns> /// true if the geometry passes the filter returned by GeometryAttributeFilter(). /// </returns> public bool PassesGeometryAttributeFilter(RhinoObject rhObject, GeometryBase geometry, ComponentIndex componentIndex) { IntPtr const_ptr_rhino_object = IntPtr.Zero; if (rhObject != null) const_ptr_rhino_object = rhObject.ConstPointer(); IntPtr const_ptr_geometry = IntPtr.Zero; if (geometry != null) const_ptr_geometry = geometry.ConstPointer(); IntPtr ptr = NonConstPointer(); return UnsafeNativeMethods.CRhinoGetObject_PassesGeometryAttributeFilter(ptr, const_ptr_rhino_object, const_ptr_geometry, componentIndex); }
/// <summary> /// Returns a bounding box for the custom render meshes for the given object. /// </summary> /// <param name="vp">The viewport being rendered.</param> /// <param name="obj">The Rhino object of interest.</param> /// <param name="requestingPlugIn">UUID of the RDK plug-in requesting the meshes.</param> /// <param name="preview">Type of mesh to build.</param> /// <returns>A bounding box value.</returns> public virtual BoundingBox BoundingBox(ViewportInfo vp, RhinoObject obj, Guid requestingPlugIn, bool preview) { var min = new Point3d(); var max = new Point3d(); if (UnsafeNativeMethods.Rdk_RMPBoundingBoxImpl(m_runtime_serial_number, vp.ConstPointer(), obj.ConstPointer(), requestingPlugIn, preview ? 1 : 0, ref min, ref max)) return new BoundingBox(min, max); return new BoundingBox(); }
/// <summary> /// /// </summary> /// <param name="obj"></param> public static void ObjectChanged(RhinoObject obj) { UnsafeNativeMethods.Rdk_CRMManager_EVF("ObjectChanged", obj.ConstPointer()); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { const Rhino.DocObjects.ObjectType geometryFilter = Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.PolysrfFilter; Rhino.DocObjects.ObjRef objref; Result rc = Rhino.Input.RhinoGet.GetOneObject("Select first/main polysurface or surface to bool", false, geometryFilter, out objref); if (rc != Rhino.Commands.Result.Success) { return(rc); } if (objref == null) { return(Rhino.Commands.Result.Failure); } Rhino.Geometry.Brep brep = objref.Brep(); bool resIssolid = brep.IsSolid; if (!resIssolid) { Dialogs.ShowMessage("Your polysurface or surface is not solid! Result might not be valid!", "Warning!"); } Guid firstBrep = objref.ObjectId; doc.Objects.UnselectAll(true); //Select rest of polysurfaces or surfaces to bool Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select rest of polysurfaces or surfaces to bool"); go.GeometryFilter = geometryFilter | Rhino.DocObjects.ObjectType.InstanceReference; go.GroupSelect = true; go.GetMultiple(1, 0); bool isSolid = true; //Add set to breps list List <Rhino.Geometry.Brep> breps = new List <Rhino.Geometry.Brep>(); for (int i = 0; i < go.ObjectCount; i++) { //Explode if instance object and add to breps list if (go.Object(i).Object() is InstanceObject) { InstanceObject instObj = go.Object(i).Object() as InstanceObject; RhinoObject[] explodedObjects; ObjectAttributes[] attributesOfExplodedObjects; Transform[] transformOfExplodedObjects; instObj.Explode(false, out explodedObjects, out attributesOfExplodedObjects, out transformOfExplodedObjects); Guid addedObjectID = doc.Objects.Add(explodedObjects[0].Geometry, explodedObjects[0].Attributes); ObjRef objrefs = new Rhino.DocObjects.ObjRef(addedObjectID); Rhino.Geometry.Brep brepd = objrefs.Brep(); brepd.Transform(transformOfExplodedObjects[0]); resIssolid = brepd.IsSolid; if (!resIssolid) { isSolid = false; } if (brepd != null && firstBrep != addedObjectID) { breps.Add(brepd); } doc.Objects.Delete(addedObjectID, true); } else { Rhino.DocObjects.ObjRef objrefs = go.Object(i); Rhino.Geometry.Brep brepd = objrefs.Brep(); resIssolid = brepd.IsSolid; if (!resIssolid) { isSolid = false; } if (brepd != null && firstBrep != objrefs.ObjectId) { breps.Add(brepd); } } } if (!isSolid) { Dialogs.ShowMessage("At least on polysurface or surface to subtract is not solid! Result might not be valid!", "Warning!"); } doc.Objects.UnselectAll(true); //Create layers for failed and successfull booleans if not already existing var fail_layer_index = doc.Layers.FindName("FJ Boolean Fails"); if (fail_layer_index == null) { string name_fail_layer = "FJ Boolean Fails"; Rhino.DocObjects.Layer boolFail = new Rhino.DocObjects.Layer(); boolFail.Name = name_fail_layer; boolFail.Color = System.Drawing.Color.Red; doc.Layers.Add(boolFail); fail_layer_index = doc.Layers.FindName(name_fail_layer); } var done_layer_index = doc.Layers.FindName("FJ Boolean Done"); if (done_layer_index == null) { string name_done_layer = "FJ Boolean Done"; Rhino.DocObjects.Layer boolDone = new Rhino.DocObjects.Layer(); boolDone.Name = name_done_layer; boolDone.Color = System.Drawing.Color.BlueViolet; doc.Layers.Add(boolDone); done_layer_index = doc.Layers.FindName(name_done_layer); } //Compute boolean union double tolerance = doc.ModelAbsoluteTolerance; int a = 0; for (int i = 0; i < breps.Count; i++) { RhinoApp.WriteLine("computing number: " + i + " of: " + breps.Count + " operations..."); List <Brep> brepBool = new List <Brep>(); brepBool.Add(brep); brepBool.Add(breps[i]); Rhino.Geometry.Brep[] brepBoolNew = Rhino.Geometry.Brep.CreateBooleanUnion(brepBool, tolerance, true); if (brepBoolNew == null || brepBoolNew.Length > 1) { a++; doc.Objects.Delete(go.Object(i).Object()); var boolresultfail = doc.Objects.AddBrep(breps[i]); ObjRef objFailref = new ObjRef(boolresultfail); Rhino.DocObjects.RhinoObject objFail = objFailref.Object(); objFail.Attributes.LayerIndex = fail_layer_index.Index; objFail.CommitChanges(); } else { brep = brepBoolNew[0]; doc.Objects.Delete(go.Object(i).Object()); var boolresult = doc.Objects.AddBrep(breps[i]); ObjRef obj20ref = new ObjRef(boolresult); Rhino.DocObjects.RhinoObject obj2Org = obj20ref.Object(); obj2Org.Attributes.LayerIndex = done_layer_index.Index; obj2Org.CommitChanges(); } doc.Views.Redraw(); } RhinoApp.WriteLine(a + " of " + breps.Count + " operations failed!"); Rhino.DocObjects.RhinoObject obj1Org = objref.Object(); doc.Objects.Delete(obj1Org); doc.Objects.AddBrep(brep); doc.Views.Redraw(); return(Rhino.Commands.Result.Success); }
/// <summary> /// Draws the panel. /// </summary> /// <param name="xLowerBound">The x lower bound.</param> /// <param name="xUpperBound">The x upper bound.</param> /// <param name="yLowerBound">The y lower bound.</param> /// <param name="yUpperBound">The y upper bound.</param> /// <param name="panel">The panel.</param> /// <param name="para">The para.</param> public static void drawPanel(double xLowerBound, double xUpperBound, double yLowerBound, double yUpperBound, PerforationPanel panel, bool fixingHolesManipulated, bool enablePerf) { RhinoDoc doc = RhinoDoc.ActiveDoc; List <Guid> guidList = new List <Guid>(); string layerName = null; //name of layers int layerIndex = 0; //index of layers Rhino.DocObjects.Layer parent_layer_Approval = null; //create variable to hold approval layer Rhino.DocObjects.Layer parent_layer_Nesting = null; //create variable to hold nesting layer //Rhino.DocObjects.Layer childlayer = null; //Create a variable to hold child layers string text = ""; double height = panel.labelHeight / 3; const string font = "Arial"; Guid burrLeader; RhinoObject labelText; Rhino.Geometry.Point3d pt = new Rhino.Geometry.Point3d(0, 0, 0); Rhino.Geometry.Plane plane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane(); //start //Creating layer called "Layers for Approval Drawings" to make it a parent layer layerName = "LAYERS FOR APPROVAL DRAWINGS"; // Does a layer with the same name already exist? layerIndex = doc.Layers.Find(layerName, true); // If layer does not exist if (layerIndex == -1) { // Add a new layer to the document layerIndex = doc.Layers.Add(layerName, System.Drawing.Color.Black); parent_layer_Approval = doc.Layers[layerIndex]; //set the layer as parent layer } else { parent_layer_Approval = doc.Layers[layerIndex]; } layerName = "LAYERS FOR NESTING"; // Does a layer with the same name already exist? layerIndex = doc.Layers.Find(layerName, true); // If layer does not exist if (layerIndex == -1) { // Add a new layer to the document layerIndex = doc.Layers.Add(layerName, System.Drawing.Color.Black); parent_layer_Nesting = doc.Layers[layerIndex]; } else { parent_layer_Nesting = doc.Layers[layerIndex]; } // Create a new layer called Perimeter layerName = "PANEL PERIMETER"; layerIndex = createSubLayers.createSubLayer(layerName, System.Drawing.Color.Black, parent_layer_Nesting); //make Nesting layer the parent layer doc.Layers.SetCurrentLayerIndex(layerIndex, true); //Bottom and left justified the panels in the grid (panel x0,x1,y0,y1 - refers to the folds edg (folds layer) double panelX0 = xLowerBound; double panelX1 = panelX0 + panel.X; double panelY0 = yUpperBound; double panelY1 = panelY0 + panel.Y; List <Point3d> list = new List <Point3d>(); panel.Perimeter = doc.Objects.AddLine(new Point3d(panelX0, panelY1, 0), new Point3d(panelX1, panelY1, 0)); guidList.Add(panel.Perimeter); panel.Perimeter = doc.Objects.AddLine(new Point3d(panelX0, panelY0, 0), new Point3d(panelX0, panelY1, 0)); guidList.Add(panel.Perimeter); panel.Perimeter = doc.Objects.AddLine(new Point3d(panelX0, panelY0, 0), new Point3d(panelX1, panelY0, 0)); guidList.Add(panel.Perimeter); panel.Perimeter = doc.Objects.AddLine(new Point3d(panelX1, panelY0, 0), new Point3d(panelX1, panelY1, 0)); guidList.Add(panel.Perimeter); //MetrixUtilities.joinCurves(doc.Layers.Find("PANEL PERIMETER", true)); //join the closed curves using the method //Calculating the borders double borderX0 = panelX0 + panel.LeftBorder; //refers to the borders corners double borderY0 = panelY0 + panel.BottomBorder; double borderX1 = panelX1 - panel.RightBorder; double borderY1 = panelY1 - panel.TopBorder; BoundingBox panelBox = new BoundingBox(borderX0, borderY0, 0, borderX1, borderY1, 0); List <Point3d> rectangle_corners = panelBox.GetCorners().Distinct().ToList(); // add 1st point at last to close the loop rectangle_corners.Add(rectangle_corners[0]); // Create a new layer called Border layerName = "BORDERS"; layerIndex = createSubLayers.createSubLayer(layerName, System.Drawing.Color.Purple, parent_layer_Approval); //pass to the method, make Approval layer the parent layer doc.Layers.SetCurrentLayerIndex(layerIndex, true); //Add the borders only if the panel is not solid if (panel.DrawPerf != 3) { //Create a bounding box for the borders panel.Border = doc.Objects.AddPolyline(rectangle_corners); guidList.Add(panel.Border); } // Create a new layer called LABELS layerName = "LABELS"; layerIndex = createSubLayers.createSubLayer(layerName, System.Drawing.Color.Red, parent_layer_Nesting); //pass to the method, make Nesting layer the parent layer doc.Layers.SetCurrentLayerIndex(layerIndex, true); text = panel.PartName; height = panel.labelHeight; pt = new Rhino.Geometry.Point3d(borderX0, borderY0 + 4 + height, 0); plane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane(); plane.Origin = pt; panel.Label = doc.Objects.AddText(text, plane, height, font, false, false); guidList.Add(panel.Label); RhinoApp.RunScript("SelNone", true); labelText = doc.Objects.Find(panel.Label); labelText.Select(true); BoundingBox bbox = labelText.Geometry.GetBoundingBox(true); double minX = bbox.Corner(true, true, true).X; double maxX = bbox.Corner(false, true, true).X; double minY = bbox.Corner(true, true, true).Y; double maxY = bbox.Corner(true, false, true).Y; if (maxX - minX >= panel.X - panel.LeftBorder - panel.RightBorder) { double ratio = 1; labelText.Select(true); if (panel.Y > panel.X) { RhinoApp.RunScript("_-rotate " + bbox.Center.X + "," + bbox.Center.Y + " " + "90", true); } if (maxY - minY + 4 >= panel.X - panel.LeftBorder - panel.RightBorder) { ratio = (panel.X - panel.LeftBorder - panel.RightBorder) / (2 * (maxY - minY)); if (ratio * (maxX - minX) >= (panel.Y - panel.TopBorder - panel.BottomBorder)) { ratio = ratio * (panel.Y - panel.TopBorder - panel.BottomBorder) / (2 * ratio * (maxX - minX)); } } else if (maxX - minX >= panel.Y - panel.TopBorder - panel.BottomBorder) { ratio = (panel.Y - panel.TopBorder - panel.BottomBorder) / (2 * (maxX - minX)); } RhinoApp.RunScript("_-Scale " + bbox.Center.X + "," + bbox.Center.Y + " " + ratio, true); BoundingBox bbox3 = labelText.Geometry.GetBoundingBox(true); double distance1 = borderX0 + ratio * (bbox3.Max.X - bbox3.Min.X) / 2; double distance2 = borderY0 + ratio * (bbox3.Max.Y - bbox3.Min.Y) / 2; if (panel.Y > panel.X) { distance1 = borderX0 + ratio * (bbox3.Max.Y - bbox3.Min.Y) / 2; distance2 = borderY0 + ratio * (bbox3.Max.X - bbox3.Min.X) / 2; } RhinoApp.WriteLine(bbox3.Center.ToString()); RhinoApp.RunScript("_-Move " + bbox3.Center.X + "," + bbox3.Center.Y + ",0 " + distance1 + "," + distance2 + ",0", true); } else if (maxY - minY >= panel.Y - panel.TopBorder - panel.BottomBorder) { double ratio = (panel.Y - panel.TopBorder - panel.BottomBorder) / (2 * (maxY - minY)); labelText.Select(true); RhinoApp.RunScript("_-Scale " + bbox.Center.X + "," + bbox.Center.Y + " " + ratio, true); BoundingBox bbox2 = labelText.Geometry.GetBoundingBox(true); double distanceX = borderX0 + ratio * (bbox2.Center.X - bbox2.Min.X) / 2; double distanceY = panelBox.Min.Y + ratio * (bbox2.Center.Y - bbox.Min.Y) / 2; RhinoApp.WriteLine(bbox2.Center.ToString()); RhinoApp.RunScript("_-Move " + bbox2.Center.X + "," + bbox2.Center.Y + ",0 " + distanceX + "," + distanceY + ",0", true); } labelText.Select(false); // If dotFontLabel is more than 0 draw the dot font text on the panel, else skip // if (para.DotFont == 1) if (panel.DotFontLabel > 0) { // Create a new layer called DOT SCRIBE LABEL layerName = "DOT SCRIBE LABEL"; layerIndex = createSubLayers.createSubLayer(layerName, System.Drawing.Color.Black, parent_layer_Nesting); //make Nesting layer the parent layer doc.Layers.SetCurrentLayerIndex(layerIndex, true); // Put in the Dot Matrix Label // Draw at the right side of the border aand 10mm from the bottom and 100mm from the left edge double panelOffset = 0; if (panel.BottomBorder - 8.7 <= 6) { panelOffset = (panel.BottomBorder - 8.7) / 2; } else { panelOffset = 3.1; } if (panel.X < 160) { pt = new Point3d(1 * (panelX0 + panelX1) / 2, panelY0 + panelOffset + 8.7, 0); } else { pt = new Point3d(panelX1 - 100, panelY0 + panelOffset + 8.7, 0); } if (panel.DotFontLabellerSide.Equals("Rear")) { DotMatrixLabellerCommand.Instance.drawDotMatrix(pt, panel.PartName, 8.7, panel.X); //set the size of dotfont } else //If not revered use front labeller { DotMatrixFrontLabellerCommand.Instance.drawDotMatrix(pt, panel.PartName, 8.7); } } //checks whether the perforation layers exists, if not create layer and make Approval layer the parent layer //If exists, make Approval layer the parent layer layerName = "PERFORATION"; layerIndex = createSubLayers.createSubLayer(layerName, System.Drawing.Color.Green, parent_layer_Approval); // doc.Layers.SetCurrentLayerIndex(layerIndex, true); //Create Temporary Layer if (panel.DrawPerf == 1) { RhinoUtilities.SetActiveLayer("TemporaryPerfLayer", System.Drawing.Color.Green); doc.Views.Redraw(); RhinoApp.RunScript("SelAll", true); RhinoApp.RunScript("-_Rotate 0,0,0 -" + panel.patternDirection, true); PerforationForm perforationForm = new PerforationForm(new Rhino.DocObjects.ObjRef(panel.Border).Curve()); perforationForm.enablePerforation = enablePerf; perforationForm.drawPerforationDesign(panel.PatternName, true, enablePerf); RhinoApp.RunScript("SelAll", true); RhinoApp.RunScript("-_Rotate 0,0,0 " + panel.patternDirection, true); RhinoApp.RunScript("SelNone", true); var rhinoObjects = doc.Objects.FindByLayer("TemporaryPerfLayer"); var toolHitObjects = doc.Objects.FindByLayer("TemporaryToolHit"); var temporaryTool2Layer = doc.Objects.FindByLayer("TemporaryTool2Layer"); //Perf objects if (rhinoObjects != null && rhinoObjects.Length > 1) { foreach (var rhinObj in rhinoObjects) { rhinObj.Select(true); } if (panel.patternDirection == 1) { RhinoApp.RunScript("-_Rotate 0,0,0 -90", true); RhinoApp.RunScript("-_Rotate 0,0,0 90", true); } RhinoUtilities.SetActiveLayer(Properties.Settings.Default.PerforationLayerName, System.Drawing.Color.Green); RhinoApp.RunScript("-_ChangeLayer PERFORATION", true); int index = doc.Layers.Find("TemporaryPerfLayer", true); doc.Layers.Delete(index, true); } //tool hit objects if (toolHitObjects != null && toolHitObjects.Length > 1) { foreach (var toolhitObj in toolHitObjects) { toolhitObj.Select(true); } if (panel.patternDirection == 1) { RhinoApp.RunScript("-_Rotate 0,0,0 -90", true); RhinoApp.RunScript("-_Rotate 0,0,0 90", true); } RhinoUtilities.SetActiveLayer(Properties.Settings.Default.ToolHitLayerName, System.Drawing.Color.Black); RhinoApp.RunScript("-_ChangeLayer TOOL HIT", true); int index = doc.Layers.Find("TemporaryToolHit", true); doc.Layers.Delete(index, true); } //Tool 2 objects if (temporaryTool2Layer != null && temporaryTool2Layer.Length > 1) { foreach (var tool2Objs in temporaryTool2Layer) { tool2Objs.Select(true); } if (panel.patternDirection == 1) { RhinoApp.RunScript("-_Rotate 0,0,0 -90", true); RhinoApp.RunScript("-_Rotate 0,0,0 90", true); } RhinoUtilities.SetActiveLayer("Tool 2 Layer", System.Drawing.Color.Yellow); RhinoApp.RunScript("-_ChangeLayer Tool 2 Layer", true); int index = doc.Layers.Find("TemporaryTool2Layer", true); doc.Layers.Delete(index, true); } doc.Views.Redraw(); } DimensionStyle dimStyle = MetrixUtilities.createMetrixRealDimension(); //sets the metrix real dimension Point3d origin = new Point3d(0, 0, 0); Point3d offset = new Point3d(0, 0, 0); Point2d ext1; Point2d ext2; Point2d linePt; LinearDimension dimension; Guid dimGuid = new Guid(); double u, v; // Create a new layer called DIMENSIONS BLACK layerName = "DIMENSIONS BLACK"; layerIndex = createSubLayers.createSubLayer(layerName, System.Drawing.Color.Black, parent_layer_Approval); //pass to the method, make Approval layer the parent layer doc.Layers.SetCurrentLayerIndex(layerIndex, true); // Add the word perforated area to the panel if (panel.DrawPerf != 3) //Add the text only if the panel is not a solid panel { //pt = new Rhino.Geometry.Point3d(((borderX1 + borderX0) / 2) - 117.5, ((borderY1 + borderY0) / 2) + 33, 0); text = System.Text.RegularExpressions.Regex.Unescape(panel.PerfText); height = panel.labelHeight / 2; pt = new Rhino.Geometry.Point3d(((borderX1 + borderX0) / 2) - 117.5, ((borderY1 + borderY0) / 2) + 10 + height, 0); plane.Origin = pt; Guid perforatedAreaLabel = doc.Objects.AddText(text, plane, height, font, false, false); guidList.Add(perforatedAreaLabel); double ratio = 1; if (panel.X - panel.LeftBorder - panel.RightBorder < 230) { RhinoApp.RunScript("SelNone", true); labelText = doc.Objects.Find(perforatedAreaLabel); labelText.Select(true); bbox = labelText.Geometry.GetBoundingBox(true); if (panel.Y > panel.X) { RhinoApp.RunScript("_-rotate " + bbox.Center.X + "," + bbox.Center.Y + " " + "90", true); } minX = bbox.Corner(true, true, true).X; maxX = bbox.Corner(false, true, true).X; minY = bbox.Corner(true, true, true).Y; maxY = bbox.Corner(true, false, true).Y; if (maxY - minY > panel.X - panel.LeftBorder - panel.RightBorder) { ratio = (panel.X - panel.LeftBorder - panel.RightBorder) / (2 * (maxY - minY)); if (ratio * (maxX - minX) > (panel.Y - panel.TopBorder - panel.BottomBorder)) { ratio = ratio * (panel.Y - panel.TopBorder - panel.BottomBorder) / (2 * ratio * (maxX - minX)); } } else if (maxX - minX >= panel.Y - panel.TopBorder - panel.BottomBorder) { ratio = (panel.Y - panel.TopBorder - panel.BottomBorder) / (2 * (maxX - minX)); } labelText.Select(true); RhinoApp.RunScript("_-Scale " + bbox.Center.X + "," + bbox.Center.Y + " " + ratio, true); BoundingBox bbox2 = labelText.Geometry.GetBoundingBox(true); double distanceX = (borderX0 + borderX1) / 2; double distanceY = (borderY0 + borderY1) / 2; RhinoApp.WriteLine(bbox2.Center.ToString()); RhinoApp.RunScript("_-Move " + bbox2.Center.X + "," + bbox2.Center.Y + ",0 " + distanceX + "," + distanceY + ",0", true); } else { RhinoApp.RunScript("SelNone", true); labelText = doc.Objects.Find(perforatedAreaLabel); labelText.Select(true); bbox = labelText.Geometry.GetBoundingBox(true); minX = bbox.Corner(true, true, true).X; maxX = bbox.Corner(false, true, true).X; minY = bbox.Corner(true, true, true).Y; maxY = bbox.Corner(true, false, true).Y; if (maxX - minX > panel.Y - panel.TopBorder - panel.BottomBorder) { ratio = (panel.Y - panel.TopBorder - panel.BottomBorder) / (2 * (maxY - minY)); labelText.Select(true); RhinoApp.RunScript("_-Scale " + bbox.Center.X + "," + bbox.Center.Y + " " + ratio, true); } BoundingBox bbox2 = labelText.Geometry.GetBoundingBox(true); double distanceX = (borderX0 + borderX1) / 2; double distanceY = (borderY0 + borderY1) / 2; RhinoApp.WriteLine(bbox2.Center.ToString()); RhinoApp.RunScript("_-Move " + bbox2.Center.X + "," + bbox2.Center.Y + ",0 " + distanceX + "," + distanceY + ",0", true); } } // Add horizontal dimension origin = new Point3d(panelX1, panelY0 - 50, 0); offset = new Point3d(panelX0, panelY0 - 50, 0); pt = new Point3d((offset.X - origin.X) / 2, panelY0 - 100, 0); plane = Plane.WorldXY; plane.Origin = origin; //double u, v; plane.ClosestParameter(origin, out u, out v); ext1 = new Point2d(u, v); plane.ClosestParameter(offset, out u, out v); ext2 = new Point2d(u, v); plane.ClosestParameter(pt, out u, out v); linePt = new Point2d(u, v); dimension = new LinearDimension(plane, ext1, ext2, linePt); dimGuid = doc.Objects.AddLinearDimension(dimension); //add the bottom dimension(vertical line) guidList.Add(dimGuid); // Add vertical dimension for panel origin = new Point3d(panelX0 - 20, panelY0, 0); offset = new Point3d(panelX0 - 20, panelY1, 0); pt = new Point3d(panelX0 - 100, (offset.Y - origin.Y) / 2, 0); plane = Plane.WorldXY; plane.XAxis = new Vector3d(0, -1, 0); plane.YAxis = new Vector3d(-1, 0, 0); plane.ZAxis = new Vector3d(0, 0, -1); plane.Origin = origin; plane.ClosestParameter(origin, out u, out v); ext1 = new Point2d(u, v); plane.ClosestParameter(offset, out u, out v); ext2 = new Point2d(u, v); plane.ClosestParameter(pt, out u, out v); linePt = new Point2d(u, v); dimension = new LinearDimension(plane, ext1, ext2, linePt); dimGuid = doc.Objects.AddLinearDimension(dimension); //adds the left dimension guidList.Add(dimGuid); MetrixUtilities.createMetrixBordersDimension(); //sets the dimension style for borders // Draw Border dimension on BORDERS layer if (panel.DrawPerf != 3) ///Add only if the panel is not a solid panel { layerName = "BORDERS"; layerIndex = doc.Layers.Find(layerName, true); doc.Layers.SetCurrentLayerIndex(layerIndex, true); // Add horizontal borders dimension origin = new Point3d(panelX1, (panelY0 + panelY1) / 2, 0); offset = new Point3d(borderX1, (panelY0 + panelY1) / 2, 0); pt = new Point3d((offset.X - origin.X) / 2, (borderY0 + borderY1) / 2, 0); plane = Plane.WorldXY; plane.Origin = origin; plane.ClosestParameter(origin, out u, out v); ext1 = new Point2d(u, v); plane.ClosestParameter(offset, out u, out v); ext2 = new Point2d(u, v); plane.ClosestParameter(pt, out u, out v); linePt = new Point2d(u, v); dimension = new LinearDimension(plane, ext1, ext2, linePt); dimGuid = doc.Objects.AddLinearDimension(dimension); guidList.Add(dimGuid); // Add horizontal borders dimension origin = new Point3d(panelX0, (panelY0 + panelY1) / 2, 0); offset = new Point3d(borderX0, (panelY0 + panelY1) / 2, 0); pt = new Point3d((offset.X - origin.X) / 2, (borderY0 + borderY1) / 2, 0); plane.ClosestParameter(origin, out u, out v); ext1 = new Point2d(u, v); plane.ClosestParameter(offset, out u, out v); ext2 = new Point2d(u, v); plane.ClosestParameter(pt, out u, out v); linePt = new Point2d(u, v); dimension = new LinearDimension(plane, ext1, ext2, linePt); dimGuid = doc.Objects.AddLinearDimension(dimension); guidList.Add(dimGuid); // Add vertical border dimension for panel origin = new Point3d((panelX0 + panelX1) / 2, panelY0, 0); offset = new Point3d((panelX0 + panelX1) / 2, borderY0, 0); pt = new Point3d((borderX0 + borderX1) / 2, (offset.Y - origin.Y) / 2, 0); plane = Plane.WorldXY; plane.XAxis = new Vector3d(0, -1, 0); plane.YAxis = new Vector3d(-1, 0, 0); plane.ZAxis = new Vector3d(0, 0, -1); plane.Origin = origin; plane.ClosestParameter(origin, out u, out v); ext1 = new Point2d(u, v); plane.ClosestParameter(offset, out u, out v); ext2 = new Point2d(u, v); plane.ClosestParameter(pt, out u, out v); linePt = new Point2d(u, v); dimension = new LinearDimension(plane, ext1, ext2, linePt); dimGuid = doc.Objects.AddLinearDimension(dimension); guidList.Add(dimGuid); origin = new Point3d((panelX0 + panelX1) / 2, panelY1, 0); offset = new Point3d((panelX0 + panelX1) / 2, borderY1, 0); pt = new Point3d((borderX0 + borderX1) / 2, (offset.Y - origin.Y) / 2, 0); plane.ClosestParameter(origin, out u, out v); ext1 = new Point2d(u, v); plane.ClosestParameter(offset, out u, out v); ext2 = new Point2d(u, v); plane.ClosestParameter(pt, out u, out v); linePt = new Point2d(u, v); dimension = new LinearDimension(plane, ext1, ext2, linePt); dimGuid = doc.Objects.AddLinearDimension(dimension); guidList.Add(dimGuid); } MetrixUtilities.createMetrixRealDimension(); //sets the default dimension style layerName = "VIEWPORT"; layerIndex = createSubLayers.createSubLayer(layerName, System.Drawing.Color.Black, parent_layer_Approval); //pass to the method, make Approval layer the parent layer doc.Layers.SetCurrentLayerIndex(layerIndex, true); Rhino.DocObjects.RhinoObject label = doc.Objects.Find(panel.Label); string exportFileName = "1"; if (label != null) { label.Select(true); Rhino.Geometry.TextEntity textentity = label.Geometry as Rhino.Geometry.TextEntity; exportFileName = textentity.Text + ".dxf"; } /** * Checks if the dxf files are required by the user, if yes check whether the panel is perforated * using the drawPerf property in the panel. If it is a perforated panel then check if the directory * for perforated panels dxf files already exists, if does not exist create directory and run command. * If panel is not perforated, create directory to save not perforated panels dxf files if the directory * does not exist. Then run the dxf file create command. * */ if (panel.DXFFilesRequired.Equals("Yes")) { String path; String immediateFolderName = Path.GetFileName(Path.GetDirectoryName(doc.Path)); //get the immediate foldername which the file is located in //split the path to get the parent folder. String[] newPath = MetrixUtilities.splitString(Path.GetDirectoryName(doc.Path), immediateFolderName); if (panel.DrawPerf == 1) //checks if panel is perforated { path = newPath[0] + ("5TRUMPF") + ("\\WITH PERF"); //merge path for perforated files if (!Directory.Exists(path)) //check if directory already exists { System.IO.Directory.CreateDirectory(path); //create directory if not exist } } else { path = newPath[0] + ("5TRUMPF") + ("\\NO PERF"); //merge path for not perforated files if (!Directory.Exists(path)) //check if directory already exists { System.IO.Directory.CreateDirectory(path); //create directory if not exist } } string command = string.Format("-_Export \"" + path + @"\" + exportFileName + "\" Scheme \"R12 Lines & Arcs\" Enter"); // Export the selected curves RhinoApp.RunScript(command, true); } // Unselect all objects doc.Objects.UnselectAll(); // Default layer index int defaultLayerIndex = doc.Layers.Find("Default", true); doc.Layers.SetCurrentLayerIndex(layerIndex, true); ////if draw perf is false, turnoff the toolhit layer //if (Convert.ToBoolean(panel.DrawPerf) != true) //{ // layerName = "Tool Hit"; // layerIndex = doc.Layers.Find(layerName, true); // doc.Layers[layerIndex].IsVisible = false; //} MetrixUtilities.joinCurves(doc.Layers.Find("PANEL PERIMETER", true)); if (panel.FixingHoles == "1") { //if fixing holes are not manipulated, recalculate distances if (!fixingHolesManipulated) { //panel = reCalculateDistances(panel); //Below method is if fixing holes are automated guidList = FixingHoles.drawFixingFoles(panel, null, false, 0, 0, panelY0, panelY1, dimStyle, guidList, panelX0, panelX1, 0, 0, 0, 0, 0); //add fixing holes } else { //Below method is if fixing holes have been manipulated guidList = CustomFixingHoles.drawFixingFoles(panel, null, false, 0, 0, panelY0, panelY1, dimStyle, guidList, panelX0, panelX1, 0, 0, 0, 0, 0); //add fixing holes } } layerName = "VIEWPORT"; layerIndex = createSubLayers.createSubLayer(layerName, System.Drawing.Color.Black, parent_layer_Approval); //pass to the method, make Approval layer the parent layer doc.Layers.SetCurrentLayerIndex(layerIndex, true); foreach (Guid g in guidList) { int idx = RhinoDoc.ActiveDoc.Groups.Find(panel.PartName, false); if (idx < 0) { idx = RhinoDoc.ActiveDoc.Groups.Add(panel.PartName); } RhinoDoc.ActiveDoc.Groups.AddToGroup(idx, g); } //end }
/// <summary> /// Called when this a new instance of this object is created and copied from /// an existing object /// </summary> /// <param name="source"></param> protected virtual void OnDuplicate(RhinoObject source) { }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // TODO: complete command. MyRhino5rs11project8PlugIn p = MyRhino5rs11project8PlugIn.Instance; if (p.if_painted_object_set_ == false) { RhinoApp.WriteLine("No mesh"); return(Result.Failure); } Mesh my_mesh = p.painted_object_; Stopwatch watch = new Stopwatch(); GetObject gbrep = new GetObject(); gbrep.SetCommandPrompt("get the brep"); gbrep.GeometryFilter = Rhino.DocObjects.ObjectType.Brep; gbrep.SubObjectSelect = false; gbrep.Get(); if (gbrep.CommandResult() != Rhino.Commands.Result.Success) { return(gbrep.CommandResult()); } Rhino.DocObjects.ObjRef my_objref = gbrep.Object(0); Rhino.DocObjects.RhinoObject my_obj = my_objref.Object(); if (my_obj == null) { return(Rhino.Commands.Result.Failure); } Brep brep = my_objref.Brep(); if (brep == null) { return(Result.Failure); } my_obj.Select(false); GetObjectPosition gp = new GetObjectPosition(brep, my_mesh); gp.SetCommandPrompt("Get the object position on mesh: "); gp.Constrain(my_mesh, false); gp.Get(); if (gp.CommandResult() != Result.Success) { return(gp.CommandResult()); } Brep moved_brep = brep.DuplicateBrep(); Point3d Origin = brep.UserDictionary.GetPoint3d("CurrentPosition"); Vector3d OriginVector = brep.UserDictionary.GetVector3d("CurrentDirection"); Point3d new_position = gp.Point(); Vector3d normal_on_mesh = my_mesh.NormalAt(my_mesh.ClosestMeshPoint(new_position, 0)); if (OriginVector.IsParallelTo(normal_on_mesh) == 0) { double RotationAngle = Vector3d.VectorAngle(OriginVector, normal_on_mesh); Vector3d RoationAxis = Vector3d.CrossProduct(OriginVector, normal_on_mesh); moved_brep.Rotate(RotationAngle, RoationAxis, Origin); } moved_brep.Translate(new_position - Origin); moved_brep.UserDictionary.Set("CurrentPosition", new_position); moved_brep.UserDictionary.Set("CurrentDirection", normal_on_mesh); ObjectAttributes my_attributes = new ObjectAttributes(); my_attributes.ObjectColor = Color.FromName(moved_brep.UserDictionary.GetString("Color")); my_attributes.ColorSource = ObjectColorSource.ColorFromObject; watch.Start(); //delete all old paths IEnumerable <RhinoObject> path_objref = doc.Objects.GetObjectList(ObjectType.Curve); foreach (RhinoObject path in path_objref) { doc.Objects.Delete(path, true); } watch.Stop(); RhinoApp.WriteLine("time 1: {0}", watch.Elapsed); ObjectAttributes path_attributes = new ObjectAttributes(); path_attributes.ObjectColor = Color.Yellow; path_attributes.ColorSource = ObjectColorSource.ColorFromObject; path_attributes.PlotWeightSource = ObjectPlotWeightSource.PlotWeightFromObject; path_attributes.PlotWeight = 2.0; Guid pin_1_id = moved_brep.UserDictionary.GetGuid("PinID"); MeshPoint current_meshpoint = my_mesh.ClosestMeshPoint(new_position, 0.0); watch.Restart(); List <NurbsCurve> new_path_list = p.graph.DijkstraPath_Change(pin_1_id, current_meshpoint); watch.Stop(); RhinoApp.WriteLine("time 2: {0}", watch.Elapsed); watch.Restart(); for (int i = 0; i < new_path_list.Count; i++) { doc.Objects.Add(new_path_list[i], path_attributes); } doc.Objects.Delete(my_objref, true); brep.Dispose(); doc.Objects.AddBrep(moved_brep, my_attributes); doc.Views.Redraw(); watch.Stop(); RhinoApp.WriteLine("time 3: {0}", watch.Elapsed); return(Result.Success); }
/// <summary> /// Draws the panel. /// </summary> /// <param name="xLowerBound">The x lower bound.</param> /// <param name="xUpperBound">The x upper bound.</param> /// <param name="yLowerBound">The y lower bound.</param> /// <param name="yUpperBound">The y upper bound.</param> /// <param name="panel">The panel.</param> /// <param name="para">The para.</param> public static void drawPanel(double xLowerBound, double xUpperBound, double yLowerBound, double yUpperBound, PerforationPanel panel, PanelParameters para) { RhinoDoc doc = RhinoDoc.ActiveDoc; List <Guid> guidList = new List <Guid>(); // Create a new layer called Panel Perimeter string layerName = "PANEL PERIMETER"; // Does a layer with the same name already exist? int layerIndex = doc.Layers.Find(layerName, true); // If layer does not exist if (layerIndex == -1) { // Add a new layer to the document layerIndex = doc.Layers.Add(layerName, System.Drawing.Color.Black); } doc.Layers.SetCurrentLayerIndex(layerIndex, true); // Bottom and left justified the panels in the grid double panelX0 = xLowerBound; double panelX1 = panelX0 + panel.X; double panelY0 = yUpperBound; double panelY1 = panelY0 + panel.Y; // Position the panel to be in the middle of the grid //double panelX0 = xLowerBound + ((xUpperBound - xLowerBound) - panel.X) /2 ; //double panelX1 = panelX0 + panel.X; //double panelY1 = yLowerBound - ((yLowerBound - yUpperBound) - panel.Y) / 2; //double panelY0 = panelY1 - panel.Y; BoundingBox panelBox = new BoundingBox(panelX0, panelY0, 0, panelX1, panelY1, 0); List <Point3d> rectangle_corners = panelBox.GetCorners().Distinct().ToList(); // add 1st point at last to close the loop rectangle_corners.Add(rectangle_corners[0]); panel.Perimeter = doc.Objects.AddPolyline(rectangle_corners); guidList.Add(panel.Perimeter); // Create a new layer called Border layerName = "BORDERS"; // Does a layer with the same name already exist? layerIndex = doc.Layers.Find(layerName, true); // If layer does not exist if (layerIndex == -1) { // Add a new layer to the document layerIndex = doc.Layers.Add(layerName, System.Drawing.Color.Purple); } doc.Layers.SetCurrentLayerIndex(layerIndex, true); double borderX0 = panelX0 + panel.LeftBorder; double borderY0 = panelY0 + panel.BottomBorder; double borderX1 = panelX1 - panel.RightBorder; double borderY1 = panelY1 - panel.TopBorder; panelBox = new BoundingBox(borderX0, borderY0, 0, borderX1, borderY1, 0); rectangle_corners = panelBox.GetCorners().Distinct().ToList(); // add 1st point at last to close the loop rectangle_corners.Add(rectangle_corners[0]); panel.Border = doc.Objects.AddPolyline(rectangle_corners); guidList.Add(panel.Border); // Create a new layer called LABELS layerName = "LABELS"; // Does a layer with the same name already exist? layerIndex = doc.Layers.Find(layerName, true); // If layer does not exist if (layerIndex == -1) { // Add a new layer to the document layerIndex = doc.Layers.Add(layerName, System.Drawing.Color.Red); } doc.Layers.SetCurrentLayerIndex(layerIndex, true); Rhino.Geometry.Point3d pt = new Rhino.Geometry.Point3d(borderX0, borderY0, 0); string text = panel.PartName; double height = para.LabelHeight; const string font = "Arial"; Rhino.Geometry.Plane plane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane(); plane.Origin = pt; panel.Label = doc.Objects.AddText(text, plane, height, font, false, false); guidList.Add(panel.Label); // If Dot font needs to be drawn if (para.DotFont == 1) { // Create a new layer called DOTS layerName = "DOTS"; // Does a layer with the same name already exist? layerIndex = doc.Layers.Find(layerName, true); // If layer does not exist if (layerIndex == -1) { // Add a new layer to the document layerIndex = doc.Layers.Add(layerName, System.Drawing.Color.Black); } doc.Layers.SetCurrentLayerIndex(layerIndex, true); // Put in the Dot Matrix Label // Draw at the right side of the border aand 10mm from the bottom and 100mm from the left edge pt = new Point3d(panelX1 - 100, panelY0 + 5, 0); DotMatrixLabellerCommand.Instance.drawDotMatrix(pt, panel.PartName, Properties.Settings.Default.DotMatrixHeight, panel.X); } if (para.PatternDirection == 1) { // Export the selected curves RhinoApp.RunScript("SelAll", true); RhinoApp.RunScript("-_Rotate 0,0,0 90", true); } PerforationForm perforationForm = new PerforationForm(new Rhino.DocObjects.ObjRef(panel.Border).Curve()); perforationForm.drawPerforationDesign(panel.PatternName, true); if (para.PatternDirection == 1) { // Export the selected curves RhinoApp.RunScript("SelAll", true); RhinoApp.RunScript("-_Rotate 0,0,0 -90", true); } // Draw Dimension // Find the Dimension Style // Create a new layer called DIMENSION layerName = "DIMENSION"; // Does a layer with the same name already exist? layerIndex = doc.Layers.Find(layerName, true); // If layer does not exist if (layerIndex == -1) { // Add a new layer to the document layerIndex = doc.Layers.Add(layerName, System.Drawing.Color.Black); } doc.Layers.SetCurrentLayerIndex(layerIndex, true); // Add the word perforated area to the panel pt = new Rhino.Geometry.Point3d(((borderX1 + borderX0) / 2) - 117.5, ((borderY1 + borderY0) / 2) + 33, 0); text = "PERFORATED \nAREA"; height = para.LabelHeight / 2; plane.Origin = pt; Guid perforatedAreaLabel = doc.Objects.AddText(text, plane, height, font, false, false); guidList.Add(perforatedAreaLabel); DimensionStyle dimStyle = doc.DimStyles.Find("Metrix Real", true); int dimStyleIndex = 0; if (dimStyle == null) { dimStyleIndex = doc.DimStyles.Add("Metrix Real"); dimStyle = doc.DimStyles.Find("Metrix Real", true); } else { dimStyleIndex = dimStyle.Index; } dimStyle.TextHeight = 40; dimStyle.TextGap = 25; dimStyle.ExtensionLineExtension = 25; dimStyle.ExtensionLineOffset = 25; dimStyle.LengthResolution = 0; dimStyle.AngleResolution = 0; dimStyle.ArrowLength = 25; dimStyle.LeaderArrowLength = 25; dimStyle.FitText = DimensionStyle.TextFit.TextInside; dimStyle.FixedExtensionLength = 25; dimStyle.FixedExtensionOn = true; dimStyle.DimRadialTextLocation = DimensionStyle.TextLocation.AboveDimLine; doc.DimStyles.Modify(dimStyle, dimStyleIndex, false); dimStyle.LeaderTextVerticalAlignment = TextVerticalAlignment.Middle; doc.DimStyles.SetCurrent(dimStyleIndex, false); // Add horizontal dimension Point3d origin = new Point3d(panelX1, panelY0, 0); Point3d offset = new Point3d(panelX0, panelY0, 0); pt = new Point3d((offset.X - origin.X) / 2, panelY0 - (dimStyle.TextHeight * 4), 0); plane = Plane.WorldXY; plane.Origin = origin; double u, v; plane.ClosestParameter(origin, out u, out v); Point2d ext1 = new Point2d(u, v); plane.ClosestParameter(offset, out u, out v); Point2d ext2 = new Point2d(u, v); plane.ClosestParameter(pt, out u, out v); Point2d linePt = new Point2d(u, v); LinearDimension dimension = new LinearDimension(plane, ext1, ext2, linePt); Guid dimGuid = doc.Objects.AddLinearDimension(dimension); guidList.Add(dimGuid); // Add horizontal borders dimension origin = new Point3d(panelX0, panelY0, 0); offset = new Point3d(borderX0, panelY0, 0); pt = new Point3d((offset.X - origin.X) / 2, panelY0 - (dimStyle.TextHeight * 2), 0); plane.ClosestParameter(origin, out u, out v); ext1 = new Point2d(u, v); plane.ClosestParameter(offset, out u, out v); ext2 = new Point2d(u, v); plane.ClosestParameter(pt, out u, out v); linePt = new Point2d(u, v); dimension = new LinearDimension(plane, ext1, ext2, linePt); dimGuid = doc.Objects.AddLinearDimension(dimension); guidList.Add(dimGuid); // Add horizontal borders dimension origin = new Point3d(panelX1, panelY0, 0); offset = new Point3d(borderX1, panelY0, 0); pt = new Point3d((offset.X - origin.X) / 2, panelY0 - (dimStyle.TextHeight * 2), 0); plane.ClosestParameter(origin, out u, out v); ext1 = new Point2d(u, v); plane.ClosestParameter(offset, out u, out v); ext2 = new Point2d(u, v); plane.ClosestParameter(pt, out u, out v); linePt = new Point2d(u, v); dimension = new LinearDimension(plane, ext1, ext2, linePt); dimGuid = doc.Objects.AddLinearDimension(dimension); guidList.Add(dimGuid); // Add vertical dimension for panel origin = new Point3d(panelX0, panelY0, 0); offset = new Point3d(panelX0, panelY1, 0); pt = new Point3d(panelX0 - (dimStyle.TextHeight * 4), (offset.Y - origin.Y) / 2, 0); plane = Plane.WorldXY; plane.XAxis = new Vector3d(0, -1, 0); plane.YAxis = new Vector3d(-1, 0, 0); plane.ZAxis = new Vector3d(0, 0, -1); plane.Origin = origin; plane.ClosestParameter(origin, out u, out v); ext1 = new Point2d(u, v); plane.ClosestParameter(offset, out u, out v); ext2 = new Point2d(u, v); plane.ClosestParameter(pt, out u, out v); linePt = new Point2d(u, v); dimension = new LinearDimension(plane, ext1, ext2, linePt); dimGuid = doc.Objects.AddLinearDimension(dimension); guidList.Add(dimGuid); // Add vertical dimension for panel origin = new Point3d(panelX0, panelY0, 0); offset = new Point3d(panelX0, borderY0, 0); pt = new Point3d(panelX0 - (dimStyle.TextHeight * 2), (offset.Y - origin.Y) / 2, 0); plane = Plane.WorldXY; plane.XAxis = new Vector3d(0, -1, 0); plane.YAxis = new Vector3d(-1, 0, 0); plane.ZAxis = new Vector3d(0, 0, -1); plane.Origin = origin; plane.ClosestParameter(origin, out u, out v); ext1 = new Point2d(u, v); plane.ClosestParameter(offset, out u, out v); ext2 = new Point2d(u, v); plane.ClosestParameter(pt, out u, out v); linePt = new Point2d(u, v); dimension = new LinearDimension(plane, ext1, ext2, linePt); dimGuid = doc.Objects.AddLinearDimension(dimension); guidList.Add(dimGuid); origin = new Point3d(panelX0, panelY1, 0); offset = new Point3d(panelX0, borderY1, 0); pt = new Point3d(panelX0 - (dimStyle.TextHeight * 2), (offset.Y - origin.Y) / 2, 0); plane = Plane.WorldXY; plane.XAxis = new Vector3d(0, -1, 0); plane.YAxis = new Vector3d(-1, 0, 0); plane.ZAxis = new Vector3d(0, 0, -1); plane.Origin = origin; plane.ClosestParameter(origin, out u, out v); ext1 = new Point2d(u, v); plane.ClosestParameter(offset, out u, out v); ext2 = new Point2d(u, v); plane.ClosestParameter(pt, out u, out v); linePt = new Point2d(u, v); dimension = new LinearDimension(plane, ext1, ext2, linePt); dimGuid = doc.Objects.AddLinearDimension(dimension); guidList.Add(dimGuid); doc.Views.Redraw(); RhinoObject panelPerimeterObj = doc.Objects.Find(panel.Perimeter); // Select all objects on Perforation Layer Rhino.DocObjects.RhinoObject[] rhinoObjs = doc.Objects.FindByLayer(Properties.Settings.Default.PerforationLayerName); double tolerance = Properties.Settings.Default.Tolerance; Rhino.Geometry.Curve panelPerimeterCurve = panelPerimeterObj.Geometry as Rhino.Geometry.Curve; // If tool perforation layer is missing if (rhinoObjs == null) { // Select all objects on Perforation Layer rhinoObjs = doc.Objects.FindByLayer(Properties.Settings.Default.ToolHitLayerName); } if (Convert.ToBoolean(panel.DrawPerf) == true && rhinoObjs != null) { foreach (RhinoObject rhinoObj in rhinoObjs) { Rhino.Geometry.Curve testCurve = rhinoObj.Geometry as Rhino.Geometry.Curve; if (testCurve != null) { if (Curve.PlanarClosedCurveRelationship(panelPerimeterCurve, testCurve, Plane.WorldXY, tolerance) == RegionContainment.BInsideA) { guidList.Add(rhinoObj.Id); } } } } // Export the panel doc.Objects.UnselectAll(); doc.Objects.Select(panel.Perimeter); // Get all of the objects on the layer. If layername is bogus, you will // just get an empty list back Rhino.DocObjects.RhinoObject label = doc.Objects.Find(panel.Label); string exportFileName = "1"; if (label != null) { label.Select(true); Rhino.Geometry.TextEntity textentity = label.Geometry as Rhino.Geometry.TextEntity; exportFileName = textentity.Text + ".dxf"; } // Select all objects on DOTS Layer rhinoObjs = doc.Objects.FindByLayer("DOTS"); tolerance = Properties.Settings.Default.Tolerance; panelPerimeterCurve = panelPerimeterObj.Geometry as Rhino.Geometry.Curve; if (rhinoObjs != null) { foreach (RhinoObject rhinoObj in rhinoObjs) { Rhino.Geometry.Curve testCurve = rhinoObj.Geometry as Rhino.Geometry.Curve; if (testCurve != null) { if (Curve.PlanarClosedCurveRelationship(panelPerimeterCurve, testCurve, Plane.WorldXY, tolerance) == RegionContainment.BInsideA) { rhinoObj.Select(true); } } } } // Select all objects on Tool Hit rhinoObjs = doc.Objects.FindByLayer(Properties.Settings.Default.ToolHitLayerName); if (rhinoObjs == null) { rhinoObjs = doc.Objects.FindByLayer(Properties.Settings.Default.PerforationLayerName); } if (rhinoObjs != null) { foreach (RhinoObject rhinoObj in rhinoObjs) { Rhino.Geometry.Curve testCurve = rhinoObj.Geometry as Rhino.Geometry.Curve; if (testCurve != null) { if (Curve.PlanarClosedCurveRelationship(panelPerimeterCurve, testCurve, Plane.WorldXY, tolerance) == RegionContainment.BInsideA) { rhinoObj.Select(true); } } } } string command = string.Format("-_Export \"" + Path.GetDirectoryName(doc.Path) + @"\" + exportFileName + "\" Scheme \"R12 Lines & Arcs\" Enter"); // Export the selected curves RhinoApp.RunScript(command, true); // Unselect all objects doc.Objects.UnselectAll(); // Default layer index int defaultLayerIndex = doc.Layers.Find("Default", true); doc.Layers.SetCurrentLayerIndex(layerIndex, true); if (Convert.ToBoolean(panel.DrawPerf) != true) { // Delete the Perforation layer as it consumes too much memory // Create a new layer called DIMENSION layerName = "PERFORATION"; // Does a layer with the same name already exist? layerIndex = doc.Layers.Find(layerName, true); // Get all of the objects on the layer. If layername is bogus, you will // just get an empty list back Rhino.DocObjects.RhinoObject[] rhobjs = doc.Objects.FindByLayer(layerName); if (rhobjs != null) { if (rhobjs.Length > 0) { for (int i = 0; i < rhobjs.Length; i++) { doc.Objects.Delete(rhobjs[i], true); } } } doc.Layers.Delete(layerIndex, true); } foreach (Guid g in guidList) { int idx = RhinoDoc.ActiveDoc.Groups.Find(panel.PartName, false); if (idx < 0) { idx = RhinoDoc.ActiveDoc.Groups.Add(panel.PartName); } RhinoDoc.ActiveDoc.Groups.AddToGroup(idx, g); } }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { var myTypes = ObjectType.AnyObject ^ ObjectType.BrepLoop; //pick objects to expand Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select objects to scale"); go.GeometryFilter = myTypes; //go.GroupSelect = true; go.SubObjectSelect = true; //go.EnableClearObjectsOnEntry(false); //go.EnableUnselectObjectsOnExit(false); //go.DeselectAllBeforePostSelect = false; go.GetMultiple(1, 0); //Compute center Point3d centersAdd = new Point3d(); for (int i = 0; i < go.ObjectCount; i++) { BoundingBox bbObj = go.Object(i).Geometry().GetBoundingBox(true); Point3d bbObjCenter = bbObj.Center; centers.Add(bbObjCenter); centersAdd += bbObjCenter; Rhino.DocObjects.ObjRef objref = go.Object(i); // get selected surface object Rhino.DocObjects.RhinoObject obj = objref.Object(); dynRef.Add(objref); } Point3d allCenter = centersAdd / centers.Count; //pick center GetPoint gp = new GetPoint(); gp.SetCommandPrompt("Basepoint. Press Enter for automatic."); gp.AcceptNothing(true); var resgp = gp.Get(); if (resgp == GetResult.Nothing) { scaleCenter = allCenter; } else { scaleCenter = gp.Point(); } Rhino.Display.RhinoView view = gp.View(); plane2D = view.ActiveViewport.ConstructionPlane(); //Expansion factor GetPoint gp2 = new GetPoint(); gp2.SetCommandPrompt("Scale factor or first reference point <" + factor + ">"); gp2.DrawLineFromPoint(scaleCenter, true); gp2.AcceptNumber(true, true); GetResult gr = gp2.Get(); if (gr == GetResult.Number) { factor = gp2.Number(); } if (gr == GetResult.Point) { scaleRefPoint = gp2.Point(); Line line1 = new Line(scaleCenter, scaleRefPoint); Guid tempLine = doc.Objects.AddLine(line1); Guid tempPoint = doc.Objects.AddPoint(scaleRefPoint); if (scaleCenter == gp2.Point()) { return(Rhino.Commands.Result.Cancel); } GetPoint gp3 = new GetPoint(); gp3.SetCommandPrompt("Secondt reference point"); gp3.AddOptionList("ScaleDimension", dimensions, 0); gp3.DrawLineFromPoint(scaleCenter, true); gp3.DynamicDraw += RefObjDraw; while (true) { GetResult res = gp3.Get(); if (res == GetResult.Option) { dimensionIndex = gp3.Option().CurrentListOptionIndex; continue; } else if (res == GetResult.Point) { Point3d scaleRefPoint2 = gp3.Point(); factor = (scaleCenter.DistanceTo(scaleRefPoint2)) / (scaleCenter.DistanceTo(scaleRefPoint)); doc.Objects.Delete(tempLine, true); doc.Objects.Delete(tempPoint, true); } break; } } RhinoApp.WriteLine("Scale factor: " + factor); //Compute translation //Translate 3d if (dimensionIndex == 0) { for (int i = 0; i < go.ObjectCount; i++) { var xform = Transform.Scale(centers[i], factor); var objref = go.Object(i); var brep = objref.Brep(); var index = objref.GeometryComponentIndex.Index; if (index > 0) { brep.TransformComponent(new[] { objref.GeometryComponentIndex }, xform, doc.ModelAbsoluteTolerance, 0, true); doc.Objects.Replace(objref.ObjectId, brep); } else { doc.Objects.Transform(go.Object(i), xform, true); } } } //Translate 2d else if (dimensionIndex == 1) { for (int i = 0; i < go.ObjectCount; i++) { plane2D.Origin = centers[i]; var xform = Rhino.Geometry.Transform.Scale(plane2D, factor, factor, 1); var objref = go.Object(i); var brep = objref.Brep(); var index = objref.GeometryComponentIndex.Index; if (index > 0) { brep.TransformComponent(new[] { objref.GeometryComponentIndex }, xform, doc.ModelAbsoluteTolerance, 0, true); doc.Objects.Replace(objref.ObjectId, brep); } else { doc.Objects.Transform(go.Object(i), xform, true); } } } //Translate 1d else if (dimensionIndex == 2) { for (int i = 0; i < go.ObjectCount; i++) { Vector3d vec = (scaleRefPoint - scaleCenter); Plane scalePlane = new Plane(centers[i], vec); var xform = Transform.Scale(scalePlane, 1, 1, factor); var objref = go.Object(i); var brep = objref.Brep(); var index = objref.GeometryComponentIndex.Index; if (index > 0) { brep.TransformComponent(new[] { objref.GeometryComponentIndex }, xform, doc.ModelAbsoluteTolerance, 0, true); doc.Objects.Replace(objref.ObjectId, brep); } else { doc.Objects.Transform(go.Object(i), xform, true); } } } centers = new List <Point3d>(); dimensionIndex = 0; plane2D = new Plane(); dynRef = new List <Rhino.DocObjects.ObjRef>(); doc.Views.Redraw(); return(Result.Success); }
/// <summary> /// Override to provide fancy object filtering /// </summary> public override bool CustomGeometryFilter(RhinoObject rhObject, GeometryBase geometry, ComponentIndex componentIndex) { return SampleCsRectangleHelper.IsRectangle(geometry); }
private bool GetCircle(RhinoObject rhObj, ref Circle circle) { var rc = false; if (null != rhObj) { var curve_obj = rhObj as CurveObject; if (null != curve_obj) { var arc_curve = curve_obj.CurveGeometry as ArcCurve; if (null != arc_curve && arc_curve.IsCompleteCircle) { circle = new Circle(arc_curve.Arc); rc = true; } } } return rc; }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { double tolerance = doc.ModelAbsoluteTolerance; List <Curve> icur = new List <Curve>(); GetObject gcr = new Rhino.Input.Custom.GetObject(); gcr.SetCommandPrompt("Select reference circles for stones. (No curves)"); gcr.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; gcr.GroupSelect = true; gcr.SubObjectSelect = true; gcr.DeselectAllBeforePostSelect = true; gcr.OneByOnePostSelect = false; gcr.GetMultiple(1, 0); for (int ie = 0; ie < gcr.ObjectCount; ie++) { Rhino.DocObjects.ObjRef objref = gcr.Object(ie); Rhino.DocObjects.RhinoObject obj = objref.Object(); if (obj == null) { return(Result.Failure); } Curve refcr = objref.Curve(); if (refcr == null) { return(Result.Failure); } obj.Select(false); icur.Add(refcr); } var rm = FindMaterial(doc, "Diamond"); if (null == rm) { //Didn't find the material - create one and carry on. //Create a basic material var custom = new Rhino.DocObjects.Material(); custom.Reflectivity = 1; custom.Transparency = 0.2; custom.SetEnvironmentTexture(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/Free Jewels Rhino Plug-Ins/Dia3.jpg"); custom.Name = "Diamond"; custom.CommitChanges(); rm = RenderMaterial.CreateBasicMaterial(custom); var docMats = doc.RenderMaterials; //docMats.BeginChange(RenderContent.ChangeContexts.Program); docMats.Add(rm); //docMats.EndChange(); } // Create Stone Mesh Rhino.Geometry.Mesh mesh = new Rhino.Geometry.Mesh(); mesh.Vertices.Add(0.0, 0.0, -0.44); //0 mesh.Vertices.Add(0.0, 0.097, -0.363); //1 mesh.Vertices.Add(0.069, 0.069, -0.363); //2 mesh.Vertices.Add(0.097, 0.0, -0.363); //3 mesh.Vertices.Add(0.0, 0.5, -0.013); //4 mesh.Vertices.Add(0.098, 0.49, -0.005); //5 mesh.Vertices.Add(0.191, 0.462, -0.013); //6 mesh.Vertices.Add(0.278, 0.416, -0.005); //7 mesh.Vertices.Add(0.354, 0.354, -0.013); //8 mesh.Vertices.Add(0.416, 0.278, -0.005); //9 mesh.Vertices.Add(0.462, 0.191, -0.013); //10 mesh.Vertices.Add(0.49, 0.098, -0.005); //11 mesh.Vertices.Add(0.5, 0.0, -0.013); //12 mesh.Vertices.Add(0.0, 0.5, 0.013); //13 mesh.Vertices.Add(0.098, 0.49, 0.005); //14 mesh.Vertices.Add(0.191, 0.462, 0.013); //15 mesh.Vertices.Add(0.278, 0.416, 0.005); //16 mesh.Vertices.Add(0.354, 0.354, 0.013); //17 mesh.Vertices.Add(0.416, 0.278, 0.005); //18 mesh.Vertices.Add(0.462, 0.191, 0.013); //19 mesh.Vertices.Add(0.49, 0.098, 0.005); //20 mesh.Vertices.Add(0.5, 0.0, 0.013); //21 mesh.Vertices.Add(0.0, 0.372, 0.12); //22 mesh.Vertices.Add(0.263, 0.263, 0.12); //23 mesh.Vertices.Add(0.372, 0.0, 0.12); //24 mesh.Vertices.Add(0.263, -0.263, 0.12); //25 mesh.Vertices.Add(0.0, -0.372, 0.12); //26 mesh.Vertices.Add(-0.263, -0.263, 0.12); //27 mesh.Vertices.Add(-0.372, 0.0, 0.12); //28 mesh.Vertices.Add(-0.263, 0.263, 0.12); //29 mesh.Vertices.Add(0.109, 0.263, 0.16); //30 mesh.Vertices.Add(0.263, 0.109, 0.16); //31 mesh.Vertices.Add(0.263, -0.109, 0.16); //32 mesh.Vertices.Add(0.109, -0.263, 0.16); //33 mesh.Vertices.Add(-0.109, -0.263, 0.16); //34 mesh.Vertices.Add(-0.263, -0.109, 0.16); //35 mesh.Vertices.Add(-0.263, 0.109, 0.16); //36 mesh.Vertices.Add(-0.109, 0.263, 0.16); //37 mesh.Vertices.Add(0.0, 0.0, 0.16); //38 mesh.Faces.AddFace(0, 1, 6, 2); mesh.Faces.AddFace(0, 2, 10, 3); mesh.Faces.AddFace(1, 4, 5, 6); mesh.Faces.AddFace(2, 6, 7, 8); mesh.Faces.AddFace(2, 8, 9, 10); mesh.Faces.AddFace(3, 10, 11, 12); mesh.Faces.AddFace(4, 13, 14, 5); mesh.Faces.AddFace(5, 14, 15, 6); mesh.Faces.AddFace(6, 15, 16, 7); mesh.Faces.AddFace(7, 16, 17, 8); mesh.Faces.AddFace(8, 17, 18, 9); mesh.Faces.AddFace(9, 18, 19, 10); mesh.Faces.AddFace(10, 19, 20, 11); mesh.Faces.AddFace(11, 20, 21, 12); mesh.Faces.AddFace(13, 22, 15, 14); mesh.Faces.AddFace(15, 23, 17, 16); mesh.Faces.AddFace(17, 23, 19, 18); mesh.Faces.AddFace(19, 24, 21, 20); mesh.Faces.AddFace(15, 22, 30, 23); mesh.Faces.AddFace(19, 23, 31, 24); mesh.Faces.AddFace(23, 30, 31); mesh.Faces.AddFace(24, 31, 32); mesh.Faces.AddFace(32, 31, 30, 38); mesh.Unweld(0.001, false); Mesh meshAll = new Mesh(); for (int i = 0; i < 4; i++) { meshAll.Append(mesh); Point3d center = new Point3d(0.0, 0.0, 0.0); Vector3d rotVec = new Vector3d(0.0, 0.0, 1.0); mesh.Rotate(Math.PI / 2, rotVec, center); } meshAll.Compact(); meshAll.Weld(0.001); //Get object Guid to apply render material var meshGuid = doc.Objects.AddMesh(meshAll); ObjRef objre = new ObjRef(meshGuid); RhinoObject obje = objre.Object(); obje.RenderMaterial = rm; obje.CommitChanges(); //Make InstanceDefinition string instDefCount = DateTime.Now.ToString("ddMMyyyyHHmmss"); var geometry = new System.Collections.Generic.List <Rhino.Geometry.GeometryBase>() { obje.Geometry }; var attributes = new System.Collections.Generic.List <Rhino.DocObjects.ObjectAttributes>() { obje.Attributes }; var stoneIndex = doc.InstanceDefinitions.Add("Stone" + instDefCount, "StoneMesh 1mm", Point3d.Origin, geometry, attributes); List <InstanceReferenceGeometry> meshPave = new List <InstanceReferenceGeometry>(); foreach (Curve c in icur) { Circle circle1 = new Circle(); c.TryGetCircle(out circle1, tolerance); double radius = circle1.Diameter; Point3d center = circle1.Center; Vector3d moveV = new Vector3d(center); Vector3d zaxis = new Vector3d(0.0, 0.0, 1.0); Plane planeOr = new Plane(center, zaxis); Plane planeNew = circle1.Plane; var transform1 = Transform.Translation(moveV); var transform2 = Transform.Scale(center, radius); var transform3 = Transform.PlaneToPlane(planeOr, planeNew); var stoneA = doc.Objects.AddInstanceObject(stoneIndex, transform1); var stoneB = doc.Objects.Transform(stoneA, transform2, true); var stoneC = doc.Objects.Transform(stoneB, transform3, true); ids.Add(stoneC); } doc.Groups.Add(ids); doc.Objects.Delete(obje); doc.Views.Redraw(); return(Result.Success); }
internal static RhinoObject CreateRhinoObjectHelper(IntPtr pRhinoObject) { if (IntPtr.Zero == pRhinoObject) return null; uint sn = UnsafeNativeMethods.CRhinoObject_RuntimeSN(pRhinoObject); if (sn < 1) return null; int type = UnsafeNativeMethods.CRhinoRhinoObject_GetRhinoObjectType(pRhinoObject); if (type < 0) return null; RhinoObject rc; switch (type) { case idxCRhinoPointObject: //1 rc = new PointObject(sn); break; case idxCRhinoCurveObject: //2 rc = new CurveObject(sn); break; case idxCRhinoMeshObject: //3 rc = new MeshObject(sn); break; case idxCRhinoBrepObject: //4 rc = new BrepObject(sn); break; case idxCRhinoPointCloudObject: //5 rc = new PointCloudObject(sn); break; case idxCRhinoAnnotationTextObject: //6 rc = new TextObject(sn); break; case idxCRhinoSurfaceObject: //7 rc = new SurfaceObject(sn); break; case idxCRhinoInstanceObject: //8 rc = new InstanceObject(sn); break; case idxCRhinoHatchObject: //9 rc = new HatchObject(sn); break; case idxCRhinoDetailViewObject: //10 rc = new DetailViewObject(sn); break; case idxCRhinoClippingPlaneObject: //11 rc = new ClippingPlaneObject(sn); break; case idxCRhinoTextDot: //12 rc = new TextDotObject(sn); break; case idxCRhinoGripObject: //13 rc = new GripObject(sn); break; #if USING_V5_SDK case idxCRhinoExtrusionObject: //14 rc = new ExtrusionObject(sn); break; #endif case idxCRhinoLinearDimension: //15 rc = new LinearDimensionObject(sn); break; case idxCRhinoAnnotationObject: //16 rc = new AnnotationObjectBase(sn); break; case idxCRhinoLight: //17 rc = new LightObject(sn); break; case idxCRhinoMorphControl: //18 rc = new MorphControlObject(sn); break; case idxCRhinoRadialDimension: //19 rc = new RadialDimensionObject(sn); break; case idxCRhinoAngularDimension: //20 rc = new AngularDimensionObject(sn); break; default: rc = new RhinoObject(sn); break; } return rc; }
// Marked as internal, RhinoObject.GetRenderPrimitiveList will create one // but there is currently no reason for anyone else to make one. internal RenderPrimitiveList(RhinoObject obj) { m_ptr_custom_render_meshes = UnsafeNativeMethods.Rdk_CustomMeshes_New(obj.ConstPointer()); }
internal ObjectAttributes(RhinoObject parentObject) { ConstructConstObject(parentObject, -1); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { List <Rhino.Geometry.Mesh> meshes = new List <Rhino.Geometry.Mesh>(); try { string ogre_bin = System.Environment.GetEnvironmentVariable("OGRE_HOME"); #if DEBUG ogre_bin += @"\bin\Debug"; #else ogre_bin += @"\bin\Release"; #endif string path = System.Environment.GetEnvironmentVariable("PATH"); System.Environment.SetEnvironmentVariable("PATH", path + ";" + ogre_bin, EnvironmentVariableTarget.Process); Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); OptionToggle export_as_xml = new OptionToggle(false, "No", "Yes"); go.AddOptionToggle("export_as_xml", ref export_as_xml); go.SetCommandPrompt("Select surfaces, polysurfaces, or meshes"); go.GeometryFilter = geometryFilter; go.GroupSelect = true; go.SubObjectSelect = false; go.EnableClearObjectsOnEntry(false); go.EnableUnselectObjectsOnExit(false); go.DeselectAllBeforePostSelect = false; bool bHavePreselectedObjects = false; for (; ;) { Rhino.Input.GetResult res = go.GetMultiple(1, 0); if (res == Rhino.Input.GetResult.Option) { go.EnablePreSelect(false, true); continue; } else if (res != Rhino.Input.GetResult.Object) { RhinoLogger.Info("Canceled."); return(Rhino.Commands.Result.Cancel); } if (go.ObjectsWerePreselected) { bHavePreselectedObjects = true; go.EnablePreSelect(false, true); continue; } break; } SaveFileDialog sv = new SaveFileDialog(); if (!export_as_xml.CurrentValue) { sv.Filter = "Mesh files (*.mesh)|*.mesh"; sv.DefaultExt = "mesh"; } else { sv.Filter = "XML files (*.xml)|*.xml"; sv.DefaultExt = "xml"; } sv.Title = "Select File to Export :"; if (sv.ShowDialog() != System.Windows.Forms.DialogResult.OK) { RhinoLogger.Info("Canceled."); return(Result.Cancel); } if (bHavePreselectedObjects) { // Normally when command finishes, pre-selected objects will remain // selected, when and post-selected objects will be unselected. // With this sample, it is possible to have a combination of // pre-selected and post-selected objects. To make sure everything // "looks the same", unselect everything before finishing the command. for (int i = 0; i < go.ObjectCount; i++) { Rhino.DocObjects.RhinoObject rhinoObject = go.Object(i).Object(); if (null != rhinoObject) { rhinoObject.Select(false); } } doc.Views.Redraw(); } int objectCount = go.ObjectCount; Rhino.RhinoApp.WriteLine("Select object count = {0}", objectCount); for (int i = 0; i < objectCount; i++) { var objref = go.Object(i); if (objref.Geometry().ObjectType == Rhino.DocObjects.ObjectType.Mesh) { meshes.Add(objref.Mesh()); } else if (objref.Geometry().ObjectType == Rhino.DocObjects.ObjectType.Brep) { var ms = CheckOrCreateMesh(objref.Brep(), RhinoDoc.ActiveDoc.GetMeshingParameters(MeshingParameterStyle.Custom)); meshes.AddRange(ms); } else { RhinoLogger.ErrorFormat("selection is unexpected ObjectType : {0}", objref.Geometry().ObjectType); return(Result.Failure); } } var exporter = new ExportToOgreMesh(); var exp_path = exporter.Export(sv.FileName, meshes); if (!export_as_xml.CurrentValue) { exporter.ConvertXmlToMesh(exp_path); } } catch (Exception e) { RhinoLogger.Fatal(e); return(Result.Failure); } return(Result.Success); }