<?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: Required codign in .net in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/required-codign-in-net/m-p/6835213#M33019</link>
    <description>&lt;P&gt;Many Thanks,&lt;BR /&gt;&lt;BR /&gt;I am getting errors, attached image,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Could please tell me what to do?&lt;/P&gt;</description>
    <pubDate>Fri, 27 Jan 2017 10:08:09 GMT</pubDate>
    <dc:creator>waseefur.rahman</dc:creator>
    <dc:date>2017-01-27T10:08:09Z</dc:date>
    <item>
      <title>Required codign in .net</title>
      <link>https://forums.autodesk.com/t5/net-forum/required-codign-in-net/m-p/6830164#M33015</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;I am a .net learner,&lt;BR /&gt;&lt;BR /&gt;I want to create a coding to copy 3D Solid in Same place with different layer,&lt;/P&gt;&lt;P&gt;(i.e) I am having object in Layer 1,&lt;BR /&gt;coding should ask to select object,&lt;BR /&gt;then create a copy in layer 2 in same place.&lt;BR /&gt;Could any provide me a coding on this?&lt;BR /&gt;&lt;BR /&gt;Thanks &amp;amp; Regards&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2017 14:30:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/required-codign-in-net/m-p/6830164#M33015</guid>
      <dc:creator>waseefur.rahman</dc:creator>
      <dc:date>2017-01-25T14:30:22Z</dc:date>
    </item>
    <item>
      <title>Re: Required codign in .net</title>
      <link>https://forums.autodesk.com/t5/net-forum/required-codign-in-net/m-p/6833211#M33016</link>
      <description>&lt;P&gt;The following function can clone any Entity and change i'ts layer.&lt;/P&gt;&lt;P&gt;I also use an additional function to check if the entered layer exists.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Customization;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Application = Autodesk.AutoCAD.ApplicationServices.Application;

namespace AutodeskAppStoreTesting
{
    public class Commands : IExtensionApplication
    { 
       [CommandMethod("ChangeLayerOfSelected", CommandFlags.UsePickSet)]
        public static void ChangeLayerOfSelected()
        {
                        Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            Database db = doc.Database;

            ObjectIdCollection Entities = null;

            var PSelection = ed.SelectImplied();
            if (PSelection.Status != PromptStatus.OK || PSelection.Value.Count == 0)
            {
                var Selection = ed.GetSelection(new PromptSelectionOptions()
                {
                    MessageForAdding = "\nSelect Entities to Change Layer",
                });

                if (Selection.Status != PromptStatus.OK) return;

                Entities = new ObjectIdCollection();
                Entities.AddRange(Selection.Value.GetObjectIds());
            }
            else
            {
                Entities = new ObjectIdCollection();
                Entities.AddRange(PSelection.Value.GetObjectIds());
            }

            string LayerName = "";
            var LayerNamePrompt = ed.GetString(new PromptStringOptions("\nEnter Layer Name"));
            if (LayerNamePrompt.Status != PromptStatus.OK) return;

            LayerName = LayerNamePrompt.StringResult;
            MakeSureLayerExists(LayerName);

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                foreach (ObjectId n in Entities)
                {
                    Entity En = tr.GetObject(n, OpenMode.ForWrite) as Entity;
                    if (En == null) continue;

                    BlockTableRecord Owner = tr.GetObject(En.OwnerId, OpenMode.ForWrite) as BlockTableRecord;
                    if (Owner == null) continue;

                    string OldLayerName = En.Layer;

                    using (Entity NewEn = En.Clone() as Entity)
                    {
                        NewEn.Layer = LayerName;
                        Owner.AppendEntity(NewEn);
                        tr.AddNewlyCreatedDBObject(NewEn,true);
                    }

                    ed.WriteMessage("\nObject of type " + n.ObjectClass.Name + " has been duplicated with its layer changed from \"" + OldLayerName + "\" to \"" + LayerName + "\"");
                }
                tr.Commit();
            }
        }
        private static void MakeSureLayerExists(string LayerName)
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                var LayerTab = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;

