public bool UpdateBuildingAnnotationFamily() { var result = false; try { var scheduleManager = new ScheduleDataManager(m_app, CalculationTypes.BuildingArea); var category = scheduleManager.GetLPDCategoryBAM(); var allowableLPD = scheduleManager.GetAllowableLPDBAM(); var targetLPD = scheduleManager.GetTargetLPDBAM(); var actualLightingLoad = scheduleManager.GetActualLightingLoad(); var area = scheduleManager.GetArea(); var actualLPD = actualLightingLoad / area; var reduction = 1 - (actualLPD / allowableLPD); using (var trans = new Transaction(m_doc)) { try { trans.Start("Update Annotation"); var annotation = new AnnotationProperties(annotationType, CalculationTypes.BuildingArea) { ASHRAELPDCategory = category, ASHRAEAllowableLPD = allowableLPD, TargetLPD = targetLPD, ActualLightingLoad = actualLightingLoad, Area = area, ActualLPD = actualLPD, Reduction = reduction, LPDCalculatedBy = Environment.UserName }; trans.Commit(); } catch { trans.RollBack(); } } result = true; } catch (Exception ex) { MessageBox.Show("Failed to update annotation family.\n" + ex.Message, "Update Annotation Family", MessageBoxButtons.OK, MessageBoxIcon.Warning); } return(result); }
public bool UpdateSpaceAnnotationFamily() { var result = false; try { var scheduleManager = new ScheduleDataManager(m_app, CalculationTypes.SpaceBySpace); var allowableLightingLoad = scheduleManager.GetAllowableLightingLoad(); var actualLightingLoad = scheduleManager.GetActualLightingLoad(); var savings = scheduleManager.GetSavings(); var area = scheduleManager.GetArea(); var actualLPD = actualLightingLoad / area; var reduction = savings / allowableLightingLoad; using (var trans = new Transaction(m_doc)) { try { trans.Start("Update Annotation"); var annotation = new AnnotationProperties(annotationType, CalculationTypes.SpaceBySpace) { TotalAllowableLightingLoad = allowableLightingLoad, TotalActualLightingLoad = actualLightingLoad, TotalSavingsOverage = savings, Area = area, ActualLPD = actualLPD, Reduction = reduction, LPDCalculatedBy = Environment.UserName }; trans.Commit(); } catch { trans.RollBack(); } } result = true; } catch (Exception ex) { MessageBox.Show("Failed to update annotation family.\n" + ex.Message, "Update Annotation Family", MessageBoxButtons.OK, MessageBoxIcon.Warning); } return(result); }
protected override async void OnClick() { // get an anno layer AnnotationLayer annoLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType <AnnotationLayer>().FirstOrDefault(); if (annoLayer == null) { return; } bool result = await QueuedTask.Run(async() => { // get an existing template EditingTemplate template = annoLayer.GetTemplates().FirstOrDefault(); if (template == null) { return(false); } // make sure it is active before you get the inspector await template.ActivateDefaultToolAsync(); var insp = template.Inspector; if (insp == null) { return(false); } // set up some properties AnnotationProperties annoProperties = insp.GetAnnotationProperties(); annoProperties.TextString = "special text"; annoProperties.Color = ColorFactory.Instance.GreenRGB; annoProperties.SmallCaps = true; insp.SetAnnotationProperties(annoProperties); // set up default tool - use daml-id rather than guid string defaultTool = "esri_editing_SketchStraightAnnoTool"; // dont alter the filter or tags // create a new CIM template - new extension method var newTemplate = annoLayer.CreateTemplate("template from existing template", "sample template description", insp, defaultTool); return(newTemplate != null); }); }
//In your config.daml...set the categoryRefID //<tool id="..." categoryRefID="esri_editing_construction_annotation" caption="Create Anno" ...> //Sketch type Point or Line or BezierLine in the constructor... //internal class AnnoConstructionTool : MapTool { // public AnnoConstructionTool() { // IsSketchTool = true; // UseSnapping = true; // SketchType = SketchGeometryType.Point; // protected async override Task <bool> OnSketchCompleteAsync(Geometry geometry) { if (CurrentTemplate == null || geometry == null) { return(false); } // Create an edit operation var createOperation = new EditOperation(); createOperation.Name = string.Format("Create {0}", CurrentTemplate.Layer.Name); createOperation.SelectNewFeatures = true; var insp = CurrentTemplate.Inspector; var result = await QueuedTask.Run(() => { // get the annotation properties class AnnotationProperties annoProperties = insp.GetAnnotationProperties(); // set custom annotation properties annoProperties.TextString = "my custom text"; annoProperties.Color = ColorFactory.Instance.RedRGB; annoProperties.FontSize = 24; annoProperties.FontName = "Arial"; annoProperties.HorizontalAlignment = ArcGIS.Core.CIM.HorizontalAlignment.Right; annoProperties.Shape = geometry; // assign annotation properties back to the inspector insp.SetAnnotationProperties(annoProperties); // Queue feature creation createOperation.Create(CurrentTemplate.Layer, insp); // Execute the operation return(createOperation.Execute()); }); return(result); }
//Using Inspector... internal async void UpdateAnnotation() { BasicFeatureLayer annoLayer = MapView.Active.Map.GetLayersAsFlattenedList().First() as BasicFeatureLayer; var oid = 1; #region Update Annotation Text await QueuedTask.Run(() => { //annoLayer is ~your~ Annotation layer... // use the inspector methodology var insp = new Inspector(true); insp.Load(annoLayer, oid); // get the annotation properties AnnotationProperties annoProperties = insp.GetAnnotationProperties(); // set the attribute annoProperties.TextString = "Hello World"; // assign the annotation proeprties back to the inspector insp.SetAnnotationProperties(annoProperties); //create and execute the edit operation EditOperation op = new EditOperation(); op.Name = "Update annotation"; op.Modify(insp); op.Execute(); }); #endregion #region Modify Annotation Shape await QueuedTask.Run(() => { //Don't use 'Shape'....Shape is the bounding box of the annotation text. This is NOT what you want... // //var insp = new Inspector(); //insp.Load(annoLayer, oid); //var shape = insp["SHAPE"] as Polygon; //...wrong shape... //Instead, we must use the AnnotationProperties //annoLayer is ~your~ Annotation layer var insp = new Inspector(true); insp.Load(annoLayer, oid); AnnotationProperties annoProperties = insp.GetAnnotationProperties(); var shape = annoProperties.Shape; if (shape.GeometryType != GeometryType.GeometryBag) { var newGeometry = GeometryEngine.Instance.Move(shape, 10, 10); annoProperties.Shape = newGeometry; insp.SetAnnotationProperties(annoProperties); EditOperation op = new EditOperation(); op.Name = "Change annotation angle"; op.Modify(insp); op.Execute(); } }); #endregion #region Modify Annotation Text Graphic await QueuedTask.Run(() => { var selection = annoLayer.GetSelection(); if (selection.GetCount() == 0) { return; } // use the first selelcted feature var insp = new Inspector(true); insp.Load(annoLayer, selection.GetObjectIDs().FirstOrDefault()); // getAnnoProperties should return null if not an annotation feature AnnotationProperties annoProperties = insp.GetAnnotationProperties(); // get the textGraphic CIMTextGraphic textGraphic = annoProperties.TextGraphic; // change text textGraphic.Text = "Hello world"; // set x,y offset via the symbol var symbol = textGraphic.Symbol.Symbol; var textSymbol = symbol as CIMTextSymbol; textSymbol.OffsetX = 2; textSymbol.OffsetY = 3; textSymbol.HorizontalAlignment = HorizontalAlignment.Center; // load the updated textGraphic annoProperties.LoadFromTextGraphic(textGraphic); // assign the annotation properties back insp.SetAnnotationProperties(annoProperties); EditOperation op = new EditOperation(); op.Name = "modify symbol"; op.Modify(insp); bool result = op.Execute(); }); #endregion }
public void CreateTemplate() { string value1 = ""; string value2 = ""; string value3 = ""; #region Create New Template using layer.CreateTemplate var layer = MapView.Active.Map.GetLayersAsFlattenedList().OfType <FeatureLayer>().FirstOrDefault(); if (layer == null) { return; } QueuedTask.Run(() => { var insp = new Inspector(); insp.LoadSchema(layer); insp["Field1"] = value1; insp["Field2"] = value2; insp["Field3"] = value3; var tags = new[] { "Polygon", "tag1", "tag2" }; // set defaultTool using a daml-id string defaultTool = "esri_editing_SketchCirclePolygonTool"; // tool filter is the tools to filter OUT var toolFilter = new[] { "esri_editing_SketchTracePolygonTool" }; // create a new template var newTemplate = layer.CreateTemplate("My new template", "description", insp, defaultTool, tags, toolFilter); }); #endregion #region Create Annotation Template // get an anno layer AnnotationLayer annoLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType <AnnotationLayer>().FirstOrDefault(); if (annoLayer == null) { return; } QueuedTask.Run(() => { Inspector insp = null; // get the anno feature class var fc = annoLayer.GetFeatureClass() as ArcGIS.Core.Data.Mapping.AnnotationFeatureClass; // get the featureclass CIM definition which contains the labels, symbols var cimDefinition = fc.GetDefinition() as ArcGIS.Core.Data.Mapping.AnnotationFeatureClassDefinition; var labels = cimDefinition.GetLabelClassCollection(); var symbols = cimDefinition.GetSymbolCollection(); // make sure there are labels, symbols if ((labels.Count == 0) || (symbols.Count == 0)) { return; } // find the label class required // typically you would use a subtype name or some other characteristic // in this case lets just use the first one var label = labels[0]; // each label has a textSymbol // the symbolName *should* be the symbolID to be used var symbolName = label.TextSymbol.SymbolName; int symbolID = -1; if (!int.TryParse(symbolName, out symbolID)) { // int.TryParse fails - attempt to find the symbolName in the symbol collection foreach (var symbol in symbols) { if (symbol.Name == symbolName) { symbolID = symbol.ID; break; } } } // no symbol? if (symbolID == -1) { return; } // load the schema insp = new Inspector(); insp.LoadSchema(annoLayer); // ok to assign these fields using the inspector[fieldName] methodology // these fields are guaranteed to exist in the annotation schema insp["AnnotationClassID"] = label.ID; insp["SymbolID"] = symbolID; // set up some additional annotation properties AnnotationProperties annoProperties = insp.GetAnnotationProperties(); annoProperties.FontSize = 36; annoProperties.TextString = "My Annotation feature"; annoProperties.VerticalAlignment = VerticalAlignment.Top; annoProperties.HorizontalAlignment = HorizontalAlignment.Justify; insp.SetAnnotationProperties(annoProperties); var tags = new[] { "Annotation", "tag1", "tag2" }; // use daml-id rather than guid string defaultTool = "esri_editing_SketchStraightAnnoTool"; // tool filter is the tools to filter OUT var toolFilter = new[] { "esri_editing_SketchCurvedAnnoTool" }; // create a new template var newTemplate = annoLayer.CreateTemplate("new anno template", "description", insp, defaultTool, tags, toolFilter); }); #endregion }
protected override async void OnClick() { // get an anno layer AnnotationLayer annoLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType <AnnotationLayer>().FirstOrDefault(); if (annoLayer == null) { return; } Inspector insp = null; bool result = await QueuedTask.Run(() => { // get the anno feature class var fc = annoLayer.GetFeatureClass() as ArcGIS.Core.Data.Mapping.AnnotationFeatureClass; // get the featureclass CIM definition which contains the labels, symbols var cimDefinition = fc.GetDefinition() as ArcGIS.Core.Data.Mapping.AnnotationFeatureClassDefinition; var labels = cimDefinition.GetLabelClassCollection(); var symbols = cimDefinition.GetSymbolCollection(); // make sure there are labels, symbols if ((labels.Count == 0) || (symbols.Count == 0)) { return(false); } // find the label class required // typically you would use a subtype name or some other characteristic // in this case lets just use the first one // var label = labels[0]; // find the label class required // typically you would use a subtype name or some other characteristic // use the first label class var label = labels[0]; if (labels.Count > 1) { // find a label class based on template name foreach (var LabelClass in labels) { if (LabelClass.Name == "Basic") { label = LabelClass; break; } } } // each label has a textSymbol // the symbolName *should* be the symbolID to be used var symbolName = label.TextSymbol.SymbolName; int symbolID = -1; if (!int.TryParse(symbolName, out symbolID)) { // int.TryParse fails - attempt to find the symbolName in the symbol collection foreach (var symbol in symbols) { if (symbol.Name == symbolName) { symbolID = symbol.ID; break; } } } // no symbol? if (symbolID == -1) { return(false); } // load the schema insp = new Inspector(); insp.LoadSchema(annoLayer); // ok to access AnnotationClassID, SymbolID this way - it is guaranteed to exist insp["AnnotationClassID"] = label.ID; insp["SymbolID"] = symbolID; // set up some text properties AnnotationProperties annoProperties = insp.GetAnnotationProperties(); annoProperties.FontSize = 36; annoProperties.TextString = "My Annotation feature"; annoProperties.VerticalAlignment = VerticalAlignment.Top; annoProperties.HorizontalAlignment = HorizontalAlignment.Justify; // assign the properties back to the inspector insp.SetAnnotationProperties(annoProperties); // set up tags var tags = new[] { "Annotation", "tag1", "tag2" }; // set up default tool - use daml-id rather than guid string defaultTool = "esri_editing_SketchStraightAnnoTool"; // tool filter is the tools to filter OUT var toolFilter = new[] { "esri_editing_SketchCurvedAnnoTool" }; // create a new CIM template - new extension method var newTemplate = annoLayer.CreateTemplate("My new template", "sample template description", insp, defaultTool, tags, toolFilter); return(newTemplate != null); }); }