<?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 How to code Fillet function when use the c# laHow nguage,please look at the code in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/how-to-code-fillet-function-when-use-the-c-lahow-nguage-please/m-p/6067238#M36941</link>
    <description>&lt;P&gt;I want to use code to implement cad function fillet,now here is my code&lt;/P&gt;&lt;PRE&gt;public class Class1
    {
        [DllImport("acad.exe", EntryPoint = "acedCmd", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
        private extern static int acedCmd(IntPtr rbp);

        public static ObjectId toModelSpace(Entity ent)
        {
            Database db = HostApplicationServices.WorkingDatabase;
            ObjectId endId;
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
                BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
                endId = btr.AppendEntity(ent);
                trans.AddNewlyCreatedDBObject(ent, true);
                trans.Commit();
            }
            return endId;
        }
        
        public static int AcedCmd(Editor ed, ResultBuffer args)
        {
            if (!Application.DocumentManager.IsApplicationContext)
                return acedCmd(args.UnmanagedObject);
            else
                return 0;
        }
        [CommandMethod("ArxCommand")]
        public void ComCommand() {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            
            Line l1 = new Line(new Point3d(),new Point3d(1000,1000,0));
            Line l2 = new Line(new Point3d(0,400,0),new Point3d(500,0,0));
            toModelSpace(l1);
            toModelSpace(l2);
            
            ResultBuffer rb = new ResultBuffer();
            rb.Add(new TypedValue(5005, "_fillet"));
            rb.Add(new TypedValue(5005, "r"));
            rb.Add(new TypedValue(5001, 10));
            rb.Add(new TypedValue(5006, l1.ObjectId));
            rb.Add(new TypedValue(5006, l2.ObjectId));
            rb.Add(new TypedValue());
            AcedCmd(ed, rb);  
        }
        
    }&lt;/PRE&gt;&lt;P&gt;After the code runs but does not function,We hope to see where a problem write please,thanks!&lt;/P&gt;</description>
    <pubDate>Thu, 03 Mar 2016 02:37:10 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2016-03-03T02:37:10Z</dc:date>
    <item>
      <title>How to code Fillet function when use the c# laHow nguage,please look at the code</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-code-fillet-function-when-use-the-c-lahow-nguage-please/m-p/6067238#M36941</link>
      <description>&lt;P&gt;I want to use code to implement cad function fillet,now here is my code&lt;/P&gt;&lt;PRE&gt;public class Class1
    {
        [DllImport("acad.exe", EntryPoint = "acedCmd", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
        private extern static int acedCmd(IntPtr rbp);

        public static ObjectId toModelSpace(Entity ent)
        {
            Database db = HostApplicationServices.WorkingDatabase;
            ObjectId endId;
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
                BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
                endId = btr.AppendEntity(ent);
                trans.AddNewlyCreatedDBObject(ent, true);
                trans.Commit();
            }
            return endId;
        }
        
        public static int AcedCmd(Editor ed, ResultBuffer args)
        {
            if (!Application.DocumentManager.IsApplicationContext)
                return acedCmd(args.UnmanagedObject);
            else
                return 0;
        }
        [CommandMethod("ArxCommand")]
        public void ComCommand() {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            
            Line l1 = new Line(new Point3d(),new Point3d(1000,1000,0));
            Line l2 = new Line(new Point3d(0,400,0),new Point3d(500,0,0));
            toModelSpace(l1);
            toModelSpace(l2);
            
            ResultBuffer rb = new ResultBuffer();
            rb.Add(new TypedValue(5005, "_fillet"));
            rb.Add(new TypedValue(5005, "r"));
            rb.Add(new TypedValue(5001, 10));
            rb.Add(new TypedValue(5006, l1.ObjectId));
            rb.Add(new TypedValue(5006, l2.ObjectId));
            rb.Add(new TypedValue());
            AcedCmd(ed, rb);  
        }
        
    }&lt;/PRE&gt;&lt;P&gt;After the code runs but does not function,We hope to see where a problem write please,thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2016 02:37:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-code-fillet-function-when-use-the-c-lahow-nguage-please/m-p/6067238#M36941</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-03-03T02:37:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to code Fillet function when use the c# laHow nguage,please look at the</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-code-fillet-function-when-use-the-c-lahow-nguage-please/m-p/6067499#M36942</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tested your code and found 2 issues:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1) Are you sure you need to use "acad.exe" in your DllImport? It's "accore.dll" since AutoCAD 2013.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) I set the "FILLETRAD" variable first to overwrite the radius and then "_fillet" command w/o resetting the radius&lt;/P&gt;&lt;PRE&gt; Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("FILLETRAD", 10.0);&lt;BR /&gt;&amp;nbsp;ResultBuffer rb = new ResultBuffer();&lt;BR /&gt;&amp;nbsp;rb.Add(new TypedValue(5005, "_fillet"));&lt;BR /&gt;&amp;nbsp;rb.Add(new TypedValue(5006, l1.ObjectId));&lt;BR /&gt;&amp;nbsp;rb.Add(new TypedValue(5006, l2.ObjectId));&lt;BR /&gt;&amp;nbsp;AcedCmd(ed, rb);&lt;/PRE&gt;&lt;P&gt;the code now runs perfectly&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2016 08:09:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-code-fillet-function-when-use-the-c-lahow-nguage-please/m-p/6067499#M36942</guid>
      <dc:creator>sergey.utkin</dc:creator>
      <dc:date>2016-03-03T08:09:46Z</dc:date>
    </item>
    <item>
      <title>Re : How to code Fillet function when use the c# laHow nguage,please look at the</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-code-fillet-function-when-use-the-c-lahow-nguage-please/m-p/6067837#M36943</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since AutoCAD 2009 (as I recall) instead of P/Invoking acedCmd(), you can use Tony Tanzillo's wrapper for the non-public Editor.RunCommand() method.&lt;/P&gt;
&lt;P&gt;Since AutoCAD 2015 you have to use the new Editor.Command() built-in method.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;using Autodesk.AutoCAD.ApplicationServices;
using System;
using System.Reflection;

namespace Autodesk.AutoCAD.EditorInput
{
    // From Tony Tanzillo
    // https://www.theswamp.org/index.php?topic=43113.msg483306#msg483306
    public static class MyEditorExtensions
    {
        static MethodInfo runCommand = typeof(Editor).GetMethod(
           "RunCommand", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);

        public static PromptStatus Command(this Editor ed, params object[] args)
        {
            if (Application.DocumentManager.IsApplicationContext)
                throw new InvalidOperationException("Invalid execution context for Command()");
            if (ed.Document != Application.DocumentManager.MdiActiveDocument)
                throw new InvalidOperationException("Document is not active");
            return (PromptStatus)runCommand.Invoke(ed, new object[] { args });
        }
    }
}&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With both upper methods, you do not need anymore to build a ResultBuffer, just pass .NET typed objects as arguments&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;doc.Database.Filletrad = 10.0;
ed.Command("_.fillet", l1.ObjectId, l2.ObjectId);&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note the _FILLET command also accepts points as arguments, in your case (crossing lines) this allows to specify the line side you want to keep:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;doc.Database.Filletrad = 10.0;&lt;BR /&gt;ed.Command("_.fillet", new Point3d(1000, 1000, 0), new Point3d(0, 400, 0));&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2016 11:45:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-code-fillet-function-when-use-the-c-lahow-nguage-please/m-p/6067837#M36943</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2016-03-03T11:45:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to code Fillet function when use the c# laHow nguage,please look at the</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-code-fillet-function-when-use-the-c-lahow-nguage-please/m-p/6069889#M36944</link>
      <description>&lt;P&gt;以圆角半径为偏移距离分别偏移已知圆和直线,得到辅助圆和辅助直线,其交点即为圆角弧的圆心.以此点为圆心,以圆角半径为半径画第二个辅助圆,其与已知圆和已知直线的交点(其实是切点)即为圆角弧的起点和端点.画好圆角弧后删除辅助直线和两个辅助圆即可.&lt;BR /&gt;按不同的偏移方向,最多可能得到8个圆角弧的圆心,具体哪个合适,要根据具体情况判断.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2016 08:11:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-code-fillet-function-when-use-the-c-lahow-nguage-please/m-p/6069889#M36944</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-03-04T08:11:16Z</dc:date>
    </item>
    <item>
      <title>Re : How to code Fillet function when use the c# laHow nguage,please look at the</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-code-fillet-function-when-use-the-c-lahow-nguage-please/m-p/6069940#M36945</link>
      <description>&lt;P&gt;but my cad version is 2007,how to release this function&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2016 08:57:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-code-fillet-function-when-use-the-c-lahow-nguage-please/m-p/6069940#M36945</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-03-04T08:57:40Z</dc:date>
    </item>
    <item>
      <title>Re : How to code Fillet function when use the c# laHow nguage,please look at the</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-code-fillet-function-when-use-the-c-lahow-nguage-please/m-p/6070014#M36946</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;itxingqing a écrit&amp;nbsp;:&lt;BR /&gt;
&lt;P&gt;but my cad version is 2007,how to release this function&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If so you cannot use the upper methods, you need to P/Invoke acedCmd as you do or build some wrapper to get it more friendly:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        [System.Security.SuppressUnmanagedCodeSecurity]
        [DllImport("acad.exe", EntryPoint = "acedCmd",
            CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
        extern static private int acedCmd(IntPtr resbuf);

        /// &amp;lt;summary&amp;gt;
        /// Call an AutoCAD command (works synchronously).
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name="args"&amp;gt;The command name followed by command inputs.&amp;lt;/param&amp;gt;
        public static void Command(params object[] args)
        {
            ResultBuffer resbuf = new ResultBuffer();
            foreach (object obj in args)
            {
                switch (obj.GetType().Name)
                {
                    case "String":
                        resbuf.Add(new TypedValue(5005, obj)); break;
                    case "Int16":
                        resbuf.Add(new TypedValue(5003, obj)); break;
                    case "Int32":
                        resbuf.Add(new TypedValue(5010, obj)); break;
                    case "Double":
                        resbuf.Add(new TypedValue(5001, obj)); break;
                    case "Point2d":
                        resbuf.Add(new TypedValue(5002, obj)); break;
                    case "Point3d":
                        resbuf.Add(new TypedValue(5009, obj)); break;
                    case "ObjectId":
                        resbuf.Add(new TypedValue(5006, obj)); break;
                    case "ObjectId[]":
                        foreach (ObjectId id in (ObjectId[])obj)
                            resbuf.Add(new TypedValue(5006, id));
                        break;
                    case "ObjectIdCollection":
                        foreach (ObjectId id in (ObjectIdCollection)obj)
                            resbuf.Add(new TypedValue(5006, id));
                        break;
                    case "SelectionSetDelayMarshalled":
                    case "SelectionSetFullyMarshalled":
                        resbuf.Add(new TypedValue(5007, obj)); break;
                    default:
                        throw new InvalidOperationException("Unsupported type in Command() method");
                }
            }
            acedCmd(resbuf.UnmanagedObject);
        }&lt;/PRE&gt;
&lt;P&gt;Then, just do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;doc.Database.Filletrad = 10.0;
Command("_.fillet", l1.ObjectId, l2.ObjectId);&lt;/PRE&gt;
&lt;P&gt;or:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;doc.Database.Filletrad = 10.0;&lt;BR /&gt;Command("_.fillet", new Point3d(1000, 1000, 0), new Point3d(0, 400, 0));&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2016 09:55:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-code-fillet-function-when-use-the-c-lahow-nguage-please/m-p/6070014#M36946</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2016-03-04T09:55:26Z</dc:date>
    </item>
    <item>
      <title>Re : How to code Fillet function when use the c# laHow nguage,please look at the</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-code-fillet-function-when-use-the-c-lahow-nguage-please/m-p/6201563#M36947</link>
      <description>&lt;P&gt;yes , thanks i have try your answer ,it is work ,thank you very much&lt;/P&gt;</description>
      <pubDate>Mon, 07 Mar 2016 01:00:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-code-fillet-function-when-use-the-c-lahow-nguage-please/m-p/6201563#M36947</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-03-07T01:00:15Z</dc:date>
    </item>
    <item>
      <title>Re: Re : How to code Fillet function when use the c# laHow nguage,please look at</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-code-fillet-function-when-use-the-c-lahow-nguage-please/m-p/8746179#M36948</link>
      <description>&lt;P&gt;Old thread, but hopefully you can help. Sometimes when i use the ObjectId method it fillets the wrong end of my line. But when I use the point method, if there are overlapping lines it could fillet the wrong line at the specified point. Do you know if there is a way to include both ObjectIds and points as arguments to ensure the correct objectId and correct side are filleted?&lt;/P&gt;</description>
      <pubDate>Mon, 22 Apr 2019 21:23:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-code-fillet-function-when-use-the-c-lahow-nguage-please/m-p/8746179#M36948</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-04-22T21:23:39Z</dc:date>
    </item>
    <item>
      <title>Re: Re : How to code Fillet function when use the c# laHow nguage,please look at</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-code-fillet-function-when-use-the-c-lahow-nguage-please/m-p/8746610#M36949</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming you know the polyline geometry, instead of calling the native command and simulate user inputs, it may be easier to compute the fillet.&lt;/P&gt;
&lt;P&gt;You can use these extensions methods from the &lt;A href="http://www.theswamp.org/index.php?topic=31865.msg373672#msg373672" target="_blank" rel="noopener"&gt;GeometryExtensions&lt;/A&gt; library.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;    static class Extensions
    {
        /// &amp;lt;summary&amp;gt;
        /// Adds an arc (fillet), if able, at each polyline vertex.
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name="pline"&amp;gt;The instance to which the method applies.&amp;lt;/param&amp;gt;
        /// &amp;lt;param name="radius"&amp;gt;The arc radius.&amp;lt;/param&amp;gt;
        public static void FilletAll(this Polyline pline, double radius)
        {
            int n = pline.Closed ? 0 : 1;
            for (int i = n; i &amp;lt; pline.NumberOfVertices - n; i += 1 + pline.FilletAt(i, radius))
            { }
        }

        /// &amp;lt;summary&amp;gt;
        /// Adds an arc (fillet) at the specified vertex.
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name="pline"&amp;gt;The instance to which the method applies.&amp;lt;/param&amp;gt;
        /// &amp;lt;param name="index"&amp;gt;The index of the vertex.&amp;lt;/param&amp;gt;
        /// &amp;lt;param name="radius"&amp;gt;The arc radius.&amp;lt;/param&amp;gt;
        /// &amp;lt;returns&amp;gt;1, if the operation succeeded; 0, if it failed.&amp;lt;/returns&amp;gt;
        public static int FilletAt(this Polyline pline, int index, double radius)
        {
            int prev = index == 0 &amp;amp;&amp;amp; pline.Closed ? pline.NumberOfVertices - 1 : index - 1;
            if (pline.GetSegmentType(prev) != SegmentType.Line ||
                pline.GetSegmentType(index) != SegmentType.Line)
            {
                return 0;
            }
            LineSegment2d seg1 = pline.GetLineSegment2dAt(prev);
            LineSegment2d seg2 = pline.GetLineSegment2dAt(index);
            Vector2d vec1 = seg1.StartPoint - seg1.EndPoint;
            Vector2d vec2 = seg2.EndPoint - seg2.StartPoint;
            double angle = (Math.PI - vec1.GetAngleTo(vec2)) / 2.0;
            double dist = radius * Math.Tan(angle);
            if (dist == 0.0 || dist &amp;gt; seg1.Length || dist &amp;gt; seg2.Length)
            {
                return 0;
            }
            Point2d pt1 = seg1.EndPoint + vec1.GetNormal() * dist;
            Point2d pt2 = seg2.StartPoint + vec2.GetNormal() * dist;
            double bulge = Math.Tan(angle / 2.0);
            if (Clockwise(seg1.StartPoint, seg1.EndPoint, seg2.EndPoint))
            {
                bulge = -bulge;
            }
            pline.AddVertexAt(index, pt1, bulge, 0.0, 0.0);
            pline.SetPointAt(index + 1, pt2);
            return 1;
        }

        /// &amp;lt;summary&amp;gt;
        /// Evaluates if the points are clockwise.
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name="p1"&amp;gt;First point.&amp;lt;/param&amp;gt;
        /// &amp;lt;param name="p2"&amp;gt;Second point&amp;lt;/param&amp;gt;
        /// &amp;lt;param name="p3"&amp;gt;Third point&amp;lt;/param&amp;gt;
        /// &amp;lt;returns&amp;gt;True if points are clockwise, False otherwise.&amp;lt;/returns&amp;gt;
        private static bool Clockwise(Point2d p1, Point2d p2, Point2d p3)
        {
            return ((p2.X - p1.X) * (p3.Y - p1.Y) - (p2.Y - p1.Y) * (p3.X - p1.X)) &amp;lt; 1e-8;
        }
    }&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Apr 2019 06:11:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-code-fillet-function-when-use-the-c-lahow-nguage-please/m-p/8746610#M36949</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2019-04-23T06:11:01Z</dc:date>
    </item>
  </channel>
</rss>

