<?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 find the total number of lines with an angle equal to a selected line in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/find-the-total-number-of-lines-with-an-angle-equal-to-a-selected/m-p/10528025#M15564</link>
    <description>&lt;P&gt;Hello everybody.&lt;BR /&gt;In a drawing I want to find the total number of lines with an angle equal to a selected line.&lt;BR /&gt;I tried this way.&lt;/P&gt;&lt;LI-CODE lang="general"&gt;    Private Sub Button_Click(sender As Object, e As EventArgs) Handles Button.Click

        Dim Dwg_Doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim Dwg_Db As Database = Dwg_Doc.Database
        Dim Dwg_Editor As Editor = Dwg_Doc.Editor

        Dim Line As Line
        Dim Angle_Line As Double

        Dim Sel_Line As PromptEntityResult = Dwg_Editor.GetEntity("Select the line: ")

        Using Trans As Transaction = Dwg_Db.TransactionManager.StartTransaction()
            Line = Sel_Line.ObjectId.GetObject(OpenMode.ForRead)
            Angle_Line = Linea.Angle
        End Using

        Dim Elenco_Filtri() As TypedValue = New TypedValue() {
            New TypedValue(DxfCode.Start, "LINE"),
            New TypedValue(DxfCode.Operator, "="),
            New TypedValue(DxfCode.Angle, Angle_Line)
            }

        Dim Linee_Filtrate_Sel As SelectionFilter = New SelectionFilter(Elenco_Filtri)
        Dim Linee_Filtrate As PromptSelectionResult = Dwg_Editor.SelectAll(Linee_Filtrate_Sel)

        MsgBox("Number line: " &amp;amp; Linee_Filtrate.Value.Count.ToString)
    End Sub&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;This exception is thrown:&lt;BR /&gt;"System.NullReferenceException: Reference to an object not set to an object instance.&lt;BR /&gt;Autodesk.AutoCAD.EditorInput.PromptSelectionResult.Value.get returned Nothing. "&lt;BR /&gt;Where do you think I'm wrong?&lt;BR /&gt;Thanks a lot, bye.&lt;/P&gt;</description>
    <pubDate>Sat, 07 Aug 2021 17:17:34 GMT</pubDate>
    <dc:creator>mecoman6GF27</dc:creator>
    <dc:date>2021-08-07T17:17:34Z</dc:date>
    <item>
      <title>find the total number of lines with an angle equal to a selected line</title>
      <link>https://forums.autodesk.com/t5/net-forum/find-the-total-number-of-lines-with-an-angle-equal-to-a-selected/m-p/10528025#M15564</link>
      <description>&lt;P&gt;Hello everybody.&lt;BR /&gt;In a drawing I want to find the total number of lines with an angle equal to a selected line.&lt;BR /&gt;I tried this way.&lt;/P&gt;&lt;LI-CODE lang="general"&gt;    Private Sub Button_Click(sender As Object, e As EventArgs) Handles Button.Click

        Dim Dwg_Doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim Dwg_Db As Database = Dwg_Doc.Database
        Dim Dwg_Editor As Editor = Dwg_Doc.Editor

        Dim Line As Line
        Dim Angle_Line As Double

        Dim Sel_Line As PromptEntityResult = Dwg_Editor.GetEntity("Select the line: ")

        Using Trans As Transaction = Dwg_Db.TransactionManager.StartTransaction()
            Line = Sel_Line.ObjectId.GetObject(OpenMode.ForRead)
            Angle_Line = Linea.Angle
        End Using

        Dim Elenco_Filtri() As TypedValue = New TypedValue() {
            New TypedValue(DxfCode.Start, "LINE"),
            New TypedValue(DxfCode.Operator, "="),
            New TypedValue(DxfCode.Angle, Angle_Line)
            }

        Dim Linee_Filtrate_Sel As SelectionFilter = New SelectionFilter(Elenco_Filtri)
        Dim Linee_Filtrate As PromptSelectionResult = Dwg_Editor.SelectAll(Linee_Filtrate_Sel)

        MsgBox("Number line: " &amp;amp; Linee_Filtrate.Value.Count.ToString)
    End Sub&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;This exception is thrown:&lt;BR /&gt;"System.NullReferenceException: Reference to an object not set to an object instance.&lt;BR /&gt;Autodesk.AutoCAD.EditorInput.PromptSelectionResult.Value.get returned Nothing. "&lt;BR /&gt;Where do you think I'm wrong?&lt;BR /&gt;Thanks a lot, bye.&lt;/P&gt;</description>
      <pubDate>Sat, 07 Aug 2021 17:17:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/find-the-total-number-of-lines-with-an-angle-equal-to-a-selected/m-p/10528025#M15564</guid>
      <dc:creator>mecoman6GF27</dc:creator>
      <dc:date>2021-08-07T17:17:34Z</dc:date>
    </item>
    <item>
      <title>Re: find the total number of lines with an angle equal to a selected line</title>
      <link>https://forums.autodesk.com/t5/net-forum/find-the-total-number-of-lines-with-an-angle-equal-to-a-selected/m-p/10529339#M15565</link>
      <description>&lt;P&gt;When you get runtime exception, the first thing to do, if you cannot identify the cause of the error from the error message (but in your case the exception message is fairly obvious), is to step through the code in debugging, which would easily/quickly leads you to the offending line of code. At that point, you probably have a clear idea of what is wrong with that line of code. So, my question is have you done the basic debugging before asking question here?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The error you get is likely from this line:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class="lia-code-sample  language-general"&gt;&lt;CODE&gt;Line = Sel_Line.ObjectId.GetObject(OpenMode.ForRead)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;where you use &lt;EM&gt;Sel_Line&lt;/EM&gt; of PromptEntityResult obtained from Editor.GetEntity().&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The good practice of using PromptXXXXResult returned from Editor.GetXxxx() methods is ALWAYS test its Status property and proceed according to Status property's value, because when user does selecting, he/she could select entity/enter keyword/hit Esc to cancel, enter invalid input, select wrong entity... thus the reason to test Status. so the code should be like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Dim SlL_Lline As PromptEntityResult = Dwg_Editor.GetEntity(...)&lt;/P&gt;
