<?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: Swap titleblock between 2 drawings in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/swap-titleblock-between-2-drawings/m-p/3771096#M51271</link>
    <description>&lt;P&gt;I suppose in my attempt to make a brief question, some might have assumed I wanted someone to write an entire program for me. &amp;nbsp;I don't. &amp;nbsp;I'll attempt to clarify which parts I need assistance with.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Right now I'm using this code to copy a titleblock from another drawing. &amp;nbsp;Is there a way to get the new objectIds of the objects that I just inserted? &amp;nbsp;Currently they are on a layer that doesn't exist. &amp;nbsp;My goal is to get the new objectID of the item(s) I just copied, then use the setLayer property.&lt;/P&gt;&lt;PRE&gt;acCurDb.WblockCloneObjects(objColl, btr.ObjectId, iMap, DuplicateRecordCloning.Ignore, false);&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I noticed that attributes doesn't have a set command. &amp;nbsp;Is there a specific way I should copy items from an attributeCollection to a new attributeCollection?&lt;/P&gt;</description>
    <pubDate>Wed, 06 Feb 2013 15:59:47 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2013-02-06T15:59:47Z</dc:date>
    <item>
      <title>Swap titleblock between 2 drawings</title>
      <link>https://forums.autodesk.com/t5/net-forum/swap-titleblock-between-2-drawings/m-p/3769243#M51270</link>
      <description>&lt;P&gt;I have 2 files and I'd like to copy a titleblock from a template drawing and use it to replace an existing titleblock on an in progress drawing. &amp;nbsp;The titleblock on the in progress drawing has attributes, and I'd like to keep them when I put in the new titleblock. &amp;nbsp;The attribute tag names between the 2 titleblocks are the same.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I do not know the exact names of the titleblocks, only that they contain the words "title block" somewhere in their name.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've developed for Inventor for a while now, but I'm completely new to AutoCAD. &amp;nbsp;How might I go about this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I believe the basic steps would be something like this:&lt;/P&gt;&lt;P&gt;1. &amp;nbsp;Identify which object to copy from template sheet.&lt;/P&gt;&lt;P&gt;2. &amp;nbsp;Save that object to memory&lt;/P&gt;&lt;P&gt;3. &amp;nbsp;Identify object to replace in existing drawing&lt;/P&gt;&lt;P&gt;4. &amp;nbsp;Copy attributes and get position of existing titleblock&lt;/P&gt;&lt;P&gt;5. &amp;nbsp;Delete existing titleblock&lt;/P&gt;&lt;P&gt;6. Insert new titleblock and copy in attributes&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've taken the Autocad tutorials, and I've searched for relevant posts on ThroughTheInterface. &amp;nbsp;Is there someplace else to look which might give a more in-depth example of what I'm trying to accomplish?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2013 19:38:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/swap-titleblock-between-2-drawings/m-p/3769243#M51270</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-02-04T19:38:17Z</dc:date>
    </item>
    <item>
      <title>Re: Swap titleblock between 2 drawings</title>
      <link>https://forums.autodesk.com/t5/net-forum/swap-titleblock-between-2-drawings/m-p/3771096#M51271</link>
      <description>&lt;P&gt;I suppose in my attempt to make a brief question, some might have assumed I wanted someone to write an entire program for me. &amp;nbsp;I don't. &amp;nbsp;I'll attempt to clarify which parts I need assistance with.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Right now I'm using this code to copy a titleblock from another drawing. &amp;nbsp;Is there a way to get the new objectIds of the objects that I just inserted? &amp;nbsp;Currently they are on a layer that doesn't exist. &amp;nbsp;My goal is to get the new objectID of the item(s) I just copied, then use the setLayer property.&lt;/P&gt;&lt;PRE&gt;acCurDb.WblockCloneObjects(objColl, btr.ObjectId, iMap, DuplicateRecordCloning.Ignore, false);&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I noticed that attributes doesn't have a set command. &amp;nbsp;Is there a specific way I should copy items from an attributeCollection to a new attributeCollection?&lt;/P&gt;</description>
      <pubDate>Wed, 06 Feb 2013 15:59:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/swap-titleblock-between-2-drawings/m-p/3771096#M51271</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-02-06T15:59:47Z</dc:date>
    </item>
    <item>
      <title>Re: Swap titleblock between 2 drawings</title>
      <link>https://forums.autodesk.com/t5/net-forum/swap-titleblock-between-2-drawings/m-p/3772477#M51272</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've never tried it but I assume the IdMap gives you the facility to look up the new id from the original one..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;IdMapping&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;IdMapping acIdMap = new IdMapping();
acCurDb.WblockCloneObjects(interferenceIdCol, acBlkTblRecNewDoc.ObjectId, acIdMap,
                           DuplicateRecordCloning.Ignore, false);

