string errorMessage = await QueuedTask.Run(async () =>
{
// check for selected layer
if (MapView.Active.GetSelectedLayers().Count == 0)
return "Please select a source parcel polygon feature layer in the table of contents.";
try
{
var myParcelFabricLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<ParcelLayer>().FirstOrDefault();
if (myParcelFabricLayer == null)
return "No parcel layer found in the map.";
//get the feature layer that's selected in the table of contents
var srcParcelFeatLyr = MapView.Active.GetSelectedLayers().OfType<FeatureLayer>().FirstOrDefault();
string sTargetParcelType = "Tax";
var destLineLEnum = await myParcelFabricLayer.GetParcelLineLayerByTypeNameAsync(sTargetParcelType);
if (destLineLEnum.Count() == 0)
return "";
var destLineL = destLineLEnum.FirstOrDefault();
var destPolygonLEnum = await myParcelFabricLayer.GetParcelPolygonLayerByTypeNameAsync(sTargetParcelType);
if (destPolygonLEnum.Count() == 0)
return "";
var destPolygonL = destPolygonLEnum.FirstOrDefault();
if (destLineL == null || destPolygonL == null)
return "";
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 = "Copy Lines To Parcel Type",
ProgressMessage = "Copy Lines To Parcel Type ...",
ShowModalMessageAfterFailure = true,
SelectNewFeatures = true,
SelectModifiedFeatures = false
};
var ids = new List<long>(srcParcelFeatLyr.GetSelection().GetObjectIDs());
if (ids.Count == 0)
return "No selected parcels found. Please select parcels and try again.";
//add the standard feature line layers source, and their feature ids to a new Dictionary
var sourceParcelFeatures = new Dictionary<MapMember, List<long>>();
sourceParcelFeatures.Add(srcParcelFeatLyr, ids);
editOper.CopyParcelLinesToParcelType(myParcelFabricLayer, SelectionSet.FromDictionary(sourceParcelFeatures), destLineL, destPolygonL, true, false, true);
if (!editOper.Execute())
return editOper.ErrorMessage;
}
catch (Exception ex)
{
return ex.Message;
}
return "";
});
if (!string.IsNullOrEmpty(errorMessage))
MessageBox.Show(errorMessage, "Copy Parcel Lines To Parcel Type.");