<?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: problems with creating a helix using c#.net in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/problems-with-creating-a-helix-using-c-net/m-p/5677790#M39594</link>
    <description>&lt;P&gt;This will create a Helix, Polyline and then sweep the Polyline with the Helix&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the Polylines is converted to an Entity and the helix to a Curve.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I didn't change the AxisVector, it seems to work fine without it being changed.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Geometry;

namespace CreateHelix
{
    public class clsCreateHelix
    {
        [CommandMethod("MHelix", CommandFlags.Session)]
        public void CreateHelix()
        {
            Database acCurDb = Application.DocumentManager.MdiActiveDocument.Database;
            Document doc = Application.DocumentManager.MdiActiveDocument;

            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                using (DocumentLock DocLock = doc.LockDocument())
                {
                    using (BlockTable acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable)
                    {
                        using (BlockTableRecord acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord)
                        {
                            // Create Helix
                            Helix acHelix = getHelix(270, true, 100, new Point3d(0, 0, 0), 10);
                            acBlkTblRec.AppendEntity((Entity)acHelix);
                            acTrans.AddNewlyCreatedDBObject(acHelix, true);

                            // Create Polyline for Sweep
                            Polyline acPolyline = getPolylineForSweep();
                            acBlkTblRec.AppendEntity((Entity)acPolyline);
                            acTrans.AddNewlyCreatedDBObject(acPolyline, true);
                        
                            // Sweep Polyline along helix. 
                            Solid3d acSolid = SweepAlongPath(acPolyline, acHelix);

                            if (acSolid != null)
                            {
                                acBlkTblRec.AppendEntity((Entity)acSolid);
                                acTrans.AddNewlyCreatedDBObject(acSolid, true);
                            }
                        }
                    }
                }
                acTrans.Commit();
            }
        }

        private double getTurnAngle(double dblDegrees)
        {
            return (((dblDegrees * 100) / 360) * .01);
        }

        internal Helix getHelix(double dblTurnAngle, bool CW, double dblRadius, Point3d pt3Origin, double dblHeight)
        {
            double dblDegree = getTurnAngle(dblTurnAngle);
            Helix acHelix = new Helix();
            acHelix.SetDatabaseDefaults();
            acHelix.Constrain = ConstrainType.Height;
            acHelix.StartPoint = pt3Origin;
            acHelix.BaseRadius = dblRadius;
            acHelix.TopRadius = dblRadius;
            acHelix.Height = dblHeight;
            acHelix.TurnHeight = (1 / dblDegree);
            acHelix.Turns = dblDegree;
            acHelix.Twist = !CW;
            acHelix.CreateHelix();
            return acHelix;
        }

        internal Polyline getPolylineForSweep()
        {
            Polyline pline = new Polyline();
            pline.SetDatabaseDefaults();
            // Polyline must not intersect itself
            pline.AddVertexAt(0, new Point2d(-10, 0.0), 0.0, 0.0, 0.0);
            pline.AddVertexAt(1, new Point2d(10, 0.0), 0.0, 0.0, 0.0);
            pline.AddVertexAt(2, new Point2d(10, 10), 0.0, 0.0, 0.0);
            pline.AddVertexAt(3, new Point2d(-10, 10), 0.0, 0.0, 0.0);
            pline.Closed = true;

            return pline;
        }


        internal Solid3d SweepAlongPath(Polyline acPolyline, Helix acHelix)
        {
            Solid3d rtnValue = new Solid3d();

            try
            {
                // Convert Entity's to appropriate types
                Entity sweepEnt = (Entity)acPolyline;
                Curve pathEnt = (Curve)acHelix;

                if (sweepEnt == null || pathEnt == null)
                {
                    return null;
                }

                // We use a builder object to create
                // our SweepOptions
                SweepOptionsBuilder sob = new SweepOptionsBuilder();

                // Align the entity to sweep to the path
                sob.Align = SweepOptionsAlignOption.AlignSweepEntityToPath;

                // The base point is the start of the path
                sob.BasePoint = new Autodesk.AutoCAD.Geometry.Point3d(0, 0, 0);

                // The profile will rotate to follow the path
                sob.Bank = false;
                sob.DraftAngle = 0;

                // Now generate the solid or surface...
                Solid3d sol = new Solid3d();
                sol.SetDatabaseDefaults();
                sol.CreateSweptSolid(sweepEnt, pathEnt, sob.ToSweepOptions());
                rtnValue = sol;
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.ToString());
                rtnValue = null;
            }

