<?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: Insert block with attributes, c sharp. in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/insert-block-with-attributes-c-sharp/m-p/5428485#M42643</link>
    <description />
    <pubDate>Mon, 01 Dec 2014 06:08:28 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2014-12-01T06:08:28Z</dc:date>
    <item>
      <title>Insert block with attributes, c sharp.</title>
      <link>https://forums.autodesk.com/t5/net-forum/insert-block-with-attributes-c-sharp/m-p/5294619#M42640</link>
      <description>&lt;P&gt;Good Day,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm crafting a csharp programme through visual studio to calculate invert levels in autocad and insert a block with that level automatically added. Then repeat the calcs and insertion at any point the user clicks on until the programme is cancelled.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The calculations are complete but I'm having problems inserting the block. I'm trying to pull the block (Level_Arrow) from another drawing (C:\Test.dwg) to be placed at the target point (ptInsert) with block scale (drgScale), rotation 0 and (ptDisp) as first attribute, " " as second attribute (or nothing).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a simple and easy way of doing this?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please note, I have experience with Lisp but little experience with Csharp. If your answer could be simple and well explained I would be grateful.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;</description>
      <pubDate>Wed, 24 Sep 2014 08:58:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/insert-block-with-attributes-c-sharp/m-p/5294619#M42640</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-09-24T08:58:26Z</dc:date>
    </item>
    <item>
      <title>Re: Insert block with attributes, c sharp.</title>
      <link>https://forums.autodesk.com/t5/net-forum/insert-block-with-attributes-c-sharp/m-p/5296001#M42641</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@Anonymous wrote:&lt;BR /&gt;&lt;P&gt;Good Day,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm crafting a csharp programme through visual studio to calculate invert levels in autocad and insert a block with that level automatically added. Then repeat the calcs and insertion at any point the user clicks on until the programme is cancelled.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The calculations are complete but I'm having problems inserting the block. I'm trying to pull the block (Level_Arrow) from another drawing (C:\Test.dwg) to be placed at the target point (ptInsert) with block scale (drgScale), rotation 0 and (ptDisp) as first attribute, " " as second attribute (or nothing).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a simple and easy way of doing this?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please note, I have experience with Lisp but little experience with Csharp. If your answer could be simple and well explained I would be grateful.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Here's a snippet from a project that is copying attribute values from one block to another; complete Transaction not shown here:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;				// ...

				    Dictionary&amp;lt;string, string&amp;gt; d = new Dictionary&amp;lt;string, string&amp;gt;();
                                    AttributeCollection ac = block.AttributeCollection;

                                    foreach (ObjectId attId in ac)
                                    {
                                        AttributeReference attRef =
                                            (AttributeReference)tr.GetObject(attId, OpenMode.ForRead);

                                        if (!d.ContainsKey(attRef.Tag))
                                        {
                                            d.Add(attRef.Tag, attRef.TextString);
                                        }
                                    }
									
                                    // &amp;lt;-- add your new BlockReference() here

                                    foreach (ObjectId x in &amp;lt;YourNewBlockHere&amp;gt;)
                                    {
                                        AttributeDefinition ad = 
                                            tr.GetObject(x, OpenMode.ForRead) as AttributeDefinition;

                                        if (ad != null)
                                        {
                                            AttributeReference ar = new AttributeReference();
                                            ar.SetAttributeFromBlock(ad, t);
                                            ar.Position = ad.Position.TransformBy(t);
                                            ar.TextString = d[ar.Tag];
                                        }
                                    }
									
				// ...&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;</description>
      <pubDate>Wed, 24 Sep 2014 17:41:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/insert-block-with-attributes-c-sharp/m-p/5296001#M42641</guid>
      <dc:creator>BlackBox_</dc:creator>
      <dc:date>2014-09-24T17:41:21Z</dc:date>
    </item>
    <item>
      <title>Re: Insert block with attributes, c sharp.</title>
      <link>https://forums.autodesk.com/t5/net-forum/insert-block-with-attributes-c-sharp/m-p/5427398#M42642</link>
      <description>&lt;P&gt;i would also love a clean example,&amp;nbsp; been working\failing on trying to get the attributes to show up.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Nov 2014 15:31:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/insert-block-with-attributes-c-sharp/m-p/5427398#M42642</guid>
      <dc:creator>bherber</dc:creator>
      <dc:date>2014-11-28T15:31:32Z</dc:date>
    </item>
    <item>
      <title>Re: Insert block with attributes, c sharp.</title>
      <link>https://forums.autodesk.com/t5/net-forum/insert-block-with-attributes-c-sharp/m-p/5428485#M42643</link>
      <description />
      <pubDate>Mon, 01 Dec 2014 06:08:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/insert-block-with-attributes-c-sharp/m-p/5428485#M42643</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-12-01T06:08:28Z</dc:date>
    </item>
    <item>
      <title>Re: Insert block with attributes, c sharp.</title>
      <link>https://forums.autodesk.com/t5/net-forum/insert-block-with-attributes-c-sharp/m-p/5428487#M42644</link>
      <description>It took me days to figure out but I managed to extract the attributes. See extract: if (OrgBtr.HasAttributeDefinitions) { foreach (ObjectId id in OrgBtr) { DBObject obj = tr.GetObject(id, OpenMode.ForRead); AttributeDefinition ad = obj as AttributeDefinition; if (ad != null &amp;amp;&amp;amp; !ad.Constant) { ar = new AttributeReference(); ar.SetAttributeFromBlock(ad, insblkref.BlockTransform); ar.Position = ad.Position.TransformBy(insblkref.BlockTransform); if (ad.Justify != AttachmentPoint.BaseLeft) { ar.AlignmentPoint.TransformBy(insblkref.BlockTransform); } if (ar.IsMTextAttribute) { ar.UpdateMTextAttribute(); } ar.TextString = ptDisp.ToString(("N3")); ObjectId arId = insblkref.AttributeCollection.AppendAttribute(ar); tr.AddNewlyCreatedDBObject(ar, true); break; } } } My work computer appears to have issue with forum posting setting I do hope this comes out legible.</description>
      <pubDate>Mon, 01 Dec 2014 06:10:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/insert-block-with-attributes-c-sharp/m-p/5428487#M42644</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-12-01T06:10:37Z</dc:date>
    </item>
  </channel>
</rss>

