<?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: How can I use .net api to  realize the  function as CAD ‘laytrans ’  command in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/how-can-i-use-net-api-to-realize-the-function-as-cad-laytrans/m-p/3749724#M51840</link>
    <description>&lt;P&gt;I used "WBlockCloneObjects“&amp;nbsp; ，however, it take&amp;nbsp;all&amp;nbsp; information of&amp;nbsp; layers&amp;nbsp;to the open dwg file.Then I want to use CAD ‘laytrans ’&amp;nbsp; command to delete these information of &amp;nbsp;layers before use "WBlockCloneObjects",but where is the function?&lt;/P&gt;&lt;P&gt;Can anyone help me ? Thanks very much!&lt;/P&gt;</description>
    <pubDate>Thu, 10 Jan 2013 03:02:00 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2013-01-10T03:02:00Z</dc:date>
    <item>
      <title>How can I use .net api to  realize the  function as CAD ‘laytrans ’  command</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-can-i-use-net-api-to-realize-the-function-as-cad-laytrans/m-p/3744412#M51834</link>
      <description>&lt;P&gt;How can I use .net api to&amp;nbsp; realize the&amp;nbsp; function as CAD ‘laytrans ’&amp;nbsp; command。I want to use it by code！&lt;/P&gt;</description>
      <pubDate>Tue, 01 Jan 2013 05:34:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-can-i-use-net-api-to-realize-the-function-as-cad-laytrans/m-p/3744412#M51834</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-01-01T05:34:53Z</dc:date>
    </item>
    <item>
      <title>Re : How can I use .net api to  realize the  function as CAD ‘laytrans ’  comman</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-can-i-use-net-api-to-realize-the-function-as-cad-laytrans/m-p/3744431#M51835</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It depends on how you get the new layers and if new layers have the same or different names from the old ones.&lt;/P&gt;&lt;P&gt;You can use WBlockCloneObjects() method to import layers from a file (dwg or dwt) or create them 'on the fly'.&lt;/P&gt;&lt;P&gt;If you import layers which have the same names as the old ones, using DuplicateRecordCloning.Replace with WBlockCloneObjects() should do the trick.&lt;/P&gt;&lt;P&gt;If you create layers 'on the fly', for layer names which already exist in the drawing, just change the layers properties.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In both cases, if layer names are different, you can iterate the whole database to change entities layer from old ones to new ones and then delete the old ones.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Jan 2013 12:20:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-can-i-use-net-api-to-realize-the-function-as-cad-laytrans/m-p/3744431#M51835</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2013-01-01T12:20:34Z</dc:date>
    </item>
    <item>
      <title>Re: How can I use .net api to  realize the  function as CAD ‘laytrans ’  command</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-can-i-use-net-api-to-realize-the-function-as-cad-laytrans/m-p/3744432#M51836</link>
      <description>&lt;P&gt;You mean that you want to add a new Command to Autocad but you want want that it functions like one of Autocad's Command and in addition you want to produce this code with .net ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Jan 2013 13:02:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-can-i-use-net-api-to-realize-the-function-as-cad-laytrans/m-p/3744432#M51836</guid>
      <dc:creator>autodeskprogrammer</dc:creator>
      <dc:date>2013-01-01T13:02:10Z</dc:date>
    </item>
    <item>
      <title>Re : How can I use .net api to  realize the  function as CAD ‘laytrans ’  comman</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-can-i-use-net-api-to-realize-the-function-as-cad-laytrans/m-p/3744466#M51837</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's a little snippet importing layers from a dwg or dwt file. The method arguments are: a dictionary containing pairs of type: old_layer_name, new_layer_name and the source file name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;        private void LayTrans(Dictionary&amp;lt;string, string&amp;gt; layerNames, string fileName)
        {
            Document doc = AcAp.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                LayerTable lt = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForRead);
                List&amp;lt;string&amp;gt; toRemove = new List&amp;lt;string&amp;gt;();
                foreach (KeyValuePair&amp;lt;string, string&amp;gt; pair in layerNames)
                {
                    if (!lt.Has(pair.Key))
                    {
                        ed.WriteMessage("\nTarget drawing does not contain '{0}'", pair.Key);
                        toRemove.Add(pair.Key);
                    }
                }
                foreach (string layer in toRemove)
                {
                    layerNames.Remove(layer);
                }
                List&amp;lt;LayerTableRecord&amp;gt; oldLayers = new List&amp;lt;LayerTableRecord&amp;gt;();
                using (Database sourceDb = new Database())
                {
                    sourceDb.ReadDwgFile(fileName, System.IO.FileShare.Read, false, "");
                    using (Transaction trx = sourceDb.TransactionManager.StartTransaction())
                    {
                        LayerTable sourceTable = (LayerTable)trx.GetObject(sourceDb.LayerTableId, OpenMode.ForRead);
                        ObjectIdCollection idCol = new ObjectIdCollection();
                        foreach (KeyValuePair&amp;lt;string, string&amp;gt; pair in layerNames)
                        {
                            if (sourceTable.Has(pair.Value))
                            {
                                idCol.Add(sourceTable[pair.Value]);
                                LayerTableRecord ltr = (LayerTableRecord)tr.GetObject(lt[pair.Key], OpenMode.ForWrite);
                                oldLayers.Add(ltr);
                            }
                            else
                            {
                                ed.WriteMessage("\nSource drawing does not contain '{0}'", pair.Value);
                            }
                        }
                        foreach (LayerTableRecord ltr in oldLayers)
                        {
                            ltr.Name = "Old_" + ltr.Name;
                        }
                        IdMapping idMap = new IdMapping();
                        sourceDb.WblockCloneObjects(
                            idCol, db.LayerTableId, idMap, DuplicateRecordCloning.Ignore, false);
                        trx.Commit();
                    }
                }
                BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
                foreach (ObjectId btrId in bt)
                {
                    BlockTableRecord btr = (BlockTableRecord)tr.GetObject(btrId, OpenMode.ForRead);
                    foreach (ObjectId id in btr)
                    {
                        Entity ent = (Entity)tr.GetObject(id, OpenMode.ForRead);
                        if (ent.Layer.StartsWith("Old_"))
                        {
                            string name = ent.Layer.Substring(4);
                            ent.UpgradeOpen();
                            ent.Layer = layerNames[name];
                        }
                    }
                }
                foreach (LayerTableRecord ltr in oldLayers)
                {
                    ltr.Erase();
                }
                tr.Commit();
            }
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Jan 2013 18:23:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-can-i-use-net-api-to-realize-the-function-as-cad-laytrans/m-p/3744466#M51837</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2013-01-01T18:23:21Z</dc:date>
    </item>
    <item>
      <title>Re: How can I use .net api to  realize the  function as CAD ‘laytrans ’  command</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-can-i-use-net-api-to-realize-the-function-as-cad-laytrans/m-p/3749698#M51838</link>
      <description>&lt;P&gt;Thanks for all！ I am sorry that CAD forum does not&amp;nbsp; send me any Email when you replied! I will try all you suggestion!&lt;/P&gt;</description>
      <pubDate>Thu, 10 Jan 2013 01:28:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-can-i-use-net-api-to-realize-the-function-as-cad-laytrans/m-p/3749698#M51838</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-01-10T01:28:56Z</dc:date>
    </item>
    <item>
      <title>Re: How can I use .net api to  realize the  function as CAD ‘laytrans ’  command</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-can-i-use-net-api-to-realize-the-function-as-cad-laytrans/m-p/3749709#M51839</link>
      <description>&lt;P&gt;I just want to&amp;nbsp;&amp;nbsp;do the&amp;nbsp; function follows&lt;/P&gt;&lt;P&gt;1、select one dwg file&lt;/P&gt;&lt;P&gt;2、import to the seleced&amp;nbsp;dwg file to the open dwg&amp;nbsp;&lt;/P&gt;&lt;P&gt;3、 create&amp;nbsp;one new layer on the open dwg&amp;nbsp;&lt;/P&gt;&lt;P&gt;4、&amp;nbsp;move all seleced dwg file entities&amp;nbsp;&amp;nbsp; to the new layer&lt;/P&gt;</description>
      <pubDate>Thu, 10 Jan 2013 02:10:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-can-i-use-net-api-to-realize-the-function-as-cad-laytrans/m-p/3749709#M51839</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-01-10T02:10:27Z</dc:date>
    </item>
    <item>
      <title>Re: How can I use .net api to  realize the  function as CAD ‘laytrans ’  command</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-can-i-use-net-api-to-realize-the-function-as-cad-laytrans/m-p/3749724#M51840</link>
      <description>&lt;P&gt;I used "WBlockCloneObjects“&amp;nbsp; ，however, it take&amp;nbsp;all&amp;nbsp; information of&amp;nbsp; layers&amp;nbsp;to the open dwg file.Then I want to use CAD ‘laytrans ’&amp;nbsp; command to delete these information of &amp;nbsp;layers before use "WBlockCloneObjects",but where is the function?&lt;/P&gt;&lt;P&gt;Can anyone help me ? Thanks very much!&lt;/P&gt;</description>
      <pubDate>Thu, 10 Jan 2013 03:02:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-can-i-use-net-api-to-realize-the-function-as-cad-laytrans/m-p/3749724#M51840</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-01-10T03:02:00Z</dc:date>
    </item>
  </channel>
</rss>

