<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic My code don't work in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/my-code-don-t-work/m-p/8772639#M42598</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;Where is my mistake?&lt;BR /&gt;Thank you&lt;/P&gt;
&lt;PRE&gt;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&amp;lt;Reference&amp;gt; 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 &amp;lt; 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;
        }   
    }
}&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 06 May 2019 09:21:50 GMT</pubDate>
    <dc:creator>arnaudgenty</dc:creator>
    <dc:date>2019-05-06T09:21:50Z</dc:date>
    <item>
      <title>My code don't work</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/my-code-don-t-work/m-p/8772639#M42598</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;Where is my mistake?&lt;BR /&gt;Thank you&lt;/P&gt;
&lt;PRE&gt;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&amp;lt;Reference&amp;gt; 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 &amp;lt; 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;
        }   
    }
}&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 May 2019 09:21:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/my-code-don-t-work/m-p/8772639#M42598</guid>
      <dc:creator>arnaudgenty</dc:creator>
      <dc:date>2019-05-06T09:21:50Z</dc:date>
    </item>
    <item>
      <title>Re: My code don't work</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/my-code-don-t-work/m-p/8772670#M42599</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/7246373"&gt;@arnaudgenty&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;In AddLine method,just add the following code to create a line in the document&lt;/P&gt;
&lt;PRE&gt;Line newLine = null;
                newLine = Line.CreateBound(LocalocationStartPoint, LocalocationEndPoint);
                &lt;STRONG&gt;XYZ origin = new XYZ(0, 0, 0);
                XYZ normal = new XYZ(0, 10, 0);
                Plane p = Plane.CreateByNormalAndOrigin(normal, origin);
                SketchPlane sp = SketchPlane.Create(doc, p);
                ModelLine ML = doc.Create.NewModelCurve(newLine, sp) as ModelLine;&lt;/STRONG&gt;&lt;/PRE&gt;
&lt;P&gt;If this helped solve your problem please mark it as solution, so other users can get this solutions as well&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://forums.autodesk.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 06 May 2019 09:43:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/my-code-don-t-work/m-p/8772670#M42599</guid>
      <dc:creator>naveen.kumar.t</dc:creator>
      <dc:date>2019-05-06T09:43:16Z</dc:date>
    </item>
    <item>
      <title>Re: My code don't work</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/my-code-don-t-work/m-p/8773134#M42600</link>
      <description>&lt;P&gt;Thank you for your answer.&lt;/P&gt;
&lt;P&gt;With your code, I have this message :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"Curve must be in the plane&lt;/P&gt;
&lt;P&gt;Parameter name: pCurveCopyA transaction or sub-transaction was opened but not closed. All changes to the active document made by External Command will be discarded."&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt; Transaction trans = new Transaction(doc, "Add Line");
            trans.Start();

            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 = line.GetEndPoint(1);
            XYZ LocalocationStartPoint = new XYZ();
            LocalocationStartPoint = line.GetEndPoint(0);
            Line newLine = Line.CreateBound(LocalocationStartPoint, LocalocationEndPoint);
            XYZ origin = new XYZ (0, 0, 0);
            XYZ normal = new XYZ(0, 10, 0);
            Plane p = Plane.CreateByNormalAndOrigin(normal,origin);
            SketchPlane sp = SketchPlane.Create(doc, p);
            ModelLine ML = doc.Create.NewModelCurve(newLine, sp) as ModelLine;

            trans.Commit();
            
            return true;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 May 2019 13:32:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/my-code-don-t-work/m-p/8773134#M42600</guid>
      <dc:creator>arnaudgenty</dc:creator>
      <dc:date>2019-05-06T13:32:20Z</dc:date>
    </item>
    <item>
      <title>Re: My code don't work</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/my-code-don-t-work/m-p/8774673#M42601</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/7246373"&gt;@arnaudgenty&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;I think the problem lies with the normal of the plane&lt;/P&gt;
&lt;PRE&gt;XYZ normal = new XYZ(1, 1, 0);&lt;/PRE&gt;
&lt;P&gt;I hope this helps&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2019 05:17:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/my-code-don-t-work/m-p/8774673#M42601</guid>
      <dc:creator>naveen.kumar.t</dc:creator>
      <dc:date>2019-05-07T05:17:19Z</dc:date>
    </item>
    <item>
      <title>Re: My code don't work</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/my-code-don-t-work/m-p/8774975#M42602</link>
      <description>&lt;P&gt;There was still a problem. In fact it was necessary:&lt;/P&gt;
&lt;P&gt;XYZ normal = new XYZ(0, 0, 1);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the created curve is at the axis. How to say that we want the outer or inner curve of the wall?&lt;BR /&gt;I searched on BuildingCoder but I found nothing (or understood ...)&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2019 08:17:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/my-code-don-t-work/m-p/8774975#M42602</guid>
      <dc:creator>arnaudgenty</dc:creator>
      <dc:date>2019-05-07T08:17:07Z</dc:date>
    </item>
  </channel>
</rss>