            return rtnValue;
        }


    }
}
&lt;/PRE&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, 15 Jun 2015 15:55:29 GMT</pubDate>
    <dc:creator>arcticad</dc:creator>
    <dc:date>2015-06-15T15:55:29Z</dc:date>
    <item>
      <title>problems with creating a helix using c#.net</title>
      <link>https://forums.autodesk.com/t5/net-forum/problems-with-creating-a-helix-using-c-net/m-p/5675148#M39593</link>
      <description>&lt;P&gt;I'm attempting to create a helix programmatically, but it doesn't work.&amp;nbsp; Half the time it crashes autocad, and half the time it draws a helix that doesn't follow the parameters I set.&amp;nbsp; Can someone tell me what I'm doing wrong?&amp;nbsp; Here is the code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;public static ObjectId DrawHelix(Transaction transaction, Point3d startPoint, Vector3d axis, double radius, double height, double numberOfTurns, bool isLeft)&lt;/P&gt;&lt;P&gt;{&lt;BR /&gt;&amp;nbsp; try&lt;BR /&gt;&amp;nbsp; {&lt;BR /&gt;&amp;nbsp; // Open the Block table for read&lt;BR /&gt;&amp;nbsp; using (BlockTable _blockTable = transaction.GetObject(Utils.ActiveDatabase.BlockTableId, OpenMode.ForRead) as BlockTable)&lt;BR /&gt;&amp;nbsp; {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Open the Block table record Model space for write&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; using (BlockTableRecord _blockTableRecord = transaction.GetObject(_blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; using (Helix _helix = new Helix())&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _helix.BaseRadius = radius;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _helix.TopRadius = radius;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _helix.StartPoint = startPoint;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //_helix.EndPoint = endPoint; not implemented exception?&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _helix.Height = height;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _helix.Turns = numberOfTurns;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _helix.Twist = isLeft;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //_helix.AxisVector = axis;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _blockTableRecord.AppendEntity(_helix);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; transaction.AddNewlyCreatedDBObject(_helix, true);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return _helix.Id;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp; }&lt;BR /&gt;}&lt;BR /&gt;catch&lt;BR /&gt;{&lt;BR /&gt;throw new System.Exception();&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Specific questions:&lt;/P&gt;&lt;P&gt;1) Do I have to set the properties of the helix in a particular order?&lt;/P&gt;&lt;P&gt;2) Does the StartPoint property actually control the start of the helix?&amp;nbsp; On the occasions when this function works, the resulting helix is never drawn anywhere near the given start point.&lt;/P&gt;&lt;P&gt;3) Autocad's HELIX command asks the user to select a center point, but the Helix class doesn't have a CenterPoint property.&amp;nbsp; Is there a way to set the center point programmatically?&lt;/P&gt;&lt;P&gt;4) What is the AxisVector supposed to control?&amp;nbsp; I commented it out because it never seemed to affect anything.&lt;/P&gt;&lt;P&gt;5) If I later want to sweep a rectangle along the helix object, can I use the helix directly, or do I need to cast it to another type?&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jun 2015 14:14:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/problems-with-creating-a-helix-using-c-net/m-p/5675148#M39593</guid>
      <dc:creator>jz5902</dc:creator>
      <dc:date>2015-06-12T14:14:53Z</dc:date>
    </item>
    <item>
      <title>Re: problems with creating a helix using c#.net</title>
      <link>https://forums.autodesk.com/t5/net-forum/problems-with-creating-a-helix-using-c-net/m-p/5677790#M39594</link>
      <description>&lt;P&gt;This will create a Helix, Polyline and then sweep the Polyline with the Helix&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the Polylines is converted to an Entity and the helix to a Curve.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I didn't change the AxisVector, it seems to work fine without it being changed.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Geometry;

namespace CreateHelix
{
    public class clsCreateHelix
    {
        [CommandMethod("MHelix", CommandFlags.Session)]
        public void CreateHelix()
        {
            Database acCurDb = Application.DocumentManager.MdiActiveDocument.Database;
            Document doc = Application.DocumentManager.MdiActiveDocument;

            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                using (DocumentLock DocLock = doc.LockDocument())
                {
                    using (BlockTable acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable)
                    {
                        using (BlockTableRecord acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord)
                        {
                            // Create Helix
                            Helix acHelix = getHelix(270, true, 100, new Point3d(0, 0, 0), 10);
                            acBlkTblRec.AppendEntity((Entity)acHelix);
                            acTrans.AddNewlyCreatedDBObject(acHelix, true);

                            // Create Polyline for Sweep
                            Polyline acPolyline = getPolylineForSweep();
                            acBlkTblRec.AppendEntity((Entity)acPolyline);
                            acTrans.AddNewlyCreatedDBObject(acPolyline, true);
                        
                            // Sweep Polyline along helix. 
                            Solid3d acSolid = SweepAlongPath(acPolyline, acHelix);

                            if (acSolid != null)
                            {
                                acBlkTblRec.AppendEntity((Entity)acSolid);
                                acTrans.AddNewlyCreatedDBObject(acSolid, true);
                            }
                        }
                    }
                }
                acTrans.Commit();
            }
        }

        private double getTurnAngle(double dblDegrees)
        {
            return (((dblDegrees * 100) / 360) * .01);
        }

        internal Helix getHelix(double dblTurnAngle, bool CW, double dblRadius, Point3d pt3Origin, double dblHeight)
        {
            double dblDegree = getTurnAngle(dblTurnAngle);
            Helix acHelix = new Helix();
            acHelix.SetDatabaseDefaults();
            acHelix.Constrain = ConstrainType.Height;
            acHelix.StartPoint = pt3Origin;
            acHelix.BaseRadius = dblRadius;
            acHelix.TopRadius = dblRadius;
            acHelix.Height = dblHeight;
            acHelix.TurnHeight = (1 / dblDegree);
            acHelix.Turns = dblDegree;
            acHelix.Twist = !CW;
            acHelix.CreateHelix();
            return acHelix;
        }

        internal Polyline getPolylineForSweep()
        {
            Polyline pline = new Polyline();
            pline.SetDatabaseDefaults();
            // Polyline must not intersect itself
            pline.AddVertexAt(0, new Point2d(-10, 0.0), 0.0, 0.0, 0.0);
            pline.AddVertexAt(1, new Point2d(10, 0.0), 0.0, 0.0, 0.0);
            pline.AddVertexAt(2, new Point2d(10, 10), 0.0, 0.0, 0.0);
            pline.AddVertexAt(3, new Point2d(-10, 10), 0.0, 0.0, 0.0);
            pline.Closed = true;

            return pline;
        }


        internal Solid3d SweepAlongPath(Polyline acPolyline, Helix acHelix)
        {
            Solid3d rtnValue = new Solid3d();

            try
            {
                // Convert Entity's to appropriate types
                Entity sweepEnt = (Entity)acPolyline;
                Curve pathEnt = (Curve)acHelix;

                if (sweepEnt == null || pathEnt == null)
                {
                    return null;
                }

                // We use a builder object to create
                // our SweepOptions
                SweepOptionsBuilder sob = new SweepOptionsBuilder();

                // Align the entity to sweep to the path
                sob.Align = SweepOptionsAlignOption.AlignSweepEntityToPath;

                // The base point is the start of the path
                sob.BasePoint = new Autodesk.AutoCAD.Geometry.Point3d(0, 0, 0);

                // The profile will rotate to follow the path
                sob.Bank = false;
                sob.DraftAngle = 0;

                // Now generate the solid or surface...
                Solid3d sol = new Solid3d();
                sol.SetDatabaseDefaults();
                sol.CreateSweptSolid(sweepEnt, pathEnt, sob.ToSweepOptions());
                rtnValue = sol;
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.ToString());
                rtnValue = null;
            }

            return rtnValue;
        }


    }
}
&lt;/PRE&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, 15 Jun 2015 15:55:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/problems-with-creating-a-helix-using-c-net/m-p/5677790#M39594</guid>
      <dc:creator>arcticad</dc:creator>
      <dc:date>2015-06-15T15:55:29Z</dc:date>
    </item>
    <item>
      <title>Re: problems with creating a helix using c#.net</title>
      <link>https://forums.autodesk.com/t5/net-forum/problems-with-creating-a-helix-using-c-net/m-p/5687548#M39595</link>
      <description>&lt;P&gt;Thank you, arcticad.&amp;nbsp; That was very helpful.&amp;nbsp; I finally got my code working thanks to that example.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are a couple of non-obvious things I discovered through trial and error that I'd like to point out for people (like me) who aren't very experienced with Autocad.&amp;nbsp; First, the start point of the helix is actually the center of the helix, not the start of the helical path.&amp;nbsp; Second, trying to set the StartPoint property directly always had strange effects.&amp;nbsp; To position a helix where you want it, you have to use the TransformBy method.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Jun 2015 13:08:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/problems-with-creating-a-helix-using-c-net/m-p/5687548#M39595</guid>
      <dc:creator>jz5902</dc:creator>
      <dc:date>2015-06-22T13:08:54Z</dc:date>
    </item>
  </channel>
</rss>

