Message 1 of 5
My code don't work
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi
I start on the API. I want to draw a line from my walls, then make a dimension. I don't have error message, but my lines are never drawn.
Where is my mistake?
Thank you
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Autodesk.Revit.ApplicationServices; using Autodesk.Revit.Attributes; using Autodesk.Revit.DB; using Autodesk.Revit.UI; using Autodesk.Revit.UI.Selection; using Autodesk.Revit.DB.Structure; namespace Mypluggin { [Transaction(TransactionMode.Manual)] [Regeneration(RegenerationOption.Manual)] public class Class1 : IExternalCommand { ExternalCommandData m_commandData = null; //store external command public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { m_commandData = commandData; //Get application and documnet objects UIApplication uiapp = commandData.Application; Document doc = uiapp.ActiveUIDocument.Document; try { IList<Reference> pickedRef = null; ElementArray elem = new ElementArray(); Selection sel = uiapp.ActiveUIDocument.Selection; // classe WallPickFilter qui filtre la sélection des murs WallPickFilter selFilter = new WallPickFilter(); // pickedRef = liste des murs sélectionnés pickedRef = sel.PickObjects(ObjectType.Element, selFilter, "Please select walls"); // nombre de murs sélectionnés int Num_Wall = pickedRef.Count(); for (int i = 0; i < Num_Wall; i++) { Transaction trans = new Transaction(m_commandData.Application.ActiveUIDocument.Document, "Add Line"); trans.Start(); Reference picked = null; picked = pickedRef[i]; Element eleme = doc.GetElement(picked); AddLine(eleme, picked); trans.Commit(); } } // If the user right clicks or presses Echap, handle the expression catch catch (Autodesk.Revit.Exceptions.OperationCanceledException) { return Result.Cancelled; } // Catch other errors catch (Exception ex) { message = ex.Message; } return Result.Succeeded; } public class WallPickFilter : ISelectionFilter { public bool AllowElement(Element e) { return (e.Category.Id.IntegerValue.Equals((int)BuiltInCategory.OST_Walls)); } public bool AllowReference(Reference r, XYZ p) { return false; } } public bool AddLine(Element elem, Reference picked) { Autodesk.Revit.UI.UIApplication app = m_commandData.Application; Document doc = app.ActiveUIDocument.Document; Location location = elem.Location; //get location curve LocationCurve locationline = location as LocationCurve; Line line = locationline.Curve as Line; //New Line XYZ LocalocationEndPoint = new XYZ(); LocalocationEndPoint = locationline.Curve.GetEndPoint(1); XYZ LocalocationStartPoint = new XYZ(); LocalocationStartPoint = locationline.Curve.GetEndPoint(0); Line newLine = null; newLine = Line.CreateBound(LocalocationStartPoint, LocalocationEndPoint); return true; } } }