                if (!LayerTab.Has(LayerName))
                {
                    using (var NewLayer = new LayerTableRecord())
                    {
                        NewLayer.Name = LayerName;

                        LayerTab.UpgradeOpen();
                        LayerTab.Add(NewLayer);
                        tr.AddNewlyCreatedDBObject(NewLayer, true);
                    }
                }
                tr.Commit();
            }
        }
    }
    public static class ObjectIdCollectionExtensions
    {
        public static void AddRange(this ObjectIdCollection a, ObjectId[] Range)
        {
            foreach (var n in Range)
            {
                a.Add(n);
            }
        }
    }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jan 2017 15:04:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/required-codign-in-net/m-p/6833211#M33016</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-01-26T15:04:09Z</dc:date>
    </item>
    <item>
      <title>Re: Required codign in .net</title>
      <link>https://forums.autodesk.com/t5/net-forum/required-codign-in-net/m-p/6833755#M33017</link>
      <description>Great..&lt;BR /&gt;Many thanks,&lt;BR /&gt;&lt;BR /&gt;Could you provide this coding in vb.net please..&lt;BR /&gt;&lt;BR /&gt;Also in coding you Said it's changing the selection to New layer.&lt;BR /&gt;&lt;BR /&gt;I will brief my question&lt;BR /&gt;When user selects the object,&lt;BR /&gt;Then coding need to create a copy of object to New layer.&lt;BR /&gt;&lt;BR /&gt;Also the selection object should be in same place.&lt;BR /&gt;&lt;BR /&gt;(i.e) We can take the coping &amp;amp; pasting pick point as same (0,0,0)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 26 Jan 2017 17:50:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/required-codign-in-net/m-p/6833755#M33017</guid>
      <dc:creator>waseefur.rahman</dc:creator>
      <dc:date>2017-01-26T17:50:56Z</dc:date>
    </item>
    <item>
      <title>Re: Required codign in .net</title>
      <link>https://forums.autodesk.com/t5/net-forum/required-codign-in-net/m-p/6833821#M33018</link>
      <description>&lt;P&gt;The posted code will create a copy in the same position of the selected objects to only then change the layer of the new objects.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ALthough VB.NET and C# have different syntaxes,&amp;nbsp;they can be&amp;nbsp;easily translated with almost no problem using a simple code converter.&lt;/P&gt;&lt;P&gt;Personally I prefer&amp;nbsp;&lt;A href="http://converter.telerik.com/" target="_self"&gt;Telerik's&lt;/A&gt;. Web-based free and pretty accurate...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below the converted code:&lt;/P&gt;&lt;PRE&gt;Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Customization
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.Runtime
Imports System.Collections.Generic
Imports System.Configuration
Imports System.Diagnostics
Imports System.IO
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports Application = Autodesk.AutoCAD.ApplicationServices.Application

