protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // TODO: start here modifying the behaviour of your command. //Select objects try { GetObject go = new GetObject(); go.EnablePreSelect(true, true); go.EnablePostSelect(true); go.SetCommandPrompt("Super Split | Advanced Boolean Split:"); go.GetMultiple(1, 0); if (go.ObjectCount > 0) { RhinoApp.RunScript("_BooleanSplit", true); RhinoApp.RunScript("_SelLast", true); RhinoApp.RunScript("_MergeAllFaces", true); RhinoApp.RunScript("_ShrinkTrimmedSrf", true); } return(Result.Success); } catch { return(Result.Failure); } }
private void OnIdle(object sender, EventArgs e) { RhinoApp.Idle -= OnIdle; // unsubscribe string path = Rhino.PlugIns.PlugIn.PathFromName("rhinovault_V2"); string plugin_dir = Path.GetDirectoryName(path); string command_dir_1 = "compas_rv"; string command_dir_2 = "commands"; string command_path = Path.Combine(plugin_dir, command_dir_1); command_path = Path.Combine(command_path, command_dir_2); string[] files = System.IO.Directory.GetFiles(command_path, "*.py"); //delete aliases //Rhino.ApplicationSettings.CommandAliasList.Delete(alias_del); foreach (string filepath in files) { bool b = filepath.Contains("Rv"); if (b) { //RhinoApp.WriteLine(filepath); string alias = Path.GetFileNameWithoutExtension(filepath); string macro = "_Noecho _-RunPythonScript " + filepath; Rhino.ApplicationSettings.CommandAliasList.Add(alias, macro); } } //RhinoApp.RunScript("_-Line 0,0,0 10,10,10", false); //_Noecho string scr_dir = plugin_dir.Replace(@"\", @"\\"); string cmd = "_Noecho -_RunPythonScript (" + Environment.NewLine + "import sys" + Environment.NewLine + "import scriptcontext as sc" + Environment.NewLine + "path = " + "'" + scr_dir + "'" + Environment.NewLine + "sc.sticky['path'] = path" + Environment.NewLine + ")"; //RhinoApp.WriteLine(cmd); //"sys.path.append(path)" + //Environment.NewLine + //"print sys.path" + //Environment.NewLine + RhinoApp.RunScript(cmd, false); }
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); } }
// Makes speckle start on rhino startup. Perhaps this should be customisable? private void RhinoApp_Idle(object sender, System.EventArgs e) { RhinoApp.Idle -= RhinoApp_Idle; var bindings = new ConnectorBindingsRhino(); if (bindings.GetStreamsInFile().Count > 0) { RhinoApp.RunScript("_Speckle", false); } }
public List <Point3d> GetRoadPoints() { ButtonStateCheck(ButtonState.None); RhinoApp.SendKeystrokes("Cancel", true); RhinoApp.Wait(); bool newPoint = true; List <Point3d> newpoints = new List <Point3d>(); List <Rhino.DocObjects.PointObject> newpointobjects = new List <Rhino.DocObjects.PointObject>(); while (newPoint) { newPoint = RhinoApp.RunScript("Point", false); var guid = RhinoDoc.ActiveDoc.Objects.ElementAt(0).Id; Rhino.DocObjects.PointObject pointobject = RhinoDoc.ActiveDoc.Objects.Find(guid) as Rhino.DocObjects.PointObject; newpointobjects.Add(pointobject); Rhino.Geometry.Point point = pointobject.PointGeometry; Point3d point3d = point.Location; newpoints.Add(point3d); if (!newPoint) { var result = MessageBox.Show("Yes = 끝내기 No = 이전 취소 Cancle = 취소", "도로 선택 완료", MessageBoxButton.YesNoCancel); if (result == MessageBoxResult.Cancel) { foreach (var pobj in newpointobjects) { Rhino.RhinoDoc.ActiveDoc.Objects.Delete(pobj, true); } Rhino.RhinoDoc.ActiveDoc.Views.Redraw(); } else if (result == MessageBoxResult.No) { var lastguid = RhinoDoc.ActiveDoc.Objects.ElementAt(0).Id; RhinoDoc.ActiveDoc.Objects.Delete(lastguid, true); Rhino.RhinoDoc.ActiveDoc.Views.Redraw(); newPoint = true; } } ////show/hide작업 } return(newpoints); }
protected override void OnExecuted(EventArgs e) { base.OnExecuted(e); if (_models.Length == 0) { return; } Commands.Hidden.clSelectClippingPlanes.Instance.SetClippingPlanes(_models); RhinoApp.RunScript("clSelectClippingPlanes", true); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { string path; if (mode == RunMode.Interactive) { var savefile = new SaveFileDialog { FileName = "Untitled.3ds", Filter = @"3D Studio (*.3ds)|*.3ds||" }; if (savefile.ShowDialog() != DialogResult.OK) { return(Result.Cancel); } path = savefile.FileName.Trim(); } else { var gs = new GetString(); gs.SetCommandPrompt("Name of 3D Studio file to save"); gs.Get(); if (gs.CommandResult() != Result.Success) { return(gs.CommandResult()); } path = gs.StringResult().Trim(); } if (string.IsNullOrEmpty(path)) { return(Result.Nothing); } // Ensure the path has a ".3ds" extension if (!Path.HasExtension(path)) { path = Path.ChangeExtension(path, ".3ds"); } // Script Rhino's SaveAs command. Note, in case the path // string contains spaces, we will want to surround the string // with double-quote characters so the command line parser // will deal with it property. var script = $"_-SaveAs \"{path}\" _Enter"; RhinoApp.RunScript(script, false); return(Result.Success); }
protected override void OnExecuted(EventArgs e) { base.OnExecuted(e); // if we don't have a definition yet, there is nothing to do if (_definitions is null) { return; } Commands.Hidden.bbHiddenSelectBlockInstancesByParent.Instance.SetDefinition(_definitions); RhinoApp.RunScript("bbHiddenSelectBlockInstancesByParent", false); }
//Method export the final file containing the exported DXF private static void exportDXFFile(String exportFileName, RhinoDoc doc) { String path; String immediateFolderName = Path.GetFullPath(Path.GetDirectoryName(doc.Path)); path = immediateFolderName + ("\\nRUMPF"); if (!Directory.Exists(path)) { System.IO.Directory.CreateDirectory(path); //create directory if not exist } RhinoApp.RunScript("-_Export \"" + path + "\\" + exportFileName + ".dxf" + "\" Scheme \"R12 Lines & Arcs\" Enter", true); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { int index = SampleCsCommandsPlugIn.Instance.IsolateIndex - 1; if (index < 0) { RhinoApp.WriteLine("No isolated objects to unisolate."); SampleCsCommandsPlugIn.Instance.IsolateIndex = 0; return(Result.Nothing); } var go = new GetOption(); go.SetCommandPrompt("Choose unisolate option"); int a_opt = go.AddOption("All"); int p_opt = go.AddOption("Previous"); go.Get(); if (go.CommandResult() != Result.Success) { return(go.CommandResult()); } var opt = go.Option(); if (null == opt) { return(Result.Failure); } string script = null; if (opt.Index == a_opt) { script = "_-Show _Enter"; SampleCsCommandsPlugIn.Instance.IsolateIndex = 0; } else if (opt.Index == p_opt) { script = string.Format("_-Show {0}", index); SampleCsCommandsPlugIn.Instance.IsolateIndex--; } else { return(Result.Failure); } RhinoApp.RunScript(script, false); return(Result.Success); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { bool runCommand = false; string analysisType = ""; string filePath = ""; string revitDocName = ""; string message = ""; if (!DA.GetData(0, ref runCommand)) { return; } if (!DA.GetData(1, ref analysisType)) { return; } if (!DA.GetData(2, ref filePath)) { return; } if (runCommand) { List <Mesh> analysisGrid = FindAnalysisGrid(); string docName = RhinoDoc.ActiveDoc.Name; string dirName = docName.Replace(".3dm", ""); string divaTemp = @"C:\DIVA\Temp"; string tempDirectory = Path.Combine(divaTemp, dirName); string resultDirectory = Path.Combine(Path.GetDirectoryName(RhinoDoc.ActiveDoc.Path), dirName + " - DIVA"); string objFileName = Path.Combine(tempDirectory, dirName + "-AnalysisGrid.obj"); string script = string.Format("-Export \"{0}\" Enter Enter Enter", objFileName); RhinoApp.RunScript(script, false); RegistryKeyManager.SetRegistryKeyValue("RhinoOutgoing", runCommand.ToString()); RegistryKeyManager.SetRegistryKeyValue("RhinoOutgoingPath", filePath); RegistryKeyManager.SetRegistryKeyValue("DivaTempDirectory", tempDirectory); RegistryKeyManager.SetRegistryKeyValue("DivaResultDirectory", resultDirectory); RegistryKeyManager.SetRegistryKeyValue("RhinoOutgoingId", Guid.NewGuid().ToString()); message = "Rhino is sending result data to Revit"; revitDocName = RegistryKeyManager.GetRegistryKeyValue("RevitDocName"); if (!string.IsNullOrEmpty(revitDocName)) { DA.SetData(0, revitDocName); DA.SetData(1, message); } } }
private void OnCopyButtonClick(object sender, EventArgs e) { ListViewItem selected = m_list.SelectedItems[0]; if (null != selected) { SetActiveLayout((uint)selected.Tag); RhinoApp.RunScript("_CopyLayout", false); FillList(); } //RhinoApp.RunScript("_CopyLayout", false); //FillList(); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { var go = new GetObject(); go.SetCommandPrompt("Select objects to isolate"); go.GroupSelect = true; go.SubObjectSelect = false; go.GetMultiple(1, 0); if (go.CommandResult() != Result.Success) { return(go.CommandResult()); } for (int i = 0; i < go.ObjectCount; i++) { var obj = go.Object(i).Object(); if (null != obj) { obj.Select(true); } } doc.Views.RedrawEnabled = false; RhinoApp.RunScript("_-Invert", false); string script = string.Format("_-Hide {0}", SampleCsCommandsPlugIn.Instance.IsolateIndex); RhinoApp.RunScript(script, false); SampleCsCommandsPlugIn.Instance.IsolateIndex++; if (go.ObjectsWerePreselected) { for (int i = 0; i < go.ObjectCount; i++) { var obj = go.Object(i).Object(); if (null != obj) { obj.Select(true); } } } doc.Views.RedrawEnabled = true; return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { RhinoApp.WriteLine("The {0} command will run now", EnglishName); MaterialTable materialTable = doc.Materials; List <double> totalAreas = new List <double>(); double cumulativeArea = 0; foreach (Material m in materialTable) { doc.Objects.UnselectAll(); string command = string.Format("_-SelMaterialName {0}", m.Name); RhinoApp.RunScript(command, true); IEnumerable <RhinoObject> selectedObjects = doc.Objects.GetSelectedObjects(false, false); double totalArea = 0; foreach (RhinoObject obj in selectedObjects) { if (obj.ObjectType == ObjectType.Brep) { Brep brepGeom = (Brep)obj.Geometry; double area = AreaMassProperties.Compute(brepGeom).Area; totalArea += area; } } cumulativeArea += totalArea; totalAreas.Add(totalArea); } List <double> areaPercent = new List <double>(); totalAreas.ForEach(area => areaPercent.Add(area / cumulativeArea)); string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "materialAreas.txt"); using (StreamWriter sw = File.CreateText(path)) { for (int i = 0; i < areaPercent.Count; i++) { string line = string.Format("Material: {0}, Area: {1}", materialTable[i], areaPercent[i]); } } doc.Views.Redraw(); RhinoApp.WriteLine("The curves were rebuilt"); return(Result.Success); }
/// <summary> /// Show the layout properties user interface /// </summary> private void DoLayoutProperties() { if (0 == m_list.SelectedItems.Count) { return; } var selected = m_list.SelectedItems[0]; if (null != selected) { DoActiveLayout((uint)selected.Tag); RhinoApp.RunScript("_LayoutProperties", false); FillListView(); } }
/// <summary> /// Selects the lights and opens the Light Properties page /// </summary> public override bool OnEditLight(RhinoDoc doc, ref LightArray light_array) { for (int i = 0; i < light_array.Count(); i++) { Rhino.Geometry.Light light = light_array.ElementAt(i); int index = doc.Lights.Find(light.Id, true); if (index > -1) { Rhino.DocObjects.LightObject light_obj = doc.Lights[index]; light_obj.Select(true); RhinoApp.RunScript("_-PropertiesPage _Light", true); } return(true); } return(false); }
private static void RunScript(object sender, Autodesk.Revit.UI.Events.IdlingEventArgs e) { Revit.ApplicationUI.Idling -= RunScript; var runScript = Environment.GetEnvironmentVariable("RhinoInside_RunScript"); if (string.IsNullOrEmpty(runScript)) { return; } using (var modal = new ModalScope()) { if (RhinoApp.RunScript(runScript, false)) { modal.Run(Addin.StartupMode == AddinStartupMode.AtStartup); } } }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { string filename = null; var rc = RhinoGet.GetString("Name of AutoCAD DWG file to open", false, ref filename); if (rc != Result.Success) { return(rc); } filename = filename.Trim(); if (string.IsNullOrEmpty(filename)) { return(Result.Nothing); } if (!File.Exists(filename)) { RhinoApp.WriteLine("File not found"); return(Result.Failure); } var extension = Path.GetExtension(filename); if (string.IsNullOrEmpty(extension)) { return(Result.Nothing); } if (!string.Equals(extension, ".dwg", StringComparison.InvariantCultureIgnoreCase)) { RhinoApp.WriteLine("Not an AutoCAD DWG file."); return(Result.Failure); } // Make sure to surround filename string with double-quote characters // in case the path contains spaces. var script = string.Format("_-Open \"{0}\" _Enter", filename); RhinoApp.RunScript(script, false); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { var view = doc.Views.ActiveView; if (null == view) { return(Result.Failure); } var size = view.ActiveViewport.Size; var get = new Rhino.Input.Custom.GetInteger(); get.SetCommandPrompt("Viewport width in pixels"); get.SetDefaultInteger(size.Width); get.SetLowerLimit(10, true); get.Get(); if (get.CommandResult() != Result.Success) { return(get.CommandResult()); } size.Width = get.Number(); get.SetCommandPrompt("Viewport height in pixels"); get.SetDefaultInteger(size.Height); get.SetLowerLimit(10, true); get.Get(); if (get.CommandResult() != Result.Success) { return(get.CommandResult()); } size.Height = get.Number(); var script = $"_-ViewportProperties _Size {size.Width} {size.Height} _Enter"; RhinoApp.RunScript(script, false); return(Result.Success); }
//Draw the objects public static void drawObjects(String pathName, String fileName, RhinoObject rh, int layerNumber) { GetObject go = new GetObject(); RhinoApp.RunScript("_SelNone", true); RhinoApp.RunScript("_SelBoundary _SelectionMode=_Crossing _SelID " + rh.Id.ToString(), true); RhinoApp.RunScript("_SelID " + rh.Id.ToString(), true); RhinoApp.RunScript("SelLayerNumber " + layerNumber, true); go.GeometryFilter = ObjectType.Curve; go.GeometryAttributeFilter = GeometryAttributeFilter.ClosedCurve; go.EnableTransparentCommands(true); RhinoApp.RunScript("SelLayerNumber " + layerNumber, true); //go.GetMultiple(1, 1); RhinoApp.RunScript("SelLayerNumber " + layerNumber, true); // go.Get(); RhinoApp.RunScript("SelLayerNumber " + layerNumber, true); RhinoApp.RunScript("_SelNone", true); RhinoApp.RunScript("_SelBoundary _SelectionMode=_Crossing _SelID " + rh.Id.ToString(), true); RhinoApp.RunScript("_SelID " + rh.Id.ToString(), true); }
private void MenuStripMatChange_Click(object sender, EventArgs e) { string cmd; List <string> mats = new List <string>(); foreach (RenderMaterial mat in ParentDoc.RenderMaterials) { mats.Add(mat.Name); } object selection = Dialogs.ShowListBox("Materials", "select target material", mats); if (selection is string lname) { cmd = "-_RenderAssignMaterialToObjects " + lname + " "; } else { MessageBox.Show("Material selection failed. Either no material in the document or selection improper", "Failed", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } int errn = 0; foreach (TablLineItem tli in lvTabl.SelectedItems) { ParentDoc.Views.RedrawEnabled = false; ParentDoc.Objects.Select(tli.RefId, true); RhinoApp.RunScript(cmd, false); ParentDoc.Objects.Select(tli.RefId, false); ParentDoc.Views.RedrawEnabled = true; ParentDoc.Views.Redraw(); } if (errn > 0) { MessageBox.Show(string.Format("error changing {0} material(s)\nplease email support\nsorry about the inconvenience", errn)); } RefreshTabl(); }
public static string GrasshopperExport(Brep brep) { RhinoDoc.ActiveDoc.Objects.UnselectAll(); var gh_brep = new GH_Brep(brep); Guid brepGuid = Guid.Empty; gh_brep.BakeGeometry(RhinoDoc.ActiveDoc, new ObjectAttributes(), ref brepGuid); RhinoDoc.ActiveDoc.Objects.Select(brepGuid, true); string exportName = GetTempFileName("stp"); string exportCmd = "!_-Export _SaveSmall=Yes _GeometryOnly=Yes _SaveTextures=No _SavePlugInData=Yes " + "\"" + exportName + "\"" + " _Schema=AP214AutomotiveDesign _ExportParameterSpaceCurves=Yes _SplitClosedSurfaces=No _LetImportingApplicationSetColorForBlackObjects=Yes " + " _Enter"; RhinoApp.RunScript(exportCmd, false); RhinoDoc.ActiveDoc.Objects.Delete(brepGuid, true); return(exportName); }
public static string Export(List <DisplayGeometry> geometries, ExportType exportType, string folder, string fileName) { var doc = RhinoDoc.ActiveDoc; var guids = new List <Guid>(geometries.Count); bool flipYZ = exportType == ExportType.FBX; foreach (var geometry in geometries) { guids.Add(geometry.Bake(doc, null, flipYZ)); } doc.Objects.UnselectAll(false); doc.Objects.Select(guids, true); string filePath = Path.Combine(folder, fileName); switch (exportType) { case ExportType.HTML: { RhinoApp.RunScript($"-_Export \"{filePath}.html\" ui=yes launch=yes _Enter", false); break; } case ExportType.FBX: { RhinoApp.RunScript($"-_Export \"{filePath}.fbx\" _Enter _Enter", false); break; } default: break; } doc.Objects.Delete(guids, true); return(filePath); }
private Guid[] ScriptedSweep2(RhinoDoc doc, Guid rail1, Guid rail2, IEnumerable <Guid> shapes) { doc.Objects.UnselectAll(true); var sb = new StringBuilder("_-Sweep2 "); sb.Append(string.Format("_SelID {0} ", rail1)); sb.Append(string.Format("_SelID {0} ", rail2)); foreach (var shape in shapes) { sb.Append(string.Format("_SelID {0} ", shape)); } sb.Append(string.Format("_Enter ")); sb.Append(string.Format("_Simplify=_None _Closed=_Yes _MaintainHeight=_Yes _Enter")); var start_sn = Rhino.DocObjects.RhinoObject.NextRuntimeSerialNumber; RhinoApp.RunScript(sb.ToString(), false); var end_sn = Rhino.DocObjects.RhinoObject.NextRuntimeSerialNumber; if (start_sn == end_sn) { return(new Guid[0]); } var object_ids = new List <Guid>(); for (var sn = start_sn; sn < end_sn; sn++) { var obj = doc.Objects.Find(sn); if (null != obj) { object_ids.Add(obj.Id); } } return(object_ids.ToArray()); }
/// <summary> /// Deletes the currently selected layouts /// </summary> private void DoDeleteLayout() { var count = m_list.SelectedItems.Count; if (0 == count) { return; } var message = 1 == count ? "Permanently deleted the selected layout?" : "Permanently deleted the selected layouts?"; var title = 1 == count ? "Delete Layout" : "Delete Layouts"; var rc = Dialogs.ShowMessage(message, title, ShowMessageButton.YesNo, ShowMessageIcon.Warning); if (rc == ShowMessageResult.No) { return; } m_current_event = LayoutEvent.Delete; foreach (ListViewItem item in m_list.SelectedItems) { DoActiveLayout((uint)item.Tag); RhinoApp.Wait(); RhinoApp.RunScript("_-CloseViewport _Yes", false); RhinoApp.Wait(); } FillListView(); m_current_event = LayoutEvent.None; }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { RhinoApp.RunScript(@"-_Open C:\model.3dm"); }
/// <summary> /// Creates the layout. /// </summary> /// <param name="doc">The document.</param> /// <param name="panel">The panel.</param> /// <param name="panelParas">The panel paras.</param> /// <returns></returns> public Result createLayout(RhinoDoc doc, FoldedPerforationPanel panel, PanelParameters panelParas) { if (panelParas == null) { panelParas = new PanelParameters(); } if (panel == null) { panel = new FoldedPerforationPanel(); } // Get all selected Objects GetObject go = new GetObject(); go.GroupSelect = true; go.SubObjectSelect = false; go.EnableClearObjectsOnEntry(false); go.EnableUnselectObjectsOnExit(false); go.DeselectAllBeforePostSelect = false; go.EnableSelPrevious(true); go.EnablePreSelect(true, false); go.EnablePressEnterWhenDonePrompt(false); go.SetCommandPrompt("Select items for the new layout:"); // Disable the scaling RhinoApp.RunScript("_-DocumentProperties AnnotationStyles ModelSpaceScaling=Disabled LayoutSpaceScaling=Disabled _Enter _Enter", true); GetResult result = go.GetMultiple(1, -1); if (go.CommandResult() != Rhino.Commands.Result.Success) { return(go.CommandResult()); } RhinoApp.WriteLine("Total Objects Selected: {0}", go.ObjectCount); string labelName = panel.PartName; string area = string.Format("{0:0.00}", panel.Area); Point2d minPoint = new Point2d(0, 0); Point2d maxPoint = new Point2d(0, 0); // Loop through all the objects to find Text for (int i = 0; i < go.ObjectCount; i++) { BoundingBox bBox = go.Object(i).Object().Geometry.GetBoundingBox(true); if (bBox.Min.X < minPoint.X) { minPoint.X = bBox.Min.X; } if (bBox.Min.Y < minPoint.Y) { minPoint.Y = bBox.Min.Y; } if (bBox.Max.X > maxPoint.X) { maxPoint.X = bBox.Max.X; } if (bBox.Max.Y > maxPoint.Y) { maxPoint.Y = bBox.Max.Y; } } // If the selected items has no label, return failure if (labelName == null) { return(Rhino.Commands.Result.Failure); } // Hide all the non selected objects foreach (var obj in doc.Objects) { if (obj.IsSelected(true) == 0) { doc.Objects.Hide(obj, false); } } // Add layout doc.PageUnitSystem = Rhino.UnitSystem.Millimeters; RhinoView currentView = doc.Views.ActiveView; var pageview = doc.Views.AddPageView(string.Format("{0}", labelName), 210, 297); Point2d bottomLeft = new Point2d(10, 70); Point2d topRight = new Point2d(200, 287); if (pageview != null) { pageview.SetPageAsActive(); var detail = pageview.AddDetailView("Panel", bottomLeft, topRight, Rhino.Display.DefinedViewportProjection.Top); // Show all objects RhinoApp.RunScript("_-Show _Enter", true); if (detail != null) { pageview.SetActiveDetail(detail.Id); doc.Views.ActiveView = pageview; //doc.Views.Redraw(); // Select all the objects for (int i = 0; i < go.ObjectCount; i++) { RhinoObject rhinoObject = go.Object(i).Object(); rhinoObject.Select(true); } // Hide all the non selected objects var filter = new ObjectEnumeratorSettings { NormalObjects = true, LockedObjects = false, HiddenObjects = false, ActiveObjects = true, ReferenceObjects = true }; var rh_objects = doc.Objects.FindByFilter(filter); pageview.SetPageAsActive(); //doc.Views.Redraw(); foreach (var rh_obj in rh_objects) { var select = 0 == rh_obj.IsSelected(false) && rh_obj.IsSelectable(); rh_obj.Select(select); } RhinoApp.RunScript("_-HideInDetail Enter", true); detail.IsActive = false; } bottomLeft = new Point2d(10, 40); topRight = new Point2d(135, 70); detail = pageview.AddDetailView("Sample", bottomLeft, topRight, Rhino.Display.DefinedViewportProjection.Top); // doc.Views.Redraw(); pageview.SetActiveDetail(detail.Id); detail.Viewport.SetCameraLocation(new Point3d(50, 160, 0), true); detail.CommitViewportChanges(); // doc.Views.Redraw(); detail.DetailGeometry.IsProjectionLocked = true; detail.DetailGeometry.SetScale(4.5, doc.ModelUnitSystem, 1, doc.PageUnitSystem); detail.CommitChanges(); // doc.Views.Redraw(); detail.IsActive = true; pageview.SetActiveDetail(detail.Id); RhinoApp.WriteLine("Name = {0}: Width = {1}, Height = {2}", detail.Viewport.Name, detail.Viewport.Size.Width, detail.Viewport.Size.Height); detail.CommitViewportChanges(); // doc.Views.Redraw(); detail.IsActive = false; bottomLeft = new Point2d(5, 5); topRight = new Point2d(205, 35); detail = pageview.AddDetailView("Block", bottomLeft, topRight, Rhino.Display.DefinedViewportProjection.Top); // doc.Views.Redraw(); detail.IsActive = true; pageview.SetActiveDetail(detail.Id); detail.Viewport.SetCameraLocation(new Point3d(105, 520, 0), true); detail.CommitViewportChanges(); // doc.Views.Redraw(); detail.DetailGeometry.IsProjectionLocked = true; detail.DetailGeometry.SetScale(1, doc.ModelUnitSystem, 1, doc.PageUnitSystem); detail.CommitChanges(); detail.IsActive = false; // doc.Views.Redraw(); drawBlock(doc, labelName, area, panel.PanelNumber, panelParas); // doc.Views.Redraw(); } // Show all objects RhinoApp.RunScript("_-Show _Enter", true); doc.Views.DefaultViewLayout(); doc.Views.ActiveView = currentView; return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { RhinoApp.RunScript("ShowToolbar \"Salamander 3\"", true); return(Result.Success); }
public static void ToggleGrasshopperWindow() { PlugIn.LoadPlugIn(GrasshopperGuid); RhinoApp.RunScript("!_-Grasshopper _W _T ENTER", false); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { var go = new GetObject(); go.SetCommandPrompt("Select objects to export"); go.GroupSelect = true; go.GetMultiple(1, 0); if (go.CommandResult() != Result.Success) { return(go.CommandResult()); } string path; if (mode == RunMode.Interactive) { var savefile = new SaveFileDialog { FileName = @"Untitled.dxf", Filter = @"AutoCAD Drawing Exchange (*.dxf)|*.dxf||" }; if (savefile.ShowDialog() != DialogResult.OK) { return(Result.Cancel); } path = savefile.FileName.Trim(); } else { var gs = new GetString(); gs.SetCommandPrompt("Name of AutoCAD Drawing Exchange file to save"); gs.Get(); if (gs.CommandResult() != Result.Success) { return(gs.CommandResult()); } path = gs.StringResult().Trim(); } if (string.IsNullOrEmpty(path)) { return(Result.Nothing); } // Ensure the path has a ".dxf" extension if (!Path.HasExtension(path)) { path = Path.ChangeExtension(path, ".dxf"); } // Script Rhino's Export command. Note, in case the path // string contains spaces, we will want to surround the string // with double-quote characters so the command line parser // will deal with it property. var script = $"_-Export \"{path}\" _Enter"; RhinoApp.RunScript(script, false); return(Result.Success); }