&lt;P&gt;If Sel_Line.Status = PromptStatus.Ok Then&lt;/P&gt;
&lt;P&gt;&amp;nbsp; '' Proceed, because an valid entity is selected&lt;/P&gt;
&lt;P&gt;End If&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, with your requirement, you may want to make sure you only allow user to pick a Line, not anything else. So, you may want to use PromptEntityOptions with the Editor.GetEntity(). In the PromptEntityOptions, you add Line as allowed entity.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 08 Aug 2021 16:44:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/find-the-total-number-of-lines-with-an-angle-equal-to-a-selected/m-p/10529339#M15565</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2021-08-08T16:44:23Z</dc:date>
    </item>
    <item>
      <title>Re: find the total number of lines with an angle equal to a selected line</title>
      <link>https://forums.autodesk.com/t5/net-forum/find-the-total-number-of-lines-with-an-angle-equal-to-a-selected/m-p/10531436#M15566</link>
      <description>&lt;P&gt;Hello norman.yuan.&lt;BR /&gt;I modified the code following your advice. Now I don't get any more exceptions but I still can't get the total number of lines with the angle equal to the selected line.&lt;BR /&gt;This is the code I wrote.&lt;/P&gt;&lt;LI-CODE lang="general"&gt;    Private Sub B_Filo_Esterno_Muro_Click(sender As Object, e As EventArgs) Handles B_Filo_Esterno_Muro.Click

        Dim Dwg_Doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim Dwg_Db As Database = Dwg_Doc.Database
        Dim Dwg_Editor As Editor = Dwg_Doc.Editor

        Dim Sel_Linea As PromptEntityOptions = New PromptEntityOptions(vbLf &amp;amp; "Seleziona una linea: ")
        Sel_Linea.SetRejectMessage(vbLf &amp;amp; "L'oggetto selezionato non è una linea!!!")
        Sel_Linea.AddAllowedClass(GetType(Line), True)

        Dim Sel_Linea_Result As PromptEntityResult = Dwg_Editor.GetEntity(Sel_Linea)

        If Sel_Linea_Result.Status = PromptStatus.OK Then
            Dim Linea_Angolo As Double

            Using Transazione As Transaction = Dwg_Db.TransactionManager.StartTransaction()
                Linea = Sel_Linea_Result.ObjectId.GetObject(OpenMode.ForRead)
                Linea_Angolo = Linea.Angle
            End Using

            Dim Linee_Elenco_Filtri() As TypedValue = New TypedValue() {
                            New TypedValue(DxfCode.Start, "LINE"),
                            New TypedValue(DxfCode.Operator, "="),
                            New TypedValue(DxfCode.Angle, Linea_Angolo)
            }

            Dim Linee_Filtrate_Sel As SelectionFilter = New SelectionFilter(Linee_Elenco_Filtri)
            Dim Linee_Filtrate As PromptSelectionResult = Dwg_Editor.GetSelection(Linee_Filtrate_Sel)

            If Linee_Filtrate.Status = PromptStatus.OK Then
                MsgBox("Numero linee: " &amp;amp; Linee_Filtrate.Value.Count.ToString)
            Else
                MsgBox("Nessuna linea")
            End If
        Else
            Me.Close()
        End If
    End Sub&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;Where do you think I'm wrong?&lt;BR /&gt;Thanks a lot, bye.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Aug 2021 14:54:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/find-the-total-number-of-lines-with-an-angle-equal-to-a-selected/m-p/10531436#M15566</guid>
      <dc:creator>mecoman6GF27</dc:creator>
      <dc:date>2021-08-09T14:54:19Z</dc:date>
    </item>
    <item>
      <title>Re: find the total number of lines with an angle equal to a selected line</title>
      <link>https://forums.autodesk.com/t5/net-forum/find-the-total-number-of-lines-with-an-angle-equal-to-a-selected/m-p/10537363#M15567</link>
      <description>&lt;P&gt;Not every Entity property can be filtered, using DxfCode, in SelectionFilter. In your case, the Line's Angle is not filter-able.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You would only apply filter to select all lines and then use your code to examine the line's Angle. Sometimes, you may want to choose how to gather a group of entities: using Editor.SelectXXXX() with filter, or simply loop through entities in current space with code. If your case, the latter often easier to code, where you do not have to build a filter to select and then loop through the selected lines for compare Angle, something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;var lineIds=new List&amp;lt;ObjectId&amp;gt;();&lt;/P&gt;
