/// <summary> /// Copy selected GIS features into Rhino; assign objects to corresponding layers, and apply attribute values as user text /// </summary> /// <param name="rhinoDoc">Active Rhino Doc</param> internal static void copySelectedObjects(RhinoDoc rhinoDoc) { if (rhinoDoc == null) { return; } var origin = RhinoUtil.getOrigin(rhinoDoc); // System.Windows.MessageBox.Show($"Origin {origin.ToString()}"); var layers = MapView.Active.Map.GetLayersAsFlattenedList().OfType <FeatureLayer>().ToList(); foreach (var layer in layers) { var t = QueuedTask.Run(() => { var selectionfromMap = layer.GetSelection(); var count = selectionfromMap.GetCount(); // MessageBox.Show($"Got layer {firstLayer.Name} with {count} selected features"); var filter = new QueryFilter { ObjectIDs = selectionfromMap.GetObjectIDs() }; if (count > 0) { using (RowCursor rowCursor = layer.Search(filter)) { while (rowCursor.MoveNext()) { long oid = rowCursor.Current.GetObjectID(); // get the shape from the row Feature feature = rowCursor.Current as Feature; if (feature.GetShape() is Polygon polygon) { convertPolygon(layer, feature, polygon, rhinoDoc, origin); } else if (feature.GetShape() is Polyline polyline) { convertPolyline(layer, feature, polyline, rhinoDoc, origin); } else if (feature.GetShape() is MapPoint point) { convertPoint(layer, feature, point, rhinoDoc, origin); } else if (feature.GetShape() is Multipoint multiPoint) { // TODO: treat multipoint as a group of points } else if (feature.GetShape() is Multipatch multiPatch) { // TODO: treat multipoint as a group of patches } else { // TODO: figure out other possible types inherited from ArcGIS.Core.Geometry } // MessageBox.Show("Found feature with attributes:\n" + string.Join("\n", feature.GetFields().Select(f => f.Name).ToList())); } } } }); } }
/// <summary> /// Copy compatible GH canvas preview components into ArcGIS /// </summary> /// <param name="document"></param> internal static void showDocumentPreview(RhinoDoc rhinoDoc) { try { // TODO: determine whether to purge existing GH_Preview geometry // on feature layers or append to that. var document = Grasshopper.Instances.DocumentServer.FirstOrDefault(); if (document == null) { return; } if (rhinoDoc == null) { return; } var origin = RhinoUtil.getOrigin(rhinoDoc); var previewObjects = document.Objects .OfType <IGH_ActiveObject>() .Where(o => !o.Locked && o is IGH_PreviewObject) .Select(o => o as IGH_PreviewObject) .Where(o => o.IsPreviewCapable) .ToList(); var componentParams = previewObjects .Where(o => o is IGH_Component) .Select(o => o as IGH_Component) .Where(o => !o.Hidden) .SelectMany(o => o.Params.Output) .ToList(); var otherParams = previewObjects .Where(o => o is IGH_Param) .Select(o => o as IGH_Param) .ToList(); QueuedTask.Run(() => { var operation = new EditOperation(); componentParams.ForEach(p => showParam(operation, p, origin)); otherParams.ForEach(p => showParam(operation, p, origin)); }); } catch (Exception ex) { MessageBox.Show(ex.Message + ex.StackTrace); } }