<?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 Re: Casting selectionset object to acadpolyline in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/casting-selectionset-object-to-acadpolyline/m-p/5464409#M41777</link>
    <description>&lt;P&gt;Yuan - &amp;nbsp;this works&lt;/P&gt;&lt;P&gt;I was using three separate code segments for AcadPolyLine, AcadLWPolyline &amp;amp; Acad3DPolyline. The segment for AcadPolyline was not necessary on the first place, because as you said, both are same and AcadLWPolyline is the appropriate COM object I should have used.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;This line solves the problem -&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;"In your code, since you test ObjectName="AcadPolyline", which is AcadLWPolyline, yet you try to cast it to AcadPolyline, not AcadLWPolyline. This could be the cause of problem, assuming the selectionset is a COM object."&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And yes, my selectionset is AcadSelectionSet which is a COM object&lt;/P&gt;</description>
    <pubDate>Fri, 09 Jan 2015 18:57:38 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2015-01-09T18:57:38Z</dc:date>
    <item>
      <title>Casting selectionset object to acadpolyline</title>
      <link>https://forums.autodesk.com/t5/net-forum/casting-selectionset-object-to-acadpolyline/m-p/5463691#M41771</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am trying to access properties such as polyline.closed, from polylines in a selection set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I use code as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;dim pl as acadpolyline&lt;/P&gt;&lt;P&gt;IF selectionset.item(i).objectname = "AcDbPolyline" Then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;lt;&amp;lt;Here I need to cast the object as acadpolyline &amp;gt;&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Endif&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried with:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;SPAN style="line-height: 15px;"&gt;pl =&amp;nbsp;&lt;/SPAN&gt;selectionset.item(i)&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="line-height: 15px;"&gt;pl = document.handletoobject(&lt;/SPAN&gt;selectionset.item(i).handle)&lt;/LI&gt;&lt;LI&gt;for each pl in selection if pl.handle =&amp;nbsp;&lt;SPAN&gt;selectionset.item(i).handle then ......&lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;SPAN&gt;All attempts give error as:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Unable to cast COM object of type AcadentityClass to interface type AcadPolyline&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I have refernces AcCoreMgd, AcDbMgd, AcMgd, AutoCAD.Interop &amp;amp; AutoCad.Interop.common&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Am I missing any libraries to cast acadentity into acadpolyline? Or what else am I missing?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks for all help in advance&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Mdshameer&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jan 2015 10:18:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/casting-selectionset-object-to-acadpolyline/m-p/5463691#M41771</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-01-09T10:18:45Z</dc:date>
    </item>
    <item>
      <title>Re: Casting selectionset object to acadpolyline</title>
      <link>https://forums.autodesk.com/t5/net-forum/casting-selectionset-object-to-acadpolyline/m-p/5463700#M41772</link>
      <description>in c# Selection items are a list of ObjectId's.&lt;BR /&gt;Use the transaction to return te Object/Entity or specific EntityType, like so:&lt;BR /&gt;using (Transaction tr = doc.Database.TransactionManager.StartTransaction())&lt;BR /&gt;{&lt;BR /&gt;SelectionSet currentlySelectedEntities = selectionResult.Value;&lt;BR /&gt;foreach (ObjectId id in currentlySelectedEntities.GetObjectIds())&lt;BR /&gt;{&lt;BR /&gt;Entity ent = tr.GetObject(id, OpenMode.ForRead) as Entity;&lt;BR /&gt;//or&lt;BR /&gt;if (id.ObjectClass.DxfName=="LWPOLYLINE")&lt;BR /&gt;Polyline pl=tr.GetObject(id, OpenMode.ForRead) as Polyline;&lt;BR /&gt;if (pl != null)</description>
      <pubDate>Fri, 09 Jan 2015 10:45:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/casting-selectionset-object-to-acadpolyline/m-p/5463700#M41772</guid>
      <dc:creator>SENL1362</dc:creator>
      <dc:date>2015-01-09T10:45:56Z</dc:date>
    </item>
    <item>
      <title>Re: Casting selectionset object to acadpolyline</title>
      <link>https://forums.autodesk.com/t5/net-forum/casting-selectionset-object-to-acadpolyline/m-p/5463726#M41773</link>
      <description>&lt;P&gt;SENL&lt;/P&gt;&lt;P&gt;I am trying this. Meanwhile what may be the difference between&lt;/P&gt;&lt;P&gt;document.objectidtoobject and tr.getobj()&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jan 2015 11:20:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/casting-selectionset-object-to-acadpolyline/m-p/5463726#M41773</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-01-09T11:20:07Z</dc:date>
    </item>
    <item>
      <title>Re: Casting selectionset object to acadpolyline</title>
      <link>https://forums.autodesk.com/t5/net-forum/casting-selectionset-object-to-acadpolyline/m-p/5463747#M41774</link>
      <description>&lt;P&gt;SENL&lt;/P&gt;&lt;P&gt;I dont have classes such as selectionset, entity and polyline on my code.&lt;/P&gt;&lt;P&gt;These are acadselectionset, acadentity and acadpolyline on my code&lt;/P&gt;&lt;P&gt;I believe this is a problem with reference to use COM and .NET entities&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;mdshameer&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jan 2015 11:37:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/casting-selectionset-object-to-acadpolyline/m-p/5463747#M41774</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-01-09T11:37:42Z</dc:date>
    </item>
    <item>
      <title>Re: Casting selectionset object to acadpolyline</title>
      <link>https://forums.autodesk.com/t5/net-forum/casting-selectionset-object-to-acadpolyline/m-p/5463753#M41775</link>
      <description>sorry about that, i didn't knew you are using an out of process implementation.&lt;BR /&gt;A won't be able to help because i have no experience with that.&lt;BR /&gt;</description>
      <pubDate>Fri, 09 Jan 2015 11:44:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/casting-selectionset-object-to-acadpolyline/m-p/5463753#M41775</guid>
      <dc:creator>SENL1362</dc:creator>
      <dc:date>2015-01-09T11:44:12Z</dc:date>
    </item>
    <item>
      <title>Re: Casting selectionset object to acadpolyline</title>
      <link>https://forums.autodesk.com/t5/net-forum/casting-selectionset-object-to-acadpolyline/m-p/5463984#M41776</link>
      <description>&lt;P&gt;The code shows you use COM object (AcadPolyline), however it is not clear what the SelectionSet in your code is, COM object AcadSelectionSet, or Autodesk.AutoCAD.EditorInput.SelectionSet?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You'd better show more code (or describe more details) on how the SelectionSet is created/obtained.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another thing: are you sure the entities you selected are COM AcadPolyline (Polyline2d in .NET API), not AcadLWPolyline (Polyline in .NET API)? AcadPolyline was only used in earler version of AutoCAD. If people refer "polyline" in AutoCAD, it is usually "AcadLWPolyline" (COM) or "Polyline" (.NET). If the polyline is in 3D, then it is Acad3DPolyline or Polyline3d.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your code, since you test ObjectName="AcadPolyline", which is AcadLWPolyline, yet you try to cast it to AcadPolyline, not AcadLWPolyline. This could be the cause of problem, assuming the selectionset is a COM object.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, the possible problem with your code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. you cannot cast object direcctly betweem COM object and .NET object;&lt;/P&gt;
