public static void CopyObjects(RhinoDoc doc, Layer OldLayer, Layer NewLayer, out List <RhinoObject> rhObjList) { // copy objects from old layer to new layer ObjectType type = ObjectType.Brep; rhObjList = new List <RhinoObject>(); List <RhinoObject> rhObjList0 = doc.Objects.FindByLayer(OldLayer).ToList(); // rhObjList= doc.Objects.FindByObjectType(type).ToList(); // rhObjList = doc.Objects.GetObjectList(type).ToList(); foreach (RhinoObject obj in rhObjList0) { if (type == obj.ObjectType) { Guid Duplicates = doc.Objects.Transform(obj.Id, Transform.Identity, false); RhinoObject rhobj = doc.Objects.Find(Duplicates); if (Duplicates != null) { rhobj.Attributes.LayerIndex = NewLayer.LayerIndex; rhobj.CommitChanges(); } rhObjList.Add(rhobj); } } }
public static void DecomposeObj_Invalid(RhinoDoc doc, Layer layer, RhinoObject obj, Brep brep, ref int progressCurrentIndex, ref int progressShowedPercent, int progressMax, bool beforeFixAllIssues, int objsInLayerCount = -1) { var newLayerIndex = GetNewLayer(doc, layer, obj, beforeFixAllIssues); var newlayer = doc.Layers[newLayerIndex]; //var savedCurrentIndex = doc.Layers.CurrentLayerIndex; //doc.Layers.SetCurrentLayerIndex(newLayerIndex, true); try { //var objsbefore = doc.Objects.FindByLayer(layer); //var map = new Dictionary<uint, bool>(); //foreach (var o in objsbefore) //{ // map[o.RuntimeSerialNumber] = true; //} // move obj to new layer obj.Attributes.LayerIndex = newLayerIndex; obj.CommitChanges(); // explode it doc.Objects.UnselectAll(); doc.Objects.Select(obj.Id); if (RhinoApp.RunScript("_Explode", false)) { var objsnow = doc.Objects.FindByLayer(newlayer); objsInLayerCount = objsnow.Length; int index = 0; int nameLength = 1; if (objsInLayerCount >= 10) { nameLength = 2; } if (objsInLayerCount >= 100) { nameLength = 3; } if (objsInLayerCount >= 1000) { nameLength = 4; } if (objsInLayerCount >= 10000) { nameLength = 5; } foreach (var newobj in objsnow) { index++; newobj.Attributes.Name = index.ToString("D" + nameLength); newobj.CommitChanges(); } Shared.SharedCommands.Execute(SharedCommandsEnum.ST_UpdateGeomNames); } progressCurrentIndex += brep.Faces.Count; } finally { doc.Objects.UnselectAll(); //doc.Layers.SetCurrentLayerIndex(savedCurrentIndex, true); } }
/// <summary> /// Remap the Z Axis of a prop from Rhino Y to Rhino Z /// </summary> /// <param name="obj"></param> private static bool RemapPropAxis(RhinoObject obj) { // Rotate geometry around x axis obj.Geometry.Transform(Transform.Rotation(Math.PI / 2.0, Vector3d.XAxis, Point3d.Origin)); // commit changes return(obj.CommitChanges()); }
public static void DrawObjectHighlighted(this DisplayPipeline display, RhinoObject rhinoObject, Transform xForm) { // get old color and color source var objColor = rhinoObject.Attributes.ObjectColor; var objColorSource = rhinoObject.Attributes.ColorSource; // modify rhinoObject.Attributes.ObjectColor = Rhino.ApplicationSettings.AppearanceSettings.SelectedObjectColor; rhinoObject.Attributes.ColorSource = ObjectColorSource.ColorFromObject; rhinoObject.CommitChanges(); // draw display.DrawObject(rhinoObject, xForm); // restore old settings rhinoObject.Attributes.ObjectColor = objColor; rhinoObject.Attributes.ColorSource = objColorSource; rhinoObject.CommitChanges(); }
public override bool RestoreObject(RhinoDoc doc, RhinoObject doc_object, ref Transform transform, BinaryArchiveReader archive) { Rhino.Collections.ArchivableDictionary userdata = archive.ReadDictionary(); string name = ""; if (userdata.TryGetString("ObjName", out name)) { doc_object.Attributes.Name = name; doc_object.CommitChanges(); } return(!archive.ReadErrorOccured); }
/// <summary> /// Set the name of an object /// </summary> /// <param name="objID"></param> /// <param name="name"></param> /// <returns></returns> public static bool SetObjectName(Guid objID, string name) { RhinoObject rObj = GetObject(objID); if (rObj != null) { rObj.Attributes.Name = name; return(rObj.CommitChanges()); } else { return(false); } }
/// <summary> /// Set the layer of the specified object /// </summary> /// <param name="objID"></param> /// <param name="layerID"></param> /// <param name="commit"></param> /// <returns></returns> public static bool SetObjectLayer(Guid objID, int layerID, bool commit = true) { RhinoObject rObj = GetObject(objID); if (rObj != null) { rObj.Attributes.LayerIndex = layerID; if (commit) { rObj.CommitChanges(); } return(true); } return(false); }
public static bool _Purge(this ObjectTable objects, RhinoObject obj) { if (obj == null || objects == null) { return(false); } // for successful removal object must be visible if (obj.Attributes.Visible == false) { obj.Attributes.Visible = true; obj.CommitChanges(); } bool removed = objects.Purge(obj); // if we can't remove - at least hide it if (!removed) { //var IsDocumentControlled = obj.Attributes.IsDocumentControlled; //var IsInstanceDefinitionObject = obj.Attributes.IsInstanceDefinitionObject; //var mode = obj.Attributes.Mode; //var name = obj.Attributes.Name; //var GroupCount = obj.Attributes.GroupCount; //removed = objects.Purge(obj); //var deleted = objects.Delete(obj.Id, true); //var selectable = obj.IsSelectable(); //obj.Attributes.RemoveDisplayModeOverride(); //obj.CommitChanges(); //obj.Attributes.Mode = ObjectMode.Hidden; //obj.Attributes.RemoveFromAllGroups(); obj.Attributes.Visible = false; obj.CommitChanges(); } return(removed); }
public static bool _Delete(this ObjectTable objects, RhinoObject obj) { if (obj == null || objects == null) { return(false); } // for successful removal object must be visible if (obj.Attributes.Visible == false) { obj.Attributes.Visible = true; obj.CommitChanges(); } var deleted = objects.Delete(obj, true); // if we can't delete - at least hide it if (!deleted) { obj.Attributes.Visible = false; obj.CommitChanges(); log.wrong("Failed to delete object SN={0}", obj.RuntimeSerialNumber); } return(deleted); }
/// <summary> /// Hide the given object so that it cannot be seen /// </summary> /// <param name="objID"></param> /// <param name="value">If true, hide, if false, unhide</param> public static void HideObject(Guid objID, bool value = true, bool commit = true) { RhinoObject rObj = GetObject(objID); if (rObj != null) { if (value) { rObj.Attributes.Mode = ObjectMode.Hidden; } else { rObj.Attributes.Mode = ObjectMode.Normal; } if (commit) { rObj.CommitChanges(); } } }
public static Result GetFloors(RhinoDoc rhinoDocument) { ObjRef[] objRefArray; Result multipleObjects = RhinoGet.GetMultipleObjects("Please select surfaces", false, (ObjectType)2097160, out objRefArray); if (multipleObjects != null) { return(multipleObjects); } if (objRefArray == null || objRefArray.Length < 1) { return((Result)3); } string str = "#VR User Defined Floors"; int num = rhinoDocument.Layers.Find(str, true); if (num < 0) { LayerTable layers = rhinoDocument.Layers; num = layers.Add(str, Color.Black); if (num < 0) { RhinoApp.WriteLine("Unable to add <{0}> layer.", (object)str); return((Result)3); } Layer layer = layers[num]; layer.Color = (Color.Blue); layer.CommitChanges(); } for (int index = 0; index < objRefArray.Length; ++index) { RhinoObject rhinoObject = objRefArray[index].Object(); rhinoObject.Attributes.LayerIndex = num; rhinoObject.CommitChanges(); } rhinoDocument.Views.Redraw(); return((Result)0); }
public void drawBlock(RhinoDoc doc, string labelName, string area, int panelNum, PerforationPanel panel, int panelQty) { RhinoUtilities.SetActiveLayer("LAYOUT DETAILS", System.Drawing.Color.Black); //// Get the location of current API //String path = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Logo\\MetrixLogo.jpg"; //Plane picture = new Plane(new Point3d(5, 10, 0), new Vector3d(0, 0, 1)); //// Add Company logo. //doc.Objects.AddPictureFrame(picture, path, false, 62.5, 25, false, false); // Draw bottom line doc.Objects.AddLine(new Point3d(5, 5, 0), new Point3d(205, 5, 0)); // Top line doc.Objects.AddLine(new Point3d(5, 292, 0), new Point3d(205, 292, 0)); // Left line doc.Objects.AddLine(new Point3d(5, 5, 0), new Point3d(5, 292, 0)); // Right line doc.Objects.AddLine(new Point3d(205, 5, 0), new Point3d(205, 292, 0)); //// Divider line //doc.Objects.AddLine(new Point3d(5, 10, 0), new Point3d(205, 10, 0)); //// Row 1 line //doc.Objects.AddLine(new Point3d(67.5, 15, 0), new Point3d(205, 15, 0)); //// Row 2 line //doc.Objects.AddLine(new Point3d(67.5, 20, 0), new Point3d(205, 20, 0)); //// Row 3 line //doc.Objects.AddLine(new Point3d(67.5, 25, 0), new Point3d(205, 25, 0)); //// Row 4 line //doc.Objects.AddLine(new Point3d(67.5, 30, 0), new Point3d(205, 30, 0)); //// Row 5 line //doc.Objects.AddLine(new Point3d(67.5, 35, 0), new Point3d(205, 35, 0)); //// Vertical divider line //doc.Objects.AddLine(new Point3d(136.5, 5, 0), new Point3d(136.5, 35, 0)); //// Vertical divider line //doc.Objects.AddLine(new Point3d(87.5, 10, 0), new Point3d(87.5, 35, 0)); //// Vertical divider line //doc.Objects.AddLine(new Point3d(156.5, 10, 0), new Point3d(156.5, 35, 0)); // Draw Approval Box // Horizontal lines //doc.Objects.AddLine(new Point3d(136.5, 40, 0), new Point3d(200, 40, 0)); //doc.Objects.AddLine(new Point3d(136, 39.5, 0), new Point3d(200.5, 39.5, 0)); //doc.Objects.AddLine(new Point3d(136.5, 45, 0), new Point3d(200, 45, 0)); //doc.Objects.AddLine(new Point3d(136.5, 55, 0), new Point3d(200, 55, 0)); //doc.Objects.AddLine(new Point3d(136.5, 60, 0), new Point3d(200, 60, 0)); //doc.Objects.AddLine(new Point3d(136.5, 65, 0), new Point3d(200, 65, 0)); //doc.Objects.AddLine(new Point3d(136, 65.5, 0), new Point3d(200.5, 65.5, 0)); //// Vertical lines //doc.Objects.AddLine(new Point3d(136, 39.5, 0), new Point3d(136, 65.5, 0)); //doc.Objects.AddLine(new Point3d(136.5, 40, 0), new Point3d(136.5, 65, 0)); //doc.Objects.AddLine(new Point3d(156.5, 40, 0), new Point3d(156.5, 60, 0)); //doc.Objects.AddLine(new Point3d(200, 40, 0), new Point3d(200, 65, 0)); //doc.Objects.AddLine(new Point3d(200.5, 39.5, 0), new Point3d(200.5, 65.5, 0)); Rhino.Geometry.Point3d pt = new Rhino.Geometry.Point3d(11, 15, 0); string text = "51 Holloway Drive metrixgroup.com.au\nBayswater VIC 3153 1300 792 493"; double height = 3.5; string font = "Arial"; Rhino.Geometry.Plane plane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane(); plane.Origin = pt; Guid id; //XXX: This has been turned off due to a request by Keyur(Confirmed with Ross) //if (panel.FixingHoles == "1") //Add this text only if there are fixing holes //{ // pt = new Rhino.Geometry.Point3d(43, 45, 0); // text = "Fixing Holes Diameter : " + panel.HoleDiameter + " and Centers Approximated at : "+panel.FixingHoleCentres; // height = 2.3; // font = "Arial"; // plane.Origin = pt; // id = doc.Objects.AddText(text, plane, height, font, false, false); //} //if (panel.DrawPerf != 3) //If draw perf is not solid panel //{ // //MetrixUtilities.createMetrixBordersDimension(); // //pt = new Rhino.Geometry.Point3d(43, 65, 0); // //text = "Pattern: " + panel.PatternName; // //height = 2.3; // //font = "Arial"; // //plane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane(); // //plane.Origin = pt; // //id = doc.Objects.AddText(text, plane, height, font, false, false); // //pt = new Rhino.Geometry.Point3d(43, 55, 0); // //text = "Open Area: " + openArea + "%"; // //height = 2.3; // //font = "Arial"; // //plane.Origin = pt; // //id = doc.Objects.AddText(text, plane, height, font, false, false); //} //else //{ // pt = new Rhino.Geometry.Point3d(43, 65, 0); // text = "Solid Panel"; // height = 2.3; // font = "Arial"; // plane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane(); // plane.Origin = pt; // id = doc.Objects.AddText(text, plane, height, font, false, false); //} // id = doc.Objects.AddText(text, plane, height, font, false, false); //height = 1.5; //text = "Supply of this order will be solely and exlusively according to the terms and conditions of Metrix Group Pty Ltd."; //plane.Origin = new Point3d(7, 6, 0); //id = doc.Objects.AddText(text, plane, height, font, false, false); //height = 1.5; //text = "PANEL"; //plane.Origin = new Point3d(69, 31, 0); //id = doc.Objects.AddText(text, plane, height, font, false, false); height = 1.5; text = labelName; plane.Origin = new Point3d(89, 31 + height, 0); id = doc.Objects.AddText(text, plane, height, font, false, false); //text = "DRAWN"; //plane.Origin = new Point3d(69, 26, 0); //id = doc.Objects.AddText(text, plane, height, font, false, false); //Using reg pattern to split part name and extract the quantity //Regex re = new Regex(@"([a-zA-Z]+)(\d+)"); //Match result = re.Match(panel.PartName); //text = result.Groups[2].Value; text = "" + panel.PanelQuantity; //set the quantity for each panel plane.Origin = new Point3d(89, 21 + height, 0); id = doc.Objects.AddText(text, plane, height, font, false, false); //text = "m²"; //plane.Origin = new Point3d(69, 16, 0); //id = doc.Objects.AddText(text, plane, height, font, false, false); text = area; plane.Origin = new Point3d(89, 16 + height, 0); id = doc.Objects.AddText(text, plane, height, font, false, false); //text = "Page "; //plane.Origin = new Point3d(69, 11, 0); //id = doc.Objects.AddText(text, plane, height, font, false, false); text = panelNum + " of " + panelQty; plane.Origin = new Point3d(89, 11 + height, 0); id = doc.Objects.AddText(text, plane, height, font, false, false); //text = "PROJECT"; //plane.Origin = new Point3d(138, 31, 0); //id = doc.Objects.AddText(text, plane, height, font, false, false); //height = 1.5; //text = panelParas.Project; //plane.Origin = new Point3d(158, 31, 0); //id = doc.Objects.AddText(text, plane, height, font, false, false); //text = "CUSTOMER "; //plane.Origin = new Point3d(138, 26, 0); //id = doc.Objects.AddText(text, plane, height, font, false, false); //height = 1.5; //text = panelParas.CustomerName; //plane.Origin = new Point3d(158, 26, 0); //id = doc.Objects.AddText(text, plane, height, font, false, false); //text = "JOB NO."; //plane.Origin = new Point3d(138, 21, 0); //id = doc.Objects.AddText(text, plane, height, font, false, false); //height = 1.5; //text = panelParas.JobNo; //plane.Origin = new Point3d(158, 21, 0); //id = doc.Objects.AddText(text, plane, height, font, false, false); //text = "MATERIAL"; //plane.Origin = new Point3d(138, 16, 0); //id = doc.Objects.AddText(text, plane, height, font, false, false); //height = 1.5; //text = panelParas.Material; //plane.Origin = new Point3d(158, 16, 0); //id = doc.Objects.AddText(text, plane, height, font, false, false); //text = "COATING"; //plane.Origin = new Point3d(138, 11, 0); //id = doc.Objects.AddText(text, plane, height, font, false, false); //height = 1.5; //text = panelParas.Coating; //plane.Origin = new Point3d(158, 11, 0); //id = doc.Objects.AddText(text, plane, height, font, false, false); //text = "Copyright © Metrix Group " + DateTime.Today.Year; //plane.Origin = new Point3d(138, 6, 0); //id = doc.Objects.AddText(text, plane, height, font, false, false); //text = "APPROVED BY"; //plane.Origin = new Point3d(138, 61, 0); //id = doc.Objects.AddText(text, plane, height, font, false, false); //text = "NAME"; //plane.Origin = new Point3d(138, 56, 0); //id = doc.Objects.AddText(text, plane, height, font, false, false); //text = "SIGNATURE"; //plane.Origin = new Point3d(138, 51, 0); //id = doc.Objects.AddText(text, plane, height, font, false, false); //text = "DATE"; //plane.Origin = new Point3d(138, 41, 0); //id = doc.Objects.AddText(text, plane, height, font, false, false); if (panel.DotFontLabel == 1) { if (panel.DotFontLabellerSide.Equals("Rear")) { text = "* 9 mm Dot font labelling to the rear of all panels"; plane.Origin = new Point3d(136.392, 53.865 + height, 0.000); id = doc.Objects.AddText(text, plane, height, font, false, false); } else { text = "* 9 mm Dot font labelling to the front of all panels"; plane.Origin = new Point3d(136.392, 53.865 + height, 0.000); id = doc.Objects.AddText(text, plane, height, font, false, false); } } text = "** The purple line represents the unperforated distance" + "\nbetween the edge of the panel and the perforation"; plane.Origin = new Point3d(136.392, 48.865 + height, 0.000); id = doc.Objects.AddText(text, plane, height, font, false, false); text = "*** The border dimensions shown are minimum values.\n Actual borders will be ≥ those shown."; plane.Origin = new Point3d(136.284, 42.595 + height, 0.000); id = doc.Objects.AddText(text, plane, height, font, false, false); var parentlayerIndex = doc.Layers.Find("LAYERS FOR APPROVAL DRAWINGS", true); //get parent layer index // Draw the sample block createSubLayers.createSubLayer("COLOUR AND QUANTITY", System.Drawing.Color.Red, doc.Layers[parentlayerIndex]); //create layer called perf orientation (sublayer) if (panel.coating.Equals("Mill finish") || panel.coating.Equals("Mill Finish")) { text = "Quantity: " + panel.PanelQuantity + "\nColour: " + panel.coating; plane.Origin = new Point3d(102.148, 63.946 + height, 0.000); } else { text = "Quantity: " + panel.PanelQuantity + "\nColour: " + panel.colour; plane.Origin = new Point3d(102.204, 65.299 + height, 0.000); } height = 2.5; ObjectAttributes objAttributes = new ObjectAttributes(); objAttributes.ObjectColor = System.Drawing.Color.Red; objAttributes.ColorSource = ObjectColorSource.ColorFromObject; objAttributes.PlotColor = System.Drawing.Color.Red; objAttributes.PlotColorSource = Rhino.DocObjects.ObjectPlotColorSource.PlotColorFromObject; id = doc.Objects.AddText(text, plane, height, font, false, false, objAttributes); RhinoObject colorText = doc.Objects.Find(id); colorText.Attributes.LayerIndex = doc.Layers.Find("COLOUR AND QUANTITY", true); colorText.CommitChanges(); doc.Views.Redraw(); }
/// <summary> /// Assigns a <see cref="RenderMaterial"/> to a <see cref="RhinoObject"/> /// </summary> /// <param name="material"></param> /// <param name="obj"></param> private void AssignMaterialToObject(RenderMaterial material, RhinoObject obj) { obj.Attributes.MaterialSource = ObjectMaterialSource.MaterialFromObject; obj.RenderMaterial = material; obj.CommitChanges(); }
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); }
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(); }
// Confirm private void button1_Click(object sender, EventArgs e) { Layer NewLayer = new Layer(); Layer OldLayer = new Layer(); RhinoObject obj; string str; Nodes = nodeGroups[NodeMark[comboBox1.SelectedIndex]].ToList(); OldLayer = doc.Layers.CurrentLayer; if (flag == 0) { NewLayer.Name = "Function-FI"; doc.Layers.Add(NewLayer); NewLayer.LayerIndex = doc.Layers.FindByFullPath(NewLayer.Name, true); doc.Layers.SetCurrentLayerIndex(NewLayer.LayerIndex, true); NewLayer.IsVisible = true; NewLayer.CommitChanges(); for (int i = 0; i < Nodes.Count; i++) { obj = RhObjList[Nodes[i] - 1]; Guid Duplicates = doc.Objects.Transform(obj.Id, Transform.Identity, false); RhinoObject rhobj = doc.Objects.Find(Duplicates); if (rhobj != null) { rhobj.Attributes.LayerIndex = NewLayer.LayerIndex; rhobj.CommitChanges(); } } OldLayer.IsVisible = false; NewLayer.CommitChanges(); flag = 1; // initialize FVGroup info /*FVGroup.ID = GroupID; * FVGroup.GroupName = string.Format("Group{0}", GroupID); * FVGroup.FVSingle = new List<FunctionalVolPart>(); */ } OldLayer.CommitChanges(); doc.Views.Redraw(); string treev = "xxx"; treeView1.Nodes.Add(treev, string.Format("Group{0}", comboBox1.SelectedIndex + 1)); for (int i = 0; i < Nodes.Count; i++) { str = Nodes[i].ToString() + "-" + currProduct.parts[Nodes[i] - 1].Name; TreeNode node = treeView1.Nodes[treev].Nodes.Add(str); } treeView1.ExpandAll(); // Initialize ListofAllFunctionalInterface = new List <List <FunctionalInterface> >(Nodes.Count); for (int i = 0; i < Nodes.Count; i++) { ListofAllFunctionalInterface.Add(new List <FunctionalInterface>()); } NumberOfFIs = 0; }