<?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 to set location for AttributeReference in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/how-to-set-location-for-attributereference/m-p/11884262#M9270</link>
    <description>&lt;P&gt;omg.&amp;nbsp;great, excellent, wonderfull.&amp;nbsp;I did it.&amp;nbsp;Thank you very much&lt;/P&gt;</description>
    <pubDate>Mon, 10 Apr 2023 01:57:55 GMT</pubDate>
    <dc:creator>nguyenthanguth</dc:creator>
    <dc:date>2023-04-10T01:57:55Z</dc:date>
    <item>
      <title>How to set location for AttributeReference</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-set-location-for-attributereference/m-p/11881938#M9268</link>
      <description>&lt;P&gt;Hi, I'm here to answer my questions. Hope everybody help please&lt;BR /&gt;when i insert a block into autocad drawing. I have a custom edit, it changes the position of position. I have repositioned the block but an error has appeared. attributes do not automatically move by block&lt;BR /&gt;below is my image and code&lt;BR /&gt;this is when i insert&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="1.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1199996iA5A0AB157D0ADA74/image-size/medium?v=v2&amp;amp;px=400" role="button" title="1.png" alt="1.png" /&gt;&lt;/span&gt;&lt;BR /&gt;this is the result i want.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="2.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1199995iA94EED59E08BD4AA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="2.png" alt="2.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;sample my code:&amp;nbsp;I was able to handle it with ed.Command("ATTSYNC", "Name", blockNameInsert); this is probably a bad idea.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;#region Insert block WallVertDowelType3
// Create a new block reference and add it to the current space
using (BlockReference br_Insert = new BlockReference(geoPosition, blockTable[blockNameInsert]))
{
    br_Insert.Layer = genLayer;
    br_Insert.ScaleFactors = getScale;
    br_Insert.Rotation = misRotation;

    // insert block WallVertDowelType3 vào CurrentSpaceId
    BlockTableRecord btrCurrentSpace = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
    btrCurrentSpace.AppendEntity(br_Insert);
    tr.AddNewlyCreatedDBObject(br_Insert, true);

    #region Set Attribute[] of Block Reference | if (btr.HasAttributeDefinitions)
    BlockTableRecord blockInsert = tr.GetObject(blockTable[blockNameInsert], OpenMode.ForRead) as BlockTableRecord;
    foreach (ObjectId oid_ATB in blockInsert)
    {
        DBObject dBObject = tr.GetObject(oid_ATB, OpenMode.ForRead);
        if (dBObject is AttributeDefinition)
        {
            AttributeReference attRef = new AttributeReference();

            // Add the attribute to the block reference
            AttributeDefinition attDef = dBObject as AttributeDefinition;
            attRef.SetAttributeFromBlock(attDef, br_Insert.BlockTransform);
            //attRef.Position = attDef.Position.TransformBy(br_Insert.BlockTransform);

            double temp_DIA = DIA.Contains("D") ? Convert.ToDouble(DIA.Split('D')[1]) : Convert.ToDouble(DIA);
            switch (attRef.Tag)
            {
                case "xxx": attRef.TextString = "xxx"; break;
            }
            // Add attribute to block reference
            br_Insert.AttributeCollection.AppendAttribute(attRef);
            tr.AddNewlyCreatedDBObject(attRef, true);
        }
    }
    #endregion

    #region Set Custom[] of Block Reference Dynamic | if (bref.IsDynamicBlock)
    DynamicBlockReferencePropertyCollection DBRPCollection = br_Insert.DynamicBlockReferencePropertyCollection;
    foreach (DynamicBlockReferenceProperty DBRProperty in DBRPCollection)
    {
        switch (DBRProperty.PropertyName)
        {
            case "xxx": DBRProperty.Value = canhB; break;
        }
    }
    br_Insert.Position = geoPosition; // error generated attribute is not in the correct position. Temporarily fixed with `ATTSYNC`
    #endregion
}
#endregion
ed.Command("ATTSYNC", "Name", blockNameInsert); //still usable but not optimal in terms of performance. i need another way&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 08 Apr 2023 09:58:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-set-location-for-attributereference/m-p/11881938#M9268</guid>
      <dc:creator>nguyenthanguth</dc:creator>
      <dc:date>2023-04-08T09:58:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to set location for AttributeReference</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-set-location-for-attributereference/m-p/11882102#M9269</link>
      <description>&lt;P&gt;Instead of changing Position property of a BlockReference, you use Matrix3d.Displacement() to transform a block for moving it, if the block reference owns attributes:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;var mt=Matrix3d.Displacement(blk.Position.GetVectorTo([newLocation]);&lt;/P&gt;
&lt;P&gt;blk.TransformBy(mt);&lt;/P&gt;</description>
      <pubDate>Sat, 08 Apr 2023 12:41:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-set-location-for-attributereference/m-p/11882102#M9269</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2023-04-08T12:41:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to set location for AttributeReference</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-set-location-for-attributereference/m-p/11884262#M9270</link>
      <description>&lt;P&gt;omg.&amp;nbsp;great, excellent, wonderfull.&amp;nbsp;I did it.&amp;nbsp;Thank you very much&lt;/P&gt;</description>
      <pubDate>Mon, 10 Apr 2023 01:57:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-set-location-for-attributereference/m-p/11884262#M9270</guid>
      <dc:creator>nguyenthanguth</dc:creator>
      <dc:date>2023-04-10T01:57:55Z</dc:date>
    </item>
  </channel>
</rss>