&lt;P&gt;using (var tran=TheDB.TransactionManager.StartTransaction())&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp; var model=...; //Open ModelSpace BlockTableRecord&lt;/P&gt;
&lt;P&gt;&amp;nbsp; foreach (ObjectId id in model)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; {&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; if (id.ObjectClass.DxfName!="LINE") continue;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; var line=(Line)tran.GetObject(id, OpenMode.ForRead);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; if (line.Angle=[theAngle]) lineIds.Add(id)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; }&lt;/P&gt;
&lt;P&gt;&amp;nbsp; tran.Commit();&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;//Now you have a list of ObjectId of lines that have the same angle&lt;/P&gt;</description>
      <pubDate>Wed, 11 Aug 2021 13:44:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/find-the-total-number-of-lines-with-an-angle-equal-to-a-selected/m-p/10537363#M15567</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2021-08-11T13:44:07Z</dc:date>
    </item>
    <item>
      <title>Re: find the total number of lines with an angle equal to a selected line</title>
      <link>https://forums.autodesk.com/t5/net-forum/find-the-total-number-of-lines-with-an-angle-equal-to-a-selected/m-p/10542460#M15568</link>
      <description>&lt;P&gt;Hello &lt;A href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/543921" target="_self"&gt;&lt;SPAN class="login-bold"&gt;norman.yuan&lt;/SPAN&gt;&lt;/A&gt;, thanks a lot.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Aug 2021 07:27:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/find-the-total-number-of-lines-with-an-angle-equal-to-a-selected/m-p/10542460#M15568</guid>
      <dc:creator>mecoman6GF27</dc:creator>
      <dc:date>2021-08-13T07:27:41Z</dc:date>
    </item>
    <item>
      <title>Re: find the total number of lines with an angle equal to a selected line</title>
      <link>https://forums.autodesk.com/t5/net-forum/find-the-total-number-of-lines-with-an-angle-equal-to-a-selected/m-p/10543398#M15569</link>
      <description>&lt;P&gt;If you type @, you don't have to hyperlink to a user's profile. Plus, when you use @, it sends them an email of your post.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Aug 2021 14:30:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/find-the-total-number-of-lines-with-an-angle-equal-to-a-selected/m-p/10543398#M15569</guid>
      <dc:creator>Ed__Jobe</dc:creator>
      <dc:date>2021-08-13T14:30:05Z</dc:date>
    </item>
  </channel>
</rss>