Namespace AutodeskAppStoreTesting
    Public Class Commands
        Implements IExtensionApplication
        &amp;lt;CommandMethod("ChangeLayerOfSelected", CommandFlags.UsePickSet)&amp;gt; _
        Public Shared Sub ChangeLayerOfSelected()
            Dim doc As Document = Application.DocumentManager.MdiActiveDocument
            Dim ed As Editor = doc.Editor
            Dim db As Database = doc.Database

            Dim Entities As ObjectIdCollection = Nothing

            Dim PSelection = ed.SelectImplied()
            If PSelection.Status &amp;lt;&amp;gt; PromptStatus.OK OrElse PSelection.Value.Count = 0 Then
                Dim Selection = ed.GetSelection(New PromptSelectionOptions() With { _
                    Key .MessageForAdding = vbLf &amp;amp; "Select Entities to Change Layer" _
                })

                If Selection.Status &amp;lt;&amp;gt; PromptStatus.OK Then
                    Return
                End If

                Entities = New ObjectIdCollection()
                Entities.AddRange(Selection.Value.GetObjectIds())
            Else
                Entities = New ObjectIdCollection()
                Entities.AddRange(PSelection.Value.GetObjectIds())
            End If

            Dim LayerName As String = ""
            Dim LayerNamePrompt = ed.GetString(New PromptStringOptions(vbLf &amp;amp; "Enter Layer Name"))
            If LayerNamePrompt.Status &amp;lt;&amp;gt; PromptStatus.OK Then
                Return
            End If

            LayerName = LayerNamePrompt.StringResult
            MakeSureLayerExists(LayerName)

            Using tr As Transaction = db.TransactionManager.StartTransaction()
                For Each n As ObjectId In Entities
                    Dim En As Entity = TryCast(tr.GetObject(n, OpenMode.ForWrite), Entity)
                    If En Is Nothing Then
                        Continue For
                    End If

                    Dim Owner As BlockTableRecord = TryCast(tr.GetObject(En.OwnerId, OpenMode.ForWrite), BlockTableRecord)
                    If Owner Is Nothing Then
                        Continue For
                    End If

                    Dim OldLayerName As String = En.Layer

                    Using NewEn As Entity = TryCast(En.Clone(), Entity)
                        NewEn.Layer = LayerName
                        Owner.AppendEntity(NewEn)
                        tr.AddNewlyCreatedDBObject(NewEn, True)
                    End Using

                    ed.WriteMessage((Convert.ToString((Convert.ToString(vbLf &amp;amp; "Object of type " + n.ObjectClass.Name + " has been duplicated with its layer changed from """) &amp;amp; OldLayerName) + """ to """) &amp;amp; LayerName) + """")
                Next
                tr.Commit()
            End Using
        End Sub
        Private Shared Sub MakeSureLayerExists(LayerName As String)
            Dim doc As Document = Application.DocumentManager.MdiActiveDocument
            Dim db As Database = doc.Database

            Using tr As Transaction = db.TransactionManager.StartTransaction()
                Dim LayerTab = TryCast(tr.GetObject(db.LayerTableId, OpenMode.ForRead), LayerTable)

                If Not LayerTab.Has(LayerName) Then
                    Using NewLayer = New LayerTableRecord()
                        NewLayer.Name = LayerName

                        LayerTab.UpgradeOpen()
                        LayerTab.Add(NewLayer)
                        tr.AddNewlyCreatedDBObject(NewLayer, True)
                    End Using
                End If
                tr.Commit()
            End Using
        End Sub
    End Class
    Public NotInheritable Class ObjectIdCollectionExtensions
        Private Sub New()
        End Sub
        &amp;lt;System.Runtime.CompilerServices.Extension&amp;gt; _
        Public Shared Sub AddRange(a As ObjectIdCollection, Range As ObjectId())
            For Each n As var In Range
                a.Add(n)
            Next
        End Sub
    End Class
End Namespace

'=======================================================
'Service provided by Telerik (www.telerik.com)
'Conversion powered by NRefactory.
'Twitter: @telerik
'Facebook: facebook.com/telerik
'=======================================================&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jan 2017 18:12:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/required-codign-in-net/m-p/6833821#M33018</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-01-26T18:12:08Z</dc:date>
    </item>
    <item>
      <title>Re: Required codign in .net</title>
      <link>https://forums.autodesk.com/t5/net-forum/required-codign-in-net/m-p/6835213#M33019</link>
      <description>&lt;P&gt;Many Thanks,&lt;BR /&gt;&lt;BR /&gt;I am getting errors, attached image,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Could please tell me what to do?&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jan 2017 10:08:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/required-codign-in-net/m-p/6835213#M33019</guid>
      <dc:creator>waseefur.rahman</dc:creator>
      <dc:date>2017-01-27T10:08:09Z</dc:date>
    </item>
    <item>
      <title>Re: Required codign in .net</title>
      <link>https://forums.autodesk.com/t5/net-forum/required-codign-in-net/m-p/6835241#M33020</link>
      <description>&lt;P&gt;i have tried with this code,&lt;BR /&gt;&lt;BR /&gt;its copying the selected object in same layer with different color&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;could you tell me in this code&amp;nbsp;how paste the object in different layer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also attached a dwg file, shows the output required&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Consolas" size="2"&gt;&amp;lt;&lt;/FONT&gt;&lt;FONT color="#2b91af" face="Consolas" size="2"&gt;CommandMethod&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;(&lt;/FONT&gt;&lt;FONT color="#a31515" face="Consolas" size="2"&gt;"cp"&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;)&amp;gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Public&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Shared&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Sub&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; CopyMove()&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Dim&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; doc &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;As&lt;/FONT&gt; &lt;FONT color="#2b91af" face="Consolas" size="2"&gt;Document&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; = &lt;/FONT&gt;&lt;FONT color="#2b91af" face="Consolas" size="2"&gt;Application&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;.DocumentManager.MdiActiveDocument&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Dim&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; db &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;As&lt;/FONT&gt; &lt;FONT color="#2b91af" face="Consolas" size="2"&gt;Database&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; = doc.Database&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Dim&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; ed &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;As&lt;/FONT&gt; &lt;FONT color="#2b91af" face="Consolas" size="2"&gt;Editor&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; = doc.Editor&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Dim&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; peo &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;As&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Consolas" size="2"&gt;New&lt;/FONT&gt; &lt;FONT color="#2b91af" face="Consolas" size="2"&gt;PromptEntityOptions&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;(vbLf &amp;amp; &lt;/FONT&gt;&lt;FONT color="#a31515" face="Consolas" size="2"&gt;"Select object:"&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Dim&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; per &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;As&lt;/FONT&gt; &lt;FONT color="#2b91af" face="Consolas" size="2"&gt;PromptEntityResult&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; = ed.GetEntity(peo)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;If&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; per.Status &amp;lt;&amp;gt; &lt;/FONT&gt;&lt;FONT color="#2b91af" face="Consolas" size="2"&gt;PromptStatus&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;.OK &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Then&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Return&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;End&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Consolas" size="2"&gt;If&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Dim&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; startPT &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;As&lt;/FONT&gt; &lt;FONT color="#2b91af" face="Consolas" size="2"&gt;Point3d&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; = per.PickedPoint&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Dim&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; EndPT &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;As&lt;/FONT&gt; &lt;FONT color="#2b91af" face="Consolas" size="2"&gt;Point3d&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; = per.PickedPoint&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Using&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; tr &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;As&lt;/FONT&gt; &lt;FONT color="#2b91af" face="Consolas" size="2"&gt;Transaction&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; = db.TransactionManager.StartTransaction()&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Dim&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; btr &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;As&lt;/FONT&gt; &lt;FONT color="#2b91af" face="Consolas" size="2"&gt;BlockTableRecord&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; = &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;CType&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;(tr.GetObject(db.CurrentSpaceId, &lt;/FONT&gt;&lt;FONT color="#2b91af" face="Consolas" size="2"&gt;OpenMode&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;.ForWrite), &lt;/FONT&gt;&lt;FONT color="#2b91af" face="Consolas" size="2"&gt;BlockTableRecord&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Dim&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; sourceId &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;As&lt;/FONT&gt; &lt;FONT color="#2b91af" face="Consolas" size="2"&gt;ObjectId&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; = per.ObjectId&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Dim&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; EntitySource &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;As&lt;/FONT&gt; &lt;FONT color="#2b91af" face="Consolas" size="2"&gt;Entity&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; = &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;CType&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;(tr.GetObject(sourceId, &lt;/FONT&gt;&lt;FONT color="#2b91af" face="Consolas" size="2"&gt;OpenMode&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;.ForWrite), &lt;/FONT&gt;&lt;FONT color="#2b91af" face="Consolas" size="2"&gt;Entity&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Dim&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; ids &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;As&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Consolas" size="2"&gt;New&lt;/FONT&gt; &lt;FONT color="#2b91af" face="Consolas" size="2"&gt;ObjectIdCollection&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;()&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;ids.Add(sourceId)&lt;/P&gt;&lt;P&gt;&lt;FONT face="Consolas" size="2"&gt;db.DeepCloneObjects(ids, db.CurrentSpaceId, &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;New&lt;/FONT&gt; &lt;FONT color="#2b91af" face="Consolas" size="2"&gt;IdMapping&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;, &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;False&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Dim&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; EntityCopy &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;As&lt;/FONT&gt; &lt;FONT color="#2b91af" face="Consolas" size="2"&gt;Entity&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; = &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;CType&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;(tr.GetObject(ids(0), &lt;/FONT&gt;&lt;FONT color="#2b91af" face="Consolas" size="2"&gt;OpenMode&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;.ForRead), &lt;/FONT&gt;&lt;FONT color="#2b91af" face="Consolas" size="2"&gt;Entity&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;EntityCopy.UpgradeOpen()&lt;/P&gt;&lt;P&gt;&lt;FONT face="Consolas" size="2"&gt;EntityCopy.TransformBy(&lt;/FONT&gt;&lt;FONT color="#2b91af" face="Consolas" size="2"&gt;Matrix3d&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;.Displacement(startPT.GetVectorTo(EndPT)))&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;EntityCopy.ColorIndex = 2&lt;/P&gt;&lt;P&gt;tr.Commit()&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;End&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Using&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;End&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Sub&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jan 2017 10:27:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/required-codign-in-net/m-p/6835241#M33020</guid>
      <dc:creator>waseefur.rahman</dc:creator>
      <dc:date>2017-01-27T10:27:58Z</dc:date>
    </item>
    <item>
      <title>Re: Required codign in .net</title>
      <link>https://forums.autodesk.com/t5/net-forum/required-codign-in-net/m-p/6835501#M33021</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In order to make the method I've sent work you must add this Extensions Class to the same namespace:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;    Public NotInheritable Class ObjectIdCollectionExtensions
        Private Sub New()
        End Sub
        &amp;lt;System.Runtime.CompilerServices.Extension&amp;gt; _
        Public Shared Sub AddRange(a As ObjectIdCollection, Range As ObjectId())
            For Each n As var In Range
                a.Add(n)
            Next
        End Sub
    End Class&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you want to use the method you've sent you just need a few adjustments:&lt;/P&gt;&lt;PRE&gt;&amp;lt;CommandMethod("cp")&amp;gt;
Public Shared Sub CopyMove()
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
Dim peo As New PromptEntityOptions(vbLf &amp;amp; "Select object:")
Dim per As PromptEntityResult = ed.GetEntity(peo)
If per.Status &amp;lt;&amp;gt; PromptStatus.OK Then
Return
End If
Dim LayerName As String = ""
Dim LayerNamePrompt = ed.GetString(New PromptStringOptions(vbLf &amp;amp; "Enter Layer Name"))
If LayerNamePrompt.Status &amp;lt;&amp;gt; PromptStatus.OK Then
Return
End If
Dim startPT As Point3d = per.PickedPoint
Dim EndPT As Point3d = per.PickedPoint
Using tr As Transaction = db.TransactionManager.StartTransaction()
Dim btr As BlockTableRecord = CType(tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)
Dim sourceId As ObjectId = per.ObjectId
Dim EntitySource As Entity = CType(tr.GetObject(sourceId, OpenMode.ForWrite), Entity)
Dim ids As New ObjectIdCollection()
ids.Add(sourceId)
db.DeepCloneObjects(ids, db.CurrentSpaceId, New IdMapping, False)
Dim EntityCopy As Entity = CType(tr.GetObject(ids(0), OpenMode.ForRead), Entity)
EntityCopy.UpgradeOpen()
EntityCopy.TransformBy(Matrix3d.Displacement(startPT.GetVectorTo(EndPT)))
EntityCopy.ColorIndex = 2
EntityCopy.Layer = LayerName
tr.Commit()
End Using
End Sub
&lt;BR /&gt;Private Shared Sub MakeSureLayerExists(LayerName As String)
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Using tr As Transaction = db.TransactionManager.StartTransaction()
Dim LayerTab = TryCast(tr.GetObject(db.LayerTableId, OpenMode.ForRead), LayerTable)
If Not LayerTab.Has(LayerName) Then
Using NewLayer = New LayerTableRecord()
NewLayer.Name = LayerName
LayerTab.UpgradeOpen()
LayerTab.Add(NewLayer)
tr.AddNewlyCreatedDBObject(NewLayer, True)
End Using
End If
tr.Commit()
End Using
End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jan 2017 12:41:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/required-codign-in-net/m-p/6835501#M33021</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-01-27T12:41:34Z</dc:date>
    </item>
    <item>
      <title>COPY OBJECT TO NEW LAYER</title>
      <link>https://forums.autodesk.com/t5/net-forum/required-codign-in-net/m-p/6835557#M33022</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;i have also tried with this coding, but didn't getting solution&lt;/P&gt;&lt;P&gt;also attached a error snap.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Imports&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; Autodesk.AutoCAD.DatabaseServices&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Imports&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; Autodesk.AutoCAD.Runtime&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Imports&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; Autodesk.AutoCAD.Geometry&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Imports&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; Autodesk.AutoCAD.EditorInput&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Imports&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; Autodesk.AutoCAD.Interop&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Imports&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; Autodesk.AutoCAD.ApplicationServices&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Public&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Consolas" size="2"&gt;ReadOnly&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Property&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; ThisDrawing() &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;As&lt;/FONT&gt; &lt;FONT color="#2b91af" face="Consolas" size="2"&gt;AcadDocument&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Get&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Return&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; Autodesk.AutoCAD.ApplicationServices.&lt;/FONT&gt;&lt;FONT color="#2b91af" face="Consolas" size="2"&gt;DocumentExtension&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;.GetAcadDocument(Autodesk.AutoCAD.ApplicationServices.&lt;/FONT&gt;&lt;FONT color="#2b91af" face="Consolas" size="2"&gt;Application&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;.DocumentManager.MdiActiveDocument)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;End&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Get&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;End&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Property&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Private&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Sub&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; Button3_Click(sender &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;As&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Object&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;, e &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;As&lt;/FONT&gt; &lt;FONT color="#2b91af" face="Consolas" size="2"&gt;EventArgs&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Handles&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; Button3.Click&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#2b91af" face="Consolas" size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Dim&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; tu &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;As&lt;/FONT&gt; &lt;FONT color="#2b91af" face="Consolas" size="2"&gt;AcadUtility&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;tu = ThisDrawing.Utility&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Consolas" size="2"&gt;ThisDrawing.SendCommand(&lt;/FONT&gt;&lt;FONT color="#a31515" face="Consolas" size="2"&gt;"COPYTOLAYER"&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; &amp;amp; vbCr &amp;amp; tu.Get(, &lt;/FONT&gt;&lt;FONT color="#a31515" face="Consolas" size="2"&gt;"Select objects to copy"&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;) &amp;amp; vbCr &amp;amp; &lt;/FONT&gt;&lt;FONT color="#a31515" face="Consolas" size="2"&gt;"N"&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; &amp;amp; vbCr &amp;amp; &lt;/FONT&gt;&lt;FONT color="#a31515" face="Consolas" size="2"&gt;"Layer2"&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; &amp;amp; vbCr)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;End&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Sub&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jan 2017 13:04:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/required-codign-in-net/m-p/6835557#M33022</guid>
      <dc:creator>waseefur.rahman</dc:creator>
      <dc:date>2017-01-27T13:04:16Z</dc:date>
    </item>
    <item>
      <title>Re: Required codign in .net</title>
      <link>https://forums.autodesk.com/t5/net-forum/required-codign-in-net/m-p/6842366#M33023</link>
      <description>&lt;P&gt;Many Thanks,&lt;BR /&gt;it works...&lt;/P&gt;&lt;P&gt;Could you Please tell me how to do&amp;nbsp;it with "COPYTOLAYER" command in coding&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried with this code but it dosent work&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Imports&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; Autodesk.AutoCAD.ApplicationServices&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Imports&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; Autodesk.AutoCAD.Interop&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Imports&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; Autodesk.AutoCAD.Interop.Common&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Imports&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; Autodesk.AutoCAD.DatabaseServices&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Imports&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; Autodesk.AutoCAD.EditorInput&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Imports&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; Autodesk.AutoCAD.Geometry&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Public&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Consolas" size="2"&gt;ReadOnly&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Property&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; ThisDrawing() &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;As&lt;/FONT&gt; &lt;FONT color="#2b91af" face="Consolas" size="2"&gt;AcadDocument&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Get&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Return&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; Autodesk.AutoCAD.ApplicationServices.&lt;/FONT&gt;&lt;FONT color="#2b91af" face="Consolas" size="2"&gt;DocumentExtension&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;.GetAcadDocument(Autodesk.AutoCAD.ApplicationServices.&lt;/FONT&gt;&lt;FONT color="#2b91af" face="Consolas" size="2"&gt;Application&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;.DocumentManager.MdiActiveDocument)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;End&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Get&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;End&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Property&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Private&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Sub&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; Create_Copy_Click(sender &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;As&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Object&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;, e &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;As&lt;/FONT&gt; &lt;FONT color="#2b91af" face="Consolas" size="2"&gt;EventArgs&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Handles&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; Create_Copy.Click&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Dim&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; tu &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;As&lt;/FONT&gt; &lt;FONT color="#2b91af" face="Consolas" size="2"&gt;AcadUtility&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;tu = ThisDrawing.Utility&lt;/P&gt;&lt;P&gt;&lt;FONT face="Consolas" size="2"&gt;ThisDrawing.SendCommand(&lt;/FONT&gt;&lt;FONT color="#a31515" face="Consolas" size="2"&gt;"COPYTOLAYER"&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; &amp;amp; vbCr &amp;amp; tu.GetEntity &amp;amp; vbCr &amp;amp; &lt;/FONT&gt;&lt;FONT color="#a31515" face="Consolas" size="2"&gt;"N"&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; &amp;amp; vbCr &amp;amp; &lt;/FONT&gt;&lt;FONT color="#a31515" face="Consolas" size="2"&gt;"Cutback Extruction"&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; &amp;amp; vbCr)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;End&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Sub&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2017 04:58:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/required-codign-in-net/m-p/6842366#M33023</guid>
      <dc:creator>waseefur.rahman</dc:creator>
      <dc:date>2017-01-31T04:58:54Z</dc:date>
    </item>
    <item>
      <title>Re: Required codign in .net</title>
      <link>https://forums.autodesk.com/t5/net-forum/required-codign-in-net/m-p/6842606#M33024</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SendCommand expects a string as argument and there're none implicit cast from AcadUtils.GetEntity() returned value and the String type.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your're targetting AutoCAD 2015 or later, you can use the &lt;A href="http://through-the-interface.typepad.com/through_the_interface/2014/03/autocad-2015-calling-commands.html" target="_blank"&gt;Editor.Command() method&lt;/A&gt;, for prior versions, you can use &lt;A href="https://forums.autodesk.com/t5/net/problem-calling-acedcmd/m-p/4752787/highlight/true#M38687" target="_blank"&gt;the Tony Tanzillo's wrapper for the non public RunCommand() method&lt;/A&gt; which works the same way.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming the dialog is shown as modal dialog and the "Cutback Extruction" layer already exists in the document.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;C#&lt;/P&gt;
&lt;PRE&gt;        private void button1_Click(object sender, EventArgs e)
        {
            var doc = AcAp.DocumentManager.MdiActiveDocument;
            var ed = doc.Editor;
            var selection = ed.GetSelection();
            if (selection.Status == PromptStatus.OK)
                ed.Command("_COPYTOLAYER", selection.Value, "", "Cutback Extruction", "");
        }&lt;/PRE&gt;
&lt;P&gt;VB&lt;/P&gt;
&lt;PRE&gt;    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim doc As Document = AcApp.DocumentManager.MdiActiveDocument
        Dim ed As Editor = doc.Editor
        Dim selection As PromptSelectionResult = ed.GetSelection()
        If selection.Status = PromptStatus.OK Then
            ed.Command("_COPYTOLAYER", selection.Value, "", "Cutback Extruction", "")
        End If
    End Sub&lt;/PRE&gt;
&lt;P&gt;But, as shown by @Anonymous, it's not so difficult to mimic the "COPYTOLAYER" command.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;C#&lt;/P&gt;
&lt;PRE&gt;        private void button2_Click(object sender, EventArgs e)
        {
            var doc = AcAp.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;

            var selection = ed.GetSelection();
            if (selection.Status == PromptStatus.OK) return;
            try
            {
                var ids = new ObjectIdCollection(selection.Value.GetObjectIds());
                var mapping = new IdMapping();
                db.DeepCloneObjects(ids, SymbolUtilityServices.GetBlockModelSpaceId(db), mapping, false);
                using (var tr = db.TransactionManager.StartTransaction())
                {
                    foreach (IdPair item in mapping)
                    {
                        if (item.IsCloned &amp;amp;&amp;amp; item.IsPrimary)
                        {
                            var entity = (Entity)tr.GetObject(item.Value, OpenMode.ForWrite);
                            entity.Layer = "Cutback Extruction";
                        }
                    }
                    tr.Commit();
                }
            }
            catch (Autodesk.AutoCAD.Runtime.Exception ex)
            {
                ed.WriteMessage("\n" + ex.Message);
            }
        }&lt;/PRE&gt;
&lt;P&gt;VB&lt;/P&gt;
&lt;PRE&gt;    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim doc As Document = AcApp.DocumentManager.MdiActiveDocument
        Dim db As Database = doc.Database
        Dim ed As Editor = doc.Editor

        Dim selection As PromptSelectionResult = ed.GetSelection()
        If selection.Status &amp;lt;&amp;gt; PromptStatus.OK Then
            Return
        End If
        Try
            Dim ids As ObjectIdCollection = New ObjectIdCollection(selection.Value.GetObjectIds())
            Dim mapping As IdMapping = New IdMapping()
            db.DeepCloneObjects(ids, SymbolUtilityServices.GetBlockModelSpaceId(db), mapping, False)
            Using tr As Transaction = db.TransactionManager.StartTransaction()
                For Each item As IdPair In mapping
                    If item.IsCloned AndAlso item.IsPrimary Then
                        Dim entity As Entity = DirectCast(tr.GetObject(item.Value, OpenMode.ForWrite), Entity)
                        entity.Layer = "Cutback Extruction"
                    End If
                Next
                tr.Commit()
            End Using
        Catch ex As Autodesk.AutoCAD.Runtime.Exception
            ed.WriteMessage(vbLf + ex.Message)
        End Try
    End Sub&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2017 08:23:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/required-codign-in-net/m-p/6842606#M33024</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2017-01-31T08:23:06Z</dc:date>
    </item>
    <item>
      <title>Re: Required codign in .net</title>
      <link>https://forums.autodesk.com/t5/net-forum/required-codign-in-net/m-p/6843191#M33025</link>
      <description>&lt;P&gt;Hi gile,&lt;BR /&gt;&lt;BR /&gt;Many thanks for Your response,&lt;BR /&gt;&lt;BR /&gt;The code by &lt;U&gt;&lt;FONT color="#0066cc"&gt;chavesgalinari, &lt;FONT color="#000000"&gt;has been working Fine&lt;/FONT&gt;&lt;/FONT&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;FONT color="#0066cc"&gt;&lt;FONT color="#000000"&gt;But I have been trying the above through "COPYTOLAYER" command in coding.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;FONT color="#0066cc"&gt;&lt;FONT color="#000000"&gt;while running code I got this error attached (Capture 23)&lt;BR /&gt;could you please guide what to do to achive it&lt;/FONT&gt;&lt;/FONT&gt;&lt;/U&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2017 13:51:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/required-codign-in-net/m-p/6843191#M33025</guid>
      <dc:creator>waseefur.rahman</dc:creator>
      <dc:date>2017-01-31T13:51:23Z</dc:date>
    </item>
    <item>
      <title>Re: Required codign in .net</title>
      <link>https://forums.autodesk.com/t5/net-forum/required-codign-in-net/m-p/6843251#M33026</link>
      <description>&lt;P&gt;In which context do you run this code? Editor.Command() must be called in document context.&lt;/P&gt;
&lt;P&gt;In other words, how do you call this code? from a dialog? if so, the dialog have to be shown as Modal dialog.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2017 14:12:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/required-codign-in-net/m-p/6843251#M33026</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2017-01-31T14:12:09Z</dc:date>
    </item>
    <item>
      <title>Re: Required codign in .net</title>
      <link>https://forums.autodesk.com/t5/net-forum/required-codign-in-net/m-p/6843277#M33027</link>
      <description>&lt;P&gt;Sorry,&lt;BR /&gt;I didn't get you,&lt;BR /&gt;&lt;BR /&gt;Are you asking me how I am running this code?&lt;BR /&gt;&lt;BR /&gt;I have been running this code through from, where I am having a button to call this code.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2017 14:21:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/required-codign-in-net/m-p/6843277#M33027</guid>
      <dc:creator>waseefur.rahman</dc:creator>
      <dc:date>2017-01-31T14:21:45Z</dc:date>
    </item>
    <item>
      <title>Re: Required codign in .net</title>
      <link>https://forums.autodesk.com/t5/net-forum/required-codign-in-net/m-p/6843352#M33028</link>
      <description>&lt;P&gt;How do you display this form? as &lt;A href="https://msdn.microsoft.com/en-us/library/aa984358(v=vs.71).aspx" target="_blank"&gt;modal or modeless&lt;/A&gt;?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you're using:&lt;/P&gt;
&lt;PRE&gt;form.Show()&lt;/PRE&gt;
&lt;P&gt;or, better (see &lt;A href="http://adndevblog.typepad.com/autocad/2012/06/displaying-modal-and-modeless-forms-in-autocad-net.html" target="_blank"&gt;this thread&lt;/A&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;Autodesk.AutoCAD.ApplicationServices.Application.ShowModelessDialog(form)&lt;/PRE&gt;
&lt;P&gt;you use a modeless dialog which does not execute in document context, so you cannot directly use Editor.Command() from this kind of dialog.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;On the other hand if you use (not so good):&lt;/P&gt;
&lt;PRE&gt;form.showDialog()&lt;/PRE&gt;
&lt;P&gt;or (better): &lt;/P&gt;
&lt;PRE&gt;Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(form)&lt;/PRE&gt;
&lt;P&gt;you use a modal dialog which executes in document context and so can call Editor.Command() directly. &lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2017 14:47:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/required-codign-in-net/m-p/6843352#M33028</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2017-01-31T14:47:24Z</dc:date>
    </item>
  </channel>
</rss>

