TheSwamp

Code Red => .NET => Topic started by: It's Alive! on August 14, 2008, 02:17:41 PM

Title: Is this a Bug in AutoCAD 2009?
Post by: It's Alive! on August 14, 2008, 02:17:41 PM
Can someone run this code in  07 or 08 then in 09, and let me know if you see any differences?
Don’t worry it won’t crash  :-o

Code: [Select]
#region #Using delarations
using System;

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;

using AcAp = Autodesk.AutoCAD.ApplicationServices;
using AcDb = Autodesk.AutoCAD.DatabaseServices;

#endregion

[assembly: CommandClass(typeof(ExecMethod.Commands))]

namespace ExecMethod
{
  public class Commands
  {
    [CommandMethod("doit")]
    public static void doit()
    {
      Editor editor = AcAp.Application.DocumentManager.MdiActiveDocument.Editor;
      Database database = HostApplicationServices.WorkingDatabase;
      AcDb.TransactionManager manager = database.TransactionManager;

      Polyline pl = new Polyline(4);

      Point2d pt1 = new Point2d(0,0);
      Point2d pt2 = new Point2d(0,100);
      Point2d pt3 = new Point2d(100,100);
      Point2d pt4 = new Point2d(100,0);

      pl.AddVertexAt(0, pt1, 0, 0, 0);
      pl.AddVertexAt(1, pt2, 0, 0, 0);
      pl.AddVertexAt(2, pt3, 0, 0, 0);
      pl.AddVertexAt(3, pt4, 0, 0, 0);
      pl.Closed = true;

      Vector2d move = new Vector2d(1000, 1000);

      using(Transaction transaction = manager.StartTransaction())
      {
        ObjectId modelSpaceId = SymbolUtilityServices.GetBlockModelSpaceId(database);
        BlockTableRecord record = transaction.GetObject(modelSpaceId, OpenMode.ForWrite) as BlockTableRecord;
        ObjectId mylineId = record.AppendEntity(pl);
        transaction.AddNewlyCreatedDBObject(pl, true);

        Polyline myLine = transaction.GetObject(mylineId, OpenMode.ForWrite) as Polyline;

        myLine.SetPointAt(0, pt1.Add(move));
        myLine.SetPointAt(1, pt2.Add(move));
        myLine.SetPointAt(2, pt3.Add(move));
        myLine.SetPointAt(3, pt4.Add(move));

        transaction.Commit();
      }
    }
  }
}
Title: Re: Is this a Bug in AutoCAD 2009?
Post by: It's Alive! on August 14, 2008, 02:20:32 PM
here is the dll
Title: Re: Is this a Bug in AutoCAD 2009?
Post by: HD on August 14, 2008, 02:33:51 PM
I netloaded ExecMethod2.dll and executed DoIt from 08 and 09 and didn't see any differences. End result was a nice square box in both 08 and 09.
Title: Re: Is this a Bug in AutoCAD 2009?
Post by: Glenn R on August 14, 2008, 04:19:38 PM
Are you targetting any particular framework with that dll Dan? ie I have every framework known to man and every version of Acad from '06 upwards..........
Title: Re: Is this a Bug in AutoCAD 2009?
Post by: It's Alive! on August 14, 2008, 08:49:45 PM
I netloaded ExecMethod2.dll and executed DoIt from 08 and 09 and didn't see any differences. End result was a nice square box in both 08 and 09.

Thanks for testing this
 In 09 , I get a don’t get a box, I get a line
Title: Re: Is this a Bug in AutoCAD 2009?
Post by: It's Alive! on August 14, 2008, 08:50:23 PM
Are you targetting any particular framework with that dll Dan? ie I have every framework known to man and every version of Acad from '06 upwards..........

just installed .net 3.5 SP1, but I don’t know if that’s the cause yet.
Title: Re: Is this a Bug in AutoCAD 2009?
Post by: It's Alive! on August 15, 2008, 06:19:02 AM
Well, I have done everything I can think of (including reinstalling AutoCAD) but this code still fails on my computer. Hmm

Title: Re: Is this a Bug in AutoCAD 2009?
Post by: It's Alive! on August 15, 2008, 06:45:58 AM
Ok, I think I have it narrowed down to  “Point2d.Add(Vector2d)”

08 returns  (25,25)(25,125)(125,125)(25,125)(25,25)(100024,100024)
09 returns  (25,0)(25,0)(125,0)(25,0)(25,0)(100024,0)

It seems that AutoCAD 09 is losing the Y value. Well! At least I can write my own work-around function, I thought the problem was in the polyline class

Code: [Select]
    // result from 08 (25,25)(25,125)(125,125)(25,125)(25,25)(100024,100024)
    // result from 09 (25,0)(25,0)(125,0)(25,0)(25,0)(100024,0)
    [CommandMethod("doit")]
    public static void doit()
    {
      Editor editor = AcAp.Application.DocumentManager.MdiActiveDocument.Editor;

      Vector2d MoveBy = new Vector2d(25, 25);

      Point2dCollection ptc = new Point2dCollection();
      ptc.Add(new Point2d(0, 0));
      ptc.Add(new Point2d(0, 100));
      ptc.Add(new Point2d(100,100));
      ptc.Add(new Point2d(0, 100));
      ptc.Add(new Point2d(0, 0));
      ptc.Add(new Point2d(99999, 99999));

      //bug in Point2d.Add(vector2d)
      foreach (Point2d pt in ptc)
      {
        editor.WriteMessage("{0}", pt.Add(MoveBy));
      }
    }
Title: Re: Is this a Bug in AutoCAD 2009?
Post by: It's Alive! on August 19, 2008, 02:03:10 AM
It’s a bug in .NET 3.5 SP1
 http://discussion.autodesk.com/thread.jspa?threadID=685493