<?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: Dynamic Block not placing at user selected point but offset from selected point in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/dynamic-block-not-placing-at-user-selected-point-but-offset-from/m-p/12008551#M8637</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;May be a User Cooordinate System issue.&lt;/P&gt;
&lt;P&gt;Try replacing:&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;Point3d insertionPoint = ppr.Value;&lt;/LI-CODE&gt;
&lt;P&gt;with:&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;Point3d insertionPoint = ppr.Value.TransformBy(ed.CurrentUserCoordinateSystem);&lt;/LI-CODE&gt;</description>
    <pubDate>Sat, 03 Jun 2023 05:18:08 GMT</pubDate>
    <dc:creator>_gile</dc:creator>
    <dc:date>2023-06-03T05:18:08Z</dc:date>
    <item>
      <title>Dynamic Block not placing at user selected point but offset from selected point</title>
      <link>https://forums.autodesk.com/t5/net-forum/dynamic-block-not-placing-at-user-selected-point-but-offset-from/m-p/12008508#M8636</link>
      <description>&lt;P&gt;I have below code which simply uses user selected point place the Dynamic Block. Now the issue I have is when I run this code it works fine on new drawing. but when I try this on one of my clients template drawing it is always offset from user selected point. Issue is only when I try to place the block using below code, but when I place Manually it works fine. Not sure it is template issue, Dynamic Block or code.&amp;nbsp;&lt;BR /&gt;Also Attached the Dynamic Block dwg file that I am using&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;[CommandMethod("MyDynamicBlock")]&lt;BR /&gt;public static void PlaceDynamicBlock()&lt;BR /&gt;{&lt;BR /&gt;// Get the current document and database&lt;BR /&gt;Document doc = Application.DocumentManager.MdiActiveDocument;&lt;BR /&gt;Database db = doc.Database;&lt;BR /&gt;Editor ed = doc.Editor;&lt;/P&gt;&lt;P&gt;// Prompt the user to select a point for insertion&lt;BR /&gt;PromptPointOptions ppo = new PromptPointOptions("\nSpecify insertion point for the dynamic block: ");&lt;BR /&gt;PromptPointResult ppr = ed.GetPoint(ppo);&lt;BR /&gt;ed.WriteMessage("Point selected is : " + ppr.ToString());&lt;BR /&gt;if (ppr.Status != PromptStatus.OK)&lt;BR /&gt;return;&lt;/P&gt;&lt;P&gt;Point3d insertionPoint = ppr.Value;&lt;/P&gt;&lt;P&gt;// Prompt the user to select a dynamic block reference&lt;BR /&gt;PromptEntityResult per = ed.GetEntity("\nSelect a dynamic block reference: ");&lt;BR /&gt;if (per.Status != PromptStatus.OK)&lt;BR /&gt;return;&lt;/P&gt;&lt;P&gt;// Get the selected entity (dynamic block reference)&lt;BR /&gt;using (Transaction trans = db.TransactionManager.StartTransaction())&lt;BR /&gt;{&lt;BR /&gt;BlockReference blockRef = trans.GetObject(per.ObjectId, OpenMode.ForWrite) as BlockReference;&lt;/P&gt;&lt;P&gt;// Clone the dynamic block reference at the specified insertion point&lt;BR /&gt;BlockReference newBlockRef = blockRef.Clone() as BlockReference;&lt;BR /&gt;newBlockRef.Position = insertionPoint;&lt;/P&gt;&lt;P&gt;// Add the new block reference to the current space&lt;BR /&gt;BlockTableRecord currentSpace = trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;&lt;BR /&gt;currentSpace.AppendEntity(newBlockRef);&lt;BR /&gt;trans.AddNewlyCreatedDBObject(newBlockRef, true);&lt;/P&gt;&lt;P&gt;// Update the attribute values of the new block reference&lt;BR /&gt;foreach (ObjectId attId in blockRef.AttributeCollection)&lt;BR /&gt;{&lt;BR /&gt;AttributeReference attRef = trans.GetObject(attId, OpenMode.ForRead) as AttributeReference;&lt;BR /&gt;AttributeReference newAttRef = attRef.Clone() as AttributeReference;&lt;/P&gt;&lt;P&gt;// Update the attribute reference's position based on the new block reference&lt;BR /&gt;Matrix3d transform = newBlockRef.BlockTransform.Inverse() * blockRef.BlockTransform;&lt;BR /&gt;Point3d transformedPosition = attRef.Position.TransformBy(transform);&lt;/P&gt;&lt;P&gt;newAttRef.Position = newBlockRef.Position + (transformedPosition - blockRef.Position);&lt;/P&gt;&lt;P&gt;// Add the new attribute reference to the new block reference&lt;BR /&gt;newBlockRef.AttributeCollection.AppendAttribute(newAttRef);&lt;BR /&gt;trans.AddNewlyCreatedDBObject(newAttRef, true);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Commit the transaction&lt;BR /&gt;trans.Commit();&lt;/P&gt;&lt;P&gt;// Display a message to the user&lt;BR /&gt;ed.WriteMessage("\nDynamic block placed with attributes.");&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Sat, 03 Jun 2023 04:28:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/dynamic-block-not-placing-at-user-selected-point-but-offset-from/m-p/12008508#M8636</guid>
      <dc:creator>kmkxperia</dc:creator>
      <dc:date>2023-06-03T04:28:54Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Block not placing at user selected point but offset from selected point</title>
      <link>https://forums.autodesk.com/t5/net-forum/dynamic-block-not-placing-at-user-selected-point-but-offset-from/m-p/12008551#M8637</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;May be a User Cooordinate System issue.&lt;/P&gt;
&lt;P&gt;Try replacing:&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;Point3d insertionPoint = ppr.Value;&lt;/LI-CODE&gt;
&lt;P&gt;with:&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;Point3d insertionPoint = ppr.Value.TransformBy(ed.CurrentUserCoordinateSystem);&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 03 Jun 2023 05:18:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/dynamic-block-not-placing-at-user-selected-point-but-offset-from/m-p/12008551#M8637</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2023-06-03T05:18:08Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Block not placing at user selected point but offset from selected point</title>
      <link>https://forums.autodesk.com/t5/net-forum/dynamic-block-not-placing-at-user-selected-point-but-offset-from/m-p/12008566#M8638</link>
      <description>&lt;P&gt;Thanks This worked for me.&lt;/P&gt;</description>
      <pubDate>Sat, 03 Jun 2023 05:33:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/dynamic-block-not-placing-at-user-selected-point-but-offset-from/m-p/12008566#M8638</guid>
      <dc:creator>kmkxperia</dc:creator>
      <dc:date>2023-06-03T05:33:33Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Block not placing at user selected point but offset from selected point</title>
      <link>https://forums.autodesk.com/t5/net-forum/dynamic-block-not-placing-at-user-selected-point-but-offset-from/m-p/12008576#M8639</link>
      <description>&lt;P&gt;You should use DeepCloneObjects instead so that also the attribute references are cloned.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;        [CommandMethod("COPYBLOCK")]
        public static void CopyBlockReference()
        {
            // Get the current document and database
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;

            // Prompt the user to select a block reference
            var peo = new PromptEntityOptions("\nSelect block reference: ");
            peo.SetRejectMessage("\nSelected object is no a block reference.");
            peo.AddAllowedClass(typeof(BlockReference), true);
            var per = ed.GetEntity(peo);
            if (per.Status != PromptStatus.OK) 
                return;
            var sourceId = per.ObjectId;

            // Prompt the user to select a point for insertion
            var ppr = ed.GetPoint("\nSpecify insertion point: ");
            if (ppr.Status != PromptStatus.OK)
                return;
            var insertionPoint = ppr.Value.TransformBy(ed.CurrentUserCoordinateSystem);

            // Deep clone the selected block reference
            var ids = new ObjectIdCollection { per.ObjectId };
            var mapping = new IdMapping();
            db.DeepCloneObjects(ids, db.CurrentSpaceId, mapping, false);

            // Move the copy to the specified insertion point
            using (var tr = db.TransactionManager.StartTransaction())
            {
                var br = (BlockReference)tr.GetObject(mapping[sourceId].Value, OpenMode.ForWrite);
                br.TransformBy(Matrix3d.Displacement(br.Position.GetVectorTo(insertionPoint)));
                tr.Commit();
            }
        }&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Jun 2023 05:51:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/dynamic-block-not-placing-at-user-selected-point-but-offset-from/m-p/12008576#M8639</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2023-06-03T05:51:41Z</dc:date>
    </item>
  </channel>
</rss>