newId = acIdMap.Lookup(oldId);&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Setting attributes you just loop through them and&amp;nbsp;set the text string (maybe there is away to do the whole collection at once&amp;nbsp;but I haven't managed it - hopefully someone with more time/experience than me&amp;nbsp;can confirm if it can be done)...&lt;/P&gt;&lt;PRE&gt;foreach (ObjectId attId in attcol)
{
    AttributeReference attRef = (AttributeReference)trans.GetObject(attId, OpenMode.ForWrite);
    if (attRef.Tag.ToLower() == attName.ToLower())
    {
        if (attRef.TextString.ToLower() != attValue.ToLower())
        {
            attRef.TextString = attValue;
            attUpdated += 1;
        }
    }
}&lt;/PRE&gt;&lt;P&gt;I think I would be tempted to make a list of key value pairs containing the attribute tag and the text string from the&amp;nbsp;old block, then&amp;nbsp;loop through the new block setting&amp;nbsp;the appropriate value.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Graham&lt;/P&gt;&lt;P&gt;Mitek Industries&lt;/P&gt;</description>
      <pubDate>Thu, 07 Feb 2013 16:48:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/swap-titleblock-between-2-drawings/m-p/3772477#M51272</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-02-07T16:48:42Z</dc:date>
    </item>
    <item>
      <title>Re: Swap titleblock between 2 drawings</title>
      <link>https://forums.autodesk.com/t5/net-forum/swap-titleblock-between-2-drawings/m-p/3772513#M51273</link>
      <description>&lt;P&gt;Actually, my code doesn't do what i thought it did...which means my last question was no longer relevant. &amp;nbsp;First, the code from adndevblog that I was using is wrong. &amp;nbsp;It had me copying from and to the wrong databases. &amp;nbsp;ThroughTheInterface has similar code from 2006 that is correct, so I'm using that now.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Apparently, this only copies the drawing definition:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;var iMap = new IdMapping();
sourceDatabase.WblockCloneObjects(objColl, bt.ObjectId, iMap, DuplicateRecordCloning.Ignore, false);&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Now that I have the definition, what do I need to do to actually insert this as a block in the drawing? (so i can see it)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what I have so far to insert a new block, but it obviously isn't complete. &amp;nbsp;If I understand correctly, the above code creates a BlockTableRecord. &amp;nbsp;For the code below, I don't know how to specify which BlockTableRecord(definition) I just inserted.&lt;/P&gt;&lt;PRE&gt;//Add a blockReference to the newly inserted blockTableRecord
BlockTableRecord newbtr = ???????
newbtr.Name = blockToReplace.Name + "1";
ObjectId newbtrId = bt.Add(newbtr);
tr.AddNewlyCreatedDBObject(newbtr, true);&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Feb 2013 17:01:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/swap-titleblock-between-2-drawings/m-p/3772513#M51273</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-02-07T17:01:52Z</dc:date>
    </item>
    <item>
      <title>Re: Swap titleblock between 2 drawings</title>
      <link>https://forums.autodesk.com/t5/net-forum/swap-titleblock-between-2-drawings/m-p/3772610#M51274</link>
      <description>&lt;P&gt;Inserting a block is something like this (where [cassName] is the name of your block...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;            BlockTable bt = (BlockTable)trans.GetObject(HostApplicationServices.WorkingDatabase.BlockTableId, OpenMode.ForWrite);
            BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
            try
            {
                BlockTableRecord blk = (BlockTableRecord)trans.GetObject(bt[cassName], OpenMode.ForWrite);
                if (blk != null)
                {
                    Autodesk.AutoCAD.DatabaseServices.BlockReference blkRec = new Autodesk.AutoCAD.DatabaseServices.BlockReference(ip, blk.ObjectId);
                    blkRec.SetDatabaseDefaults();
                    blkRec.LayerId = layId;
                    btr.AppendEntity(blkRec);
                    trans.AddNewlyCreatedDBObject(blkRec, true);
                    Extents3d ext3d = (Extents3d)blkRec.Bounds;
                    ip = new Point3d(ext3d.MaxPoint.X + 300, ext3d.MaxPoint.Y, 0);
                }
            }
            catch
            {
            }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Ignore the last couple of lines relating the Extents3D.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You will then need to get the attributes collection and fill out the values&amp;nbsp;similar to the previous code (i think you do this even if you want the default values).&lt;/P&gt;</description>
      <pubDate>Thu, 07 Feb 2013 18:39:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/swap-titleblock-between-2-drawings/m-p/3772610#M51274</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-02-07T18:39:13Z</dc:date>
    </item>
  </channel>
</rss>

