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.GetParcelPolygonLayerByTypeNameAsync("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.GetParcelPolygonLayerByTypeNameAsync("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 Dictionary
var sourceFeatures = new Dictionary<MapMember, List<long>>();
sourceFeatures.Add(sourcePolygonL, ids);
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,
SelectionSet.FromDictionary(sourceFeatures), theActiveRecord, targetFeatLyr);
if (!editOper.Execute())
return editOper.ErrorMessage;
}
catch (Exception ex)
{
return ex.Message;
}