&lt;P&gt;2. you need to make sure you know what the&amp;nbsp;polyline is, AcadLWPolyline, or Acad3DPolyline, or the old AcadPolyline, to cast it correctly&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jan 2015 14:42:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/casting-selectionset-object-to-acadpolyline/m-p/5463984#M41776</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2015-01-09T14:42:59Z</dc:date>
    </item>
    <item>
      <title>Re: Casting selectionset object to acadpolyline</title>
      <link>https://forums.autodesk.com/t5/net-forum/casting-selectionset-object-to-acadpolyline/m-p/5464409#M41777</link>
      <description>&lt;P&gt;Yuan - &amp;nbsp;this works&lt;/P&gt;&lt;P&gt;I was using three separate code segments for AcadPolyLine, AcadLWPolyline &amp;amp; Acad3DPolyline. The segment for AcadPolyline was not necessary on the first place, because as you said, both are same and AcadLWPolyline is the appropriate COM object I should have used.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;This line solves the problem -&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;"In your code, since you test ObjectName="AcadPolyline", which is AcadLWPolyline, yet you try to cast it to AcadPolyline, not AcadLWPolyline. This could be the cause of problem, assuming the selectionset is a COM object."&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And yes, my selectionset is AcadSelectionSet which is a COM object&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jan 2015 18:57:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/casting-selectionset-object-to-acadpolyline/m-p/5464409#M41777</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-01-09T18:57:38Z</dc:date>
    </item>
  </channel>
</rss>

