<?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: Change the size of blocks based on the Polyline in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/change-the-size-of-blocks-based-on-the-polyline/m-p/13174097#M1798</link>
    <description>&lt;P&gt;Yes, I already created the dynamic block and I am changing its value through code. The height is also changing. But the problem is how can I associate the height changes based on the curve polyline. So that I don't have to manually change each block's height, the height of all the blocks should change based on the curve height.&lt;/P&gt;&lt;P&gt;Here is the function in which I am changing the height of the block.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public void ModifyBlockLength()
{
    Document doc = Application.DocumentManager.MdiActiveDocument;
    Database db = doc.Database;
    Editor ed = doc.Editor;

    using (Transaction tr = db.TransactionManager.StartTransaction())
    {
        try
        {
            PromptEntityOptions peo = new PromptEntityOptions("\nSelect a dynamic block: ");
            peo.SetRejectMessage("\nSelected entity is not a block.");
            peo.AddAllowedClass(typeof(BlockReference), true);

            PromptEntityResult per = ed.GetEntity(peo);

            if (per.Status != PromptStatus.OK)
            {
                return;
            }

            BlockReference blkRef = tr.GetObject(per.ObjectId, OpenMode.ForRead) as BlockReference;
            if (!blkRef.IsDynamicBlock)
            {
                ed.WriteMessage("\nSelected block is not dynamic.");
                return;
            }
            DynamicBlockReferencePropertyCollection dynProps = blkRef.DynamicBlockReferencePropertyCollection;

            foreach (DynamicBlockReferenceProperty prop in dynProps)
            {
                if (prop.PropertyName == "Height")
                {
                    blkRef.UpgradeOpen();
                    double currentValue = Convert.ToDouble(prop.Value);
                    PromptDoubleOptions pdo = new PromptDoubleOptions($"\nCurrent Length: {currentValue}\nEnter new length: ")
                    {
                        AllowNegative = false,
                        AllowZero = false
                    };

                    PromptDoubleResult pdr = ed.GetDouble(pdo);

                    if (pdr.Status == PromptStatus.OK)
                    {
                        prop.Value = pdr.Value;
                        ed.WriteMessage($"\nUpdated length to {pdr.Value}");
                    }
                    else
                    {
                        ed.WriteMessage("\nNo changes made to the block length.");
                    }

                    blkRef.DowngradeOpen();
                }
            }
            tr.Commit();
            ed.Regen();
        }
        catch (System.Exception ex)
        {
            ed.WriteMessage($"\nError: {ex.Message}");
        }
    }
}&lt;/LI-CODE&gt;</description>
    <pubDate>Tue, 26 Nov 2024 07:39:13 GMT</pubDate>
    <dc:creator>prem_kumar8SXZJ</dc:creator>
    <dc:date>2024-11-26T07:39:13Z</dc:date>
    <item>
      <title>Change the size of blocks based on the Polyline</title>
      <link>https://forums.autodesk.com/t5/net-forum/change-the-size-of-blocks-based-on-the-polyline/m-p/13171508#M1791</link>
      <description>&lt;P&gt;Hi Everyone, I am working on a project with a polyline that is like a curve shape, and some blocks intersect that polyline. When I make changes in the curve polyline, like increasing or decreasing the curve's height, I want the blocks to also change their height based on the polyline. I have a working code that works perfectly on polylines, but I don't know how to do this for blocks. I have attached one image for the same. Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I appreciate any help you can provide.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Nov 2024 05:36:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/change-the-size-of-blocks-based-on-the-polyline/m-p/13171508#M1791</guid>
      <dc:creator>prem_kumar8SXZJ</dc:creator>
      <dc:date>2024-11-25T05:36:19Z</dc:date>
    </item>
    <item>
      <title>Re: Change the size of blocks based on the Polyline</title>
      <link>https://forums.autodesk.com/t5/net-forum/change-the-size-of-blocks-based-on-the-polyline/m-p/13172323#M1792</link>
      <description>&lt;P&gt;hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/14420845"&gt;@prem_kumar8SXZJ&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the problem isn't clear, have u tried obj.TransformBy() method&lt;/P&gt;</description>
      <pubDate>Mon, 25 Nov 2024 13:42:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/change-the-size-of-blocks-based-on-the-polyline/m-p/13172323#M1792</guid>
      <dc:creator>essam-salah</dc:creator>
      <dc:date>2024-11-25T13:42:30Z</dc:date>
    </item>
    <item>
      <title>Re: Change the size of blocks based on the Polyline</title>
      <link>https://forums.autodesk.com/t5/net-forum/change-the-size-of-blocks-based-on-the-polyline/m-p/13173288#M1793</link>
      <description>&lt;P&gt;Your problem statement is not entirely clear.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, when you say '&lt;EM&gt;I want the blocks to also change their height based on the polyline&lt;/EM&gt;', do you mean the Position of the blocks or do you mean that the block's contents change in some way? Your image suggests the former, but leaves some doubt.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If the blocks are static blocks and only their position changes according to the polyline location, constraints could be used to move them relative to the polyline's location. at a given point along it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, a picture is not enough to answer these questions. I would suggest posting a DWG file containing an example, showing 'before' and 'after' versions of the geometry showing how objects should react to changes to other, related objects.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2024 01:04:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/change-the-size-of-blocks-based-on-the-polyline/m-p/13173288#M1793</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2024-11-26T01:04:10Z</dc:date>
    </item>
    <item>
      <title>Re: Change the size of blocks based on the Polyline</title>
      <link>https://forums.autodesk.com/t5/net-forum/change-the-size-of-blocks-based-on-the-polyline/m-p/13173921#M1794</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/4476837"&gt;@ActivistInvestor&lt;/a&gt;,Thank you for responding to my problem. I have attached a dwg file showing the before and after geometry. Please have a look and suggest how I can achieve the desired output. Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2024 05:35:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/change-the-size-of-blocks-based-on-the-polyline/m-p/13173921#M1794</guid>
      <dc:creator>prem_kumar8SXZJ</dc:creator>
      <dc:date>2024-11-26T05:35:25Z</dc:date>
    </item>
    <item>
      <title>Re: Change the size of blocks based on the Polyline</title>
      <link>https://forums.autodesk.com/t5/net-forum/change-the-size-of-blocks-based-on-the-polyline/m-p/13173998#M1795</link>
      <description>&lt;P&gt;Simple question: How does the polyline change?&amp;nbsp; By direct user editing, by code, or both?&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2024 06:36:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/change-the-size-of-blocks-based-on-the-polyline/m-p/13173998#M1795</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2024-11-26T06:36:35Z</dc:date>
    </item>
    <item>
      <title>Re: Change the size of blocks based on the Polyline</title>
      <link>https://forums.autodesk.com/t5/net-forum/change-the-size-of-blocks-based-on-the-polyline/m-p/13174019#M1796</link>
      <description>&lt;P&gt;The polyline is changed by using code. Here it the function that changes the polyline based on the peakHeight variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;private Polyline CurveFromPoly(Polyline originalPolyline)
{
    if (originalPolyline == null)
    {
        throw new ArgumentNullException(nameof(originalPolyline), "Original polyline cannot be null.");
    }

    Document doc = Application.DocumentManager.MdiActiveDocument;
    Database db = doc.Database;
    Editor ed = doc.Editor;

    Polyline curvePolyline = null;

    using (Transaction tr = db.TransactionManager.StartTransaction())
    {
        BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
        BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

        curvePolyline = new Polyline();
        btr.AppendEntity(curvePolyline);
        tr.AddNewlyCreatedDBObject(curvePolyline, true);

        // Copy properties from original polyline
        curvePolyline.Linetype = originalPolyline.Linetype;
        curvePolyline.Color = originalPolyline.Color;
        curvePolyline.Layer = originalPolyline.Layer;
        curvePolyline.LinetypeScale = originalPolyline.LinetypeScale;

        double totalLength = originalPolyline.Length;
        double peakHeight = 25.0;

        // Define section lengths
        double startStraightLength = totalLength * 0.1;
        double startCurveLength = totalLength * 0.15;
        double middleStraightLength = totalLength * 0.5;
        double endCurveLength = startCurveLength;
        double endStraightLength = startStraightLength;

        // Step size for smooth curve
        int curvePoints = 20;

        // 1. Start straight section
        for (double i = 0; i &amp;lt;= startStraightLength; i += startStraightLength / 10)
        {
            Point3d pointAlongPolyline = originalPolyline.GetPointAtDist(i);
            Point2d newPoint = new Point2d(pointAlongPolyline.X, pointAlongPolyline.Y);
            curvePolyline.AddVertexAt(curvePolyline.NumberOfVertices, newPoint, 0, 0, 0);
        }

        // 2. Rising curved section with smooth transition
        for (int i = 0; i &amp;lt;= curvePoints; i++)
        {
            double t = i / (double)curvePoints;
            double distance = startStraightLength + t * startCurveLength;

            // Use sine function for smooth start of curve
            double heightOffset = peakHeight * Math.Sin(t * Math.PI / 2);

            Point3d pointAlongPolyline = originalPolyline.GetPointAtDist(distance);
            Point2d newPoint = new Point2d(pointAlongPolyline.X, pointAlongPolyline.Y + heightOffset);
            curvePolyline.AddVertexAt(curvePolyline.NumberOfVertices, newPoint, 0, 0, 0);
        }

        // 3. Middle straight section at peak height
        for (double i = startStraightLength + startCurveLength; i &amp;lt;= startStraightLength + startCurveLength + middleStraightLength; i += middleStraightLength / 10)
        {
            Point3d pointAlongPolyline = originalPolyline.GetPointAtDist(i);
            Point2d newPoint = new Point2d(pointAlongPolyline.X, pointAlongPolyline.Y + peakHeight);
            curvePolyline.AddVertexAt(curvePolyline.NumberOfVertices, newPoint, 0, 0, 0);
        }

        // 4. Declining curved section with smooth transition
        for (int i = 0; i &amp;lt;= curvePoints; i++)
        {
            double t = i / (double)curvePoints;
            double distance = startStraightLength + startCurveLength + middleStraightLength + t * endCurveLength;

            // Use cosine function for smooth end of curve
            double heightOffset = peakHeight * Math.Cos(t * Math.PI / 2);

            Point3d pointAlongPolyline = originalPolyline.GetPointAtDist(distance);
            Point2d newPoint = new Point2d(pointAlongPolyline.X, pointAlongPolyline.Y + heightOffset);
            curvePolyline.AddVertexAt(curvePolyline.NumberOfVertices, newPoint, 0, 0, 0);
        }

        // 5. End straight section
        for (double i = startStraightLength + startCurveLength + middleStraightLength + endCurveLength; i &amp;lt;= totalLength; i += endStraightLength / 10)
        {
            Point3d pointAlongPolyline = originalPolyline.GetPointAtDist(i);
            Point2d newPoint = new Point2d(pointAlongPolyline.X, pointAlongPolyline.Y);
            curvePolyline.AddVertexAt(curvePolyline.NumberOfVertices, newPoint, 0, 0, 0);
        }

        tr.Commit();
    }

    return curvePolyline;
}&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 26 Nov 2024 06:53:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/change-the-size-of-blocks-based-on-the-polyline/m-p/13174019#M1796</guid>
      <dc:creator>prem_kumar8SXZJ</dc:creator>
      <dc:date>2024-11-26T06:53:41Z</dc:date>
    </item>
    <item>
      <title>Re: Change the size of blocks based on the Polyline</title>
      <link>https://forums.autodesk.com/t5/net-forum/change-the-size-of-blocks-based-on-the-polyline/m-p/13174082#M1797</link>
      <description>&lt;P&gt;In that case, the solution is fairly trivial. Attached is your DWG with a modified copy of the Block, that has a "Height" dynamic property that you can set to the distance from the insertion point to the polyline measured along the y-axis.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2024 07:32:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/change-the-size-of-blocks-based-on-the-polyline/m-p/13174082#M1797</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2024-11-26T07:32:46Z</dc:date>
    </item>
    <item>
      <title>Re: Change the size of blocks based on the Polyline</title>
      <link>https://forums.autodesk.com/t5/net-forum/change-the-size-of-blocks-based-on-the-polyline/m-p/13174097#M1798</link>
      <description>&lt;P&gt;Yes, I already created the dynamic block and I am changing its value through code. The height is also changing. But the problem is how can I associate the height changes based on the curve polyline. So that I don't have to manually change each block's height, the height of all the blocks should change based on the curve height.&lt;/P&gt;&lt;P&gt;Here is the function in which I am changing the height of the block.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public void ModifyBlockLength()
{
    Document doc = Application.DocumentManager.MdiActiveDocument;
    Database db = doc.Database;
    Editor ed = doc.Editor;

    using (Transaction tr = db.TransactionManager.StartTransaction())
    {
        try
        {
            PromptEntityOptions peo = new PromptEntityOptions("\nSelect a dynamic block: ");
            peo.SetRejectMessage("\nSelected entity is not a block.");
            peo.AddAllowedClass(typeof(BlockReference), true);

            PromptEntityResult per = ed.GetEntity(peo);

            if (per.Status != PromptStatus.OK)
            {
                return;
            }

            BlockReference blkRef = tr.GetObject(per.ObjectId, OpenMode.ForRead) as BlockReference;
            if (!blkRef.IsDynamicBlock)
            {
                ed.WriteMessage("\nSelected block is not dynamic.");
                return;
            }
            DynamicBlockReferencePropertyCollection dynProps = blkRef.DynamicBlockReferencePropertyCollection;

            foreach (DynamicBlockReferenceProperty prop in dynProps)
            {
                if (prop.PropertyName == "Height")
                {
                    blkRef.UpgradeOpen();
                    double currentValue = Convert.ToDouble(prop.Value);
                    PromptDoubleOptions pdo = new PromptDoubleOptions($"\nCurrent Length: {currentValue}\nEnter new length: ")
                    {
                        AllowNegative = false,
                        AllowZero = false
                    };

                    PromptDoubleResult pdr = ed.GetDouble(pdo);

                    if (pdr.Status == PromptStatus.OK)
                    {
                        prop.Value = pdr.Value;
                        ed.WriteMessage($"\nUpdated length to {pdr.Value}");
                    }
                    else
                    {
                        ed.WriteMessage("\nNo changes made to the block length.");
                    }

                    blkRef.DowngradeOpen();
                }
            }
            tr.Commit();
            ed.Regen();
        }
        catch (System.Exception ex)
        {
            ed.WriteMessage($"\nError: {ex.Message}");
        }
    }
}&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 26 Nov 2024 07:39:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/change-the-size-of-blocks-based-on-the-polyline/m-p/13174097#M1798</guid>
      <dc:creator>prem_kumar8SXZJ</dc:creator>
      <dc:date>2024-11-26T07:39:13Z</dc:date>
    </item>
    <item>
      <title>Re: Change the size of blocks based on the Polyline</title>
      <link>https://forums.autodesk.com/t5/net-forum/change-the-size-of-blocks-based-on-the-polyline/m-p/13175727#M1799</link>
      <description>&lt;P&gt;You have to store references to the block insertions in the polyline, using an ExtensionDictionary/XRecord with its XlateReferences property set to true. You also have to contend with copying the polyline and/or the referenced blocks, and how you'll handle that, if copying those objects is a legitimate user operation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can have a look at &lt;A href="https://forums.autodesk.com/t5/net/store-list-of-handles-in-dictionary-xrecord/m-p/12738113" target="_blank" rel="noopener"&gt;this thread&lt;/A&gt; for some help with creating the XRecord, and you can search the discussion group using terms like&amp;nbsp;'SoftPointerId', etc. for more examples.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Storing the Ids of the block references on the polyline will allow you to open each block reference and update its dynamic property from within the code that changes the polyline. If you're not sure how to calculate the value that you have to assign to each block, it should be the distance from the block's insertion point to the point where the polyline intersects a line passing through the insertion point along the Y-axis.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Nov 2024 03:00:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/change-the-size-of-blocks-based-on-the-polyline/m-p/13175727#M1799</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2024-11-27T03:00:11Z</dc:date>
    </item>
    <item>
      <title>Re: Change the size of blocks based on the Polyline</title>
      <link>https://forums.autodesk.com/t5/net-forum/change-the-size-of-blocks-based-on-the-polyline/m-p/13179239#M1800</link>
      <description>&lt;P&gt;Okay Thank you! I will try and let you know if this works.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Nov 2024 05:09:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/change-the-size-of-blocks-based-on-the-polyline/m-p/13179239#M1800</guid>
      <dc:creator>prem_kumar8SXZJ</dc:creator>
      <dc:date>2024-11-28T05:09:53Z</dc:date>
    </item>
    <item>
      <title>Re: Change the size of blocks based on the Polyline</title>
      <link>https://forums.autodesk.com/t5/net-forum/change-the-size-of-blocks-based-on-the-polyline/m-p/13186136#M1801</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/4476837"&gt;@ActivistInvestor&lt;/a&gt;, Thanks a lot for your guidance. I have written the code based on what you have suggested and it works like magic. Thanks again. Happy Coding &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2024 06:38:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/change-the-size-of-blocks-based-on-the-polyline/m-p/13186136#M1801</guid>
      <dc:creator>prem_kumar8SXZJ</dc:creator>
      <dc:date>2024-12-02T06:38:46Z</dc:date>
    </item>
  </channel>
</rss>

