protected async void DuplicateParcels() { string errorMessage = await QueuedTask.Run(async() => { // check for selected layer if (MapView.Active.GetSelectedLayers().Count == 0) { return("Please select the source layer in the table of contents."); } #region Duplicate parcels var myParcelFabricLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType <ParcelLayer>().FirstOrDefault(); if (myParcelFabricLayer == null) { return("Parecl layer not found in the map."); } //get the source polygon layer from the parcel fabric layer type, in this case a layer called Lot var srcFeatLyrEnum = await myParcelFabricLayer.GetParcelPolygonLayerByTypeName("Lot"); if (srcFeatLyrEnum.Count() == 0) { return(""); } var sourcePolygonL = srcFeatLyrEnum.FirstOrDefault(); //get the target polygon layer from the parcel fabric layer type, in this case a layer called Tax var targetFeatLyrEnum = await myParcelFabricLayer.GetParcelPolygonLayerByTypeName("Tax"); if (targetFeatLyrEnum.Count() == 0) { return(""); } var targetFeatLyr = targetFeatLyrEnum.FirstOrDefault(); var ids = new List <long>(sourcePolygonL.GetSelection().GetObjectIDs()); if (ids.Count == 0) { return("No selected parcels found. Please select parcels and try again."); } //add polygon layers and the feature ids to be duplicated to a new KeyValuePair var kvp = new KeyValuePair <MapMember, List <long> >(sourcePolygonL, ids); var sourceFeatures = new List <KeyValuePair <MapMember, List <long> > > { kvp }; try { var theActiveRecord = myParcelFabricLayer.GetActiveRecord(); if (theActiveRecord == null) { return("There is no Active Record. Please set the active record and try again."); } var editOper = new EditOperation() { Name = "Duplicate Parcels", ProgressMessage = "Duplicate Parcels...", ShowModalMessageAfterFailure = true, SelectNewFeatures = true, SelectModifiedFeatures = false }; editOper.DuplicateParcels(myParcelFabricLayer, sourceFeatures, theActiveRecord, targetFeatLyr); if (!editOper.Execute()) { return(editOper.ErrorMessage); } } catch (Exception ex) { return(ex.Message); } #endregion return(""); }); if (!string.IsNullOrEmpty(errorMessage)) { MessageBox.Show(errorMessage, "Duplicate Parcels."); } }
protected async void DuplicateParcels() { await QueuedTask.Run(async() => { // check for selected layer if (MapView.Active.GetSelectedLayers().Count == 0) { System.Windows.MessageBox.Show("Please select the source parcel type polygon layer in the table of contents", "Duplicate Parcels"); return; } //first get the feature layer that's selected in the table of contents var sourcePolygonL = MapView.Active.GetSelectedLayers().First() as FeatureLayer; var myParcelFabricLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType <ParcelLayer>().FirstOrDefault(); if (!await sourcePolygonL.IsControlledByParcelFabric(ParcelFabricType.ParcelFabric)) { System.Windows.MessageBox.Show("Please select the source parcel type polygon layer in the table of contents", "Duplicate Parcels"); return; } string sTargetParcelType = "Tax"; //Microsoft.VisualBasic.Interaction.InputBox("Target Parcel Type:", "Copy Parcel Lines To", "Tax"); if (sTargetParcelType.Trim().Length == 0) { return; } if (myParcelFabricLayer == null || sourcePolygonL == null) { return; } #region Duplicate parcels //get the polygon layer from the parcel fabric layer type, in this case a layer called Tax var targetFeatLyr = MapView.Active.Map.GetLayersAsFlattenedList().OfType <FeatureLayer>().FirstOrDefault(l => l.Name == "Tax") as FeatureLayer; var ids = new List <long>(sourcePolygonL.GetSelection().GetObjectIDs()); if (ids.Count == 0) { System.Windows.MessageBox.Show("No selected parcels found. Please select parcels and try again.", "Copy Parcel Lines To"); return; } //add polygon layers and the feature ids to be duplicated to a new KeyValuePair var kvp = new KeyValuePair <MapMember, List <long> >(sourcePolygonL, ids); var sourceFeatures = new List <KeyValuePair <MapMember, List <long> > > { kvp }; var theActiveRecord = myParcelFabricLayer.GetActiveRecord(); if (theActiveRecord == null) { System.Windows.MessageBox.Show("There is no Active Record. Please set the active record and try again.", "Copy Line Features To"); return; } Guid guid = theActiveRecord.Guid; var editOper = new EditOperation() { Name = "Duplicate Parcels", ProgressMessage = "Duplicate Parcels...", ShowModalMessageAfterFailure = true, SelectNewFeatures = true, SelectModifiedFeatures = false }; editOper.DuplicateParcels(myParcelFabricLayer, sourceFeatures, guid, targetFeatLyr, -1); editOper.Execute(); #endregion }); }