<?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: draworder - an problem by select objects in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/draworder-an-problem-by-select-objects/m-p/7336221#M29874</link>
    <description>Hi!&lt;BR /&gt;&lt;BR /&gt;thanks, but EBL_SEL is only a test call to check if the selction works outside the draworder funktion.&lt;BR /&gt;&lt;BR /&gt;Jan&lt;BR /&gt;</description>
    <pubDate>Tue, 29 Aug 2017 14:51:04 GMT</pubDate>
    <dc:creator>jan_tappenbeck</dc:creator>
    <dc:date>2017-08-29T14:51:04Z</dc:date>
    <item>
      <title>draworder - an problem by select objects</title>
      <link>https://forums.autodesk.com/t5/net-forum/draworder-an-problem-by-select-objects/m-p/7335975#M29872</link>
      <description>&lt;P&gt;hi !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i want to create a draworder-function with a subfunction to select object by layer-filter.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the function to select the elements is following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; Public Function GetEntitiesOnLayer(layerName As String) As ObjectIdCollection
        ' http://ma22-wiki-001/eblwiki/index.php?title=Acad_(Klasse_von_EBL.Service)#GetEntitiesOnLayer
        ' Quelle: http://through-the-interface.typepad.com/through_the_interface/2008/05/finding-all-the.html
        Dim doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim ed As Editor = doc.Editor
        ' Build a filter list so that only entities
        ' on the specified layer are selected
        Dim tvs As TypedValue() = New TypedValue(0) {New TypedValue(CInt(DxfCode.LayerName), layerName)}
        Dim sf As New SelectionFilter(tvs)
        Dim psr As PromptSelectionResult = ed.SelectAll(sf)

        If psr.Status = PromptStatus.OK Then
            Return New ObjectIdCollection(psr.Value.GetObjectIds())
        Else
            Return New ObjectIdCollection()
        End If
    End Function&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the draworder-main function is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; ''' &amp;lt;summary&amp;gt;
    ''' ändern der Zeichenreihenfolge - HINTERgrund
    ''' &amp;lt;/summary&amp;gt;
    ''' &amp;lt;param name="LayerFilter"&amp;gt;Filter für die Layernamen&amp;lt;/param&amp;gt;
    ''' &amp;lt;param name="Log"&amp;gt;optional byref Log (default:= LEERSTRING)&amp;lt;/param&amp;gt;
    ''' &amp;lt;returns&amp;gt;true ... ok / false ....mit Fehler&amp;lt;/returns&amp;gt;
    Public Function DrawOrderChangeToButtom(ByVal LayerFilter As String, Optional ByRef Log As String = "") As Boolean
        _Editor.WriteMessage("Objekte in den Hintergrund verschieben ...")
        DrawOrderChange_Work(LayerFilter, 0, Log)
    End Function
    ''' &amp;lt;summary&amp;gt;
    ''' ändern der Zeichenreihenfolge - VORDERgrund
    ''' &amp;lt;/summary&amp;gt;
    ''' &amp;lt;param name="LayerFilter"&amp;gt;Filter für die Layernamen&amp;lt;/param&amp;gt;
    ''' &amp;lt;param name="Log"&amp;gt;optional byref Log (default:= LEERSTRING)&amp;lt;/param&amp;gt;
    ''' &amp;lt;returns&amp;gt;true ... ok / false ....mit Fehler&amp;lt;/returns&amp;gt;
    Public Function DrawOrderChangeToTop(ByVal LayerFilter As String, Optional ByRef Log As String = "") As Boolean
        _Editor.WriteMessage("Objekte in den Vordergrund verschieben ...")
        DrawOrderChange_Work(LayerFilter, 1, Log)
    End Function
    ''' &amp;lt;summary&amp;gt;
    ''' ändern der Zeichenreihenfolge - Arbeitsfunktion
    ''' &amp;lt;/summary&amp;gt;
    ''' &amp;lt;param name="LayerFilter"&amp;gt;Filter für die Layernamen&amp;lt;/param&amp;gt;
    ''' &amp;lt;param name="Status"&amp;gt;0 .... 2Buttom / 1 ... 2Top&amp;lt;/param&amp;gt;
    ''' &amp;lt;param name="Log"&amp;gt;optional byref Log (default:= LEERSTRING)&amp;lt;/param&amp;gt;
    ''' &amp;lt;returns&amp;gt;true ... ok / false ....mit Fehler&amp;lt;/returns&amp;gt;
    Private Function DrawOrderChange_Work(ByVal LayerFilter As String, ByVal Status As Short, Optional ByRef Log As String = "") As Boolean

        AcReInit()
        Dim Obj2Move As ObjectIdCollection = GetEntitiesOnLayer(LayerFilter)
        Dim drawOrder As New SortedList(Of Long, ObjectId)()

        If LayerFilter.Length = 0 Then
            Log += "kein Layerfilter angegeben!"
            Return False
        End If

        Dim Msg As String = "keine Objekte gefiltert!"
        If Obj2Move.Count = 0 Then
            _Editor.WriteMessage(Msg)
            Log += Msg
            Return True
        End If

        Msg = "Anzahl gefilterter Objekte: " &amp;amp; Obj2Move.Count.ToString
        _Editor.WriteMessage(Msg)
        Log += Msg

        Try
            Using tr As Transaction = _Database.TransactionManager.StartTransaction()

                Dim bt As BlockTable = TryCast(tr.GetObject(_Database.BlockTableId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead), BlockTable)
                Dim btrModelSpace As BlockTableRecord = TryCast(tr.GetObject(bt(BlockTableRecord.ModelSpace), Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead), BlockTableRecord)
                Dim dot As DrawOrderTable = TryCast(tr.GetObject(btrModelSpace.DrawOrderTableId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForWrite), DrawOrderTable)
                Dim objToMove As New ObjectIdCollection()

                ''For i As Integer = 0 To Obj2Move.Count - 1
                ''    objToMove.Add(Obj2Move(i))
                ''Next i

                Select Case Status
                    Case 0
                        dot.MoveToBottom(Obj2Move)
                    Case 1
                        dot.MoveToTop(Obj2Move)

                End Select

                tr.Commit()
            End Using

        Catch ex As Exception
            Log += "unerwarteter Fehler in EBL.Service &amp;gt; Acad &amp;gt; DrawOrder" &amp;amp; vbCrLf &amp;amp; ex.ToString
            Return False
        End Try

        Return True
    End Function&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the problem is to select the objects.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if i call GetEntitiesOnLayer by a text-call&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;    &amp;lt;LispFunction("EBL_SEL")&amp;gt; _
    Public Sub EBL_SEL(ByVal rbArgs As ResultBuffer)
        GetEntitiesOnLayer("Grün")
    End Sub&lt;/PRE&gt;&lt;P&gt;it works!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if i call the draworder-function there is in line&lt;/P&gt;&lt;PRE&gt;If psr.Status = PromptStatus.OK Then&lt;/PRE&gt;&lt;P&gt;of GetEntitiesOnLayer&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;psr.Status = Error {-5001}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;could someone tell me why?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;reagards Jan&lt;/P&gt;</description>
      <pubDate>Tue, 29 Aug 2017 13:52:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/draworder-an-problem-by-select-objects/m-p/7335975#M29872</guid>
      <dc:creator>jan_tappenbeck</dc:creator>
      <dc:date>2017-08-29T13:52:28Z</dc:date>
    </item>
    <item>
      <title>Re: draworder - an problem by select objects</title>
      <link>https://forums.autodesk.com/t5/net-forum/draworder-an-problem-by-select-objects/m-p/7336109#M29873</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm not sure to fully understand the question, but I saw some things in the code you should pay attention to.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your GetEntitiesOnLayer() method returns an ObjectIdCollection instance. AFAIK there's no LISP equivalent to this type.&lt;/P&gt;
&lt;P&gt;Your LispFunction should return a ResultBuffer which will be converted into a LISP list.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another thing, the DrawOrderTable is related to a specific BlockTableRecord (ModelSpace in your code) so, your SelectionFilter should also filter the space.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        public ObjectIdCollection GetEntititesOnLayer(string layerPattern)
        {
            var ed = AcAp.DocumentManager.MdiActiveDocument.Editor;
            var psr = ed.SelectAll(new SelectionFilter(
                new[] { new TypedValue(8, layerPattern), new TypedValue(410, "Model") }));
            if (psr.Status == PromptStatus.OK)
                return new ObjectIdCollection(psr.Value.GetObjectIds());
            return new ObjectIdCollection();
        }

        [LispFunction("EBL_SEL")]
        public ResultBuffer EBL_SEL(ResultBuffer resbuf)
        {
            var ids = GetEntititesOnLayer("0");
            if (ids.Count == 0)
                return null;
            var retVal = new ResultBuffer();
            foreach (ObjectId  id in ids)
            {
                retVal.Add(new TypedValue((int)LispDataType.ObjectId, id));
            }
            return retVal;
        }&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Aug 2017 14:26:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/draworder-an-problem-by-select-objects/m-p/7336109#M29873</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2017-08-29T14:26:52Z</dc:date>
    </item>
    <item>
      <title>Re: draworder - an problem by select objects</title>
      <link>https://forums.autodesk.com/t5/net-forum/draworder-an-problem-by-select-objects/m-p/7336221#M29874</link>
      <description>Hi!&lt;BR /&gt;&lt;BR /&gt;thanks, but EBL_SEL is only a test call to check if the selction works outside the draworder funktion.&lt;BR /&gt;&lt;BR /&gt;Jan&lt;BR /&gt;</description>
      <pubDate>Tue, 29 Aug 2017 14:51:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/draworder-an-problem-by-select-objects/m-p/7336221#M29874</guid>
      <dc:creator>jan_tappenbeck</dc:creator>
      <dc:date>2017-08-29T14:51:04Z</dc:date>
    </item>
    <item>
      <title>Re: draworder - an problem by select objects</title>
      <link>https://forums.autodesk.com/t5/net-forum/draworder-an-problem-by-select-objects/m-p/7336363#M29875</link>
      <description>&lt;P&gt;This seems to work for me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;

namespace DrawOrderByLayer
{
    public class Commands
    {
        enum MoveDrawOrder { ToBottom, ToTop }

        [CommandMethod("LAYERTOTOP")]
        public void SetLayerToTop()
        {
            DrawOrderByLayer(GetEntititesOnLayer(), MoveDrawOrder.ToTop);
        }

        [CommandMethod("LAYERTOBOTTOM")]
        public void SetLayerToBottom()
        {
            DrawOrderByLayer(GetEntititesOnLayer(), MoveDrawOrder.ToBottom);
        }

        private ObjectIdCollection GetEntititesOnLayer()
        {
            var ed = Application.DocumentManager.MdiActiveDocument.Editor;
            var pso = new PromptStringOptions("\nEnter the layer name: ");
            pso.AllowSpaces = true;
            var pr = ed.GetString(pso);
            if (pr.Status != PromptStatus.OK)
                return null;
            var layerName = pr.StringResult;
            if (string.IsNullOrWhiteSpace(layerName))
                return null;
            var psr = ed.SelectAll(new SelectionFilter(
                new[] { new TypedValue(8, layerName), new TypedValue(410, "Model") }));
            if (psr.Status != PromptStatus.OK)
            {
                ed.WriteMessage($"\nNone object found on layer: {layerName}");
                return null;
            }
            return new ObjectIdCollection(psr.Value.GetObjectIds());
        }

        private void DrawOrderByLayer(ObjectIdCollection ids, MoveDrawOrder order)
        {
            if (ids == null) return;
            var db = HostApplicationServices.WorkingDatabase;
            using (var tr = db.TransactionManager.StartTransaction())
            {
                var ms = (BlockTableRecord)tr.GetObject(
                    SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForRead);
                var dot = (DrawOrderTable)tr.GetObject(ms.DrawOrderTableId, OpenMode.ForWrite);
                if (order == MoveDrawOrder.ToBottom)
                    dot.MoveToBottom(ids);
                else
                    dot.MoveToTop(ids);
                tr.Commit();
            }
        }
    }
}&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Aug 2017 15:44:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/draworder-an-problem-by-select-objects/m-p/7336363#M29875</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2017-08-29T15:44:58Z</dc:date>
    </item>
  </channel>
</rss>

