TheSwamp

Code Red => .NET => Topic started by: It's Alive! on April 03, 2008, 02:16:06 AM

Title: BMP to Cad
Post by: It's Alive! on April 03, 2008, 02:16:06 AM
 :-D

Code: [Select]

[CommandMethod("bmptocad")]
    public void test()
    {
      Bitmap bitmap = new Bitmap("C:\\hal9000.bmp");
      Database db = AcAp.Application.DocumentManager.MdiActiveDocument.Database;
      using (Transaction tr = db.TransactionManager.StartTransaction())
      {
        AcDb.BlockTableRecord currentSpace = tr.GetObject
                        (db.CurrentSpaceId, OpenMode.ForWrite) as AcDb.BlockTableRecord;
        for (int i = 0; i < bitmap.Width; i++)
        {
          for (int j = 0; j < bitmap.Height; j++)
          {
            DBPoint point = new DBPoint(new Point3d(i,j,0));
            point.Color = Autodesk.AutoCAD.Colors.Color.FromColor( bitmap.GetPixel(i,j));
            currentSpace.AppendEntity(point);
            tr.AddNewlyCreatedDBObject(point, true);
          }
        }
        tr.Commit();
      }
    }


Title: Re: BMP to Cad
Post by: kdub_nz on April 03, 2008, 02:20:45 AM
nice one dave !

:-)
Title: Re: BMP to Cad
Post by: It's Alive! on April 03, 2008, 02:40:07 AM
nice one dave !

:-)

Thanks KB just having a little fun  :laugh:
Title: Re: BMP to Cad
Post by: Glenn R on April 03, 2008, 05:38:22 AM
Fairly high C.F.I. (Coolness Factor Index) there Dan.
Title: Re: BMP to Cad
Post by: It's Alive! on April 03, 2008, 05:47:52 AM
Fairly high C.F.I. (Coolness Factor Index) there Dan.

Thanks Glenn  :-)
I need to reverse the scan so the picture comes in right side up,  I was also thinking it might be fun to place the point Z based on color Ie. Lighter colors would have a higher elevation.
Title: Re: BMP to Cad
Post by: It's Alive! on April 03, 2008, 06:31:57 AM
Wow cool  :-D

Code: [Select]
[CommandMethod("doit")]
    public void test()
    {
      Bitmap bitmap = new Bitmap("C:\\hal9000.bmp");
      Database db = AcAp.Application.DocumentManager.MdiActiveDocument.Database;
      using (Transaction tr = db.TransactionManager.StartTransaction())
      {
        AcDb.BlockTableRecord currentSpace = tr.GetObject
                        (db.CurrentSpaceId, OpenMode.ForWrite) as AcDb.BlockTableRecord;
        for (int i = 0; i < bitmap.Width; i++)
        {
          for (int j = 0; j < bitmap.Height; j++)
          {
            DBPoint point = new DBPoint();
            Autodesk.AutoCAD.Colors.Color color =
              Autodesk.AutoCAD.Colors.Color.FromColor(bitmap.GetPixel(i, j));
            point.Color = color;
            double z = (color.ColorValue.R + color.ColorValue.G + color.ColorValue.B) * 0.01;//change this
            point.Position = new Point3d(i, j, z);
            currentSpace.AppendEntity(point);
            tr.AddNewlyCreatedDBObject(point, true);
          }
        }
        tr.Commit();
      }
    }

Title: Re: BMP to Cad
Post by: MickD on April 03, 2008, 06:41:29 AM
good sh1t Dan  :kewl:

i'd imagine it bogs acad down a bit though yes?
Title: Re: BMP to Cad
Post by: It's Alive! on April 03, 2008, 06:45:05 AM
good sh1t Dan  :kewl:

i'd imagine it bogs acad down a bit though yes?

hehe Not too bad on small images, don’t go loading a 5 mega pixel pic though  :lol:
Title: Re: BMP to Cad
Post by: It's Alive! on April 03, 2008, 06:52:26 AM
and triangulated  :laugh:

Title: Re: BMP to Cad
Post by: Chuck Gabriel on April 03, 2008, 07:13:06 AM
That is so cool, I don't even have words for it.
Title: Re: BMP to Cad
Post by: It's Alive! on April 03, 2008, 01:25:34 PM
That is so cool, I don't even have words for it.

Thanks Chuck,
While it’s much prettier than my Morse code lisp routine, it probably just a useful  :laugh:
Title: Re: BMP to Cad
Post by: Glenn R on April 03, 2008, 01:51:50 PM
Image "binding" anyone?
Title: Re: BMP to Cad
Post by: Josh Nieman on April 03, 2008, 02:01:04 PM
thaaaaat's probably one of the cooler things I've seen in a while! lol
Title: Re: BMP to Cad
Post by: Antisthenes on April 03, 2008, 02:17:47 PM
nice you made the  "Heightfield"  command
Title: Re: BMP to Cad
Post by: Swift on April 03, 2008, 03:51:02 PM
Nice work

I've been pondering something similar using tiffs
Title: Re: BMP to Cad
Post by: alanjt on April 03, 2008, 04:24:58 PM
i know i'm asking a rather stupid question, but how do you use that coding. it's actually quite useful, i just don't understand what to do with the coding to get it to work.
Title: Re: BMP to Cad
Post by: Antisthenes on April 03, 2008, 04:25:16 PM
yes bmp jpg pcx png and tiff are supported
Title: Re: BMP to Cad
Post by: FengK on April 03, 2008, 06:12:59 PM
:-D
Code: [Select]
[CommandMethod("bmptocad")]

Very cool Daniel! Did you notice the image is flipped upside down?
Title: Re: BMP to Cad
Post by: FengK on April 04, 2008, 04:57:19 AM
changing this line
DBPoint point = new DBPoint(new Point3d(i,j,0));
to
DBPoint point = new DBPoint(new Point3d(i,0-j,0));

seems to be a fix.
Title: Re: BMP to Cad
Post by: Kerry on April 04, 2008, 07:19:30 AM
hehehehe
http://www.objectarx.net/bbs/viewthread.php?tid=1766&extra=page%3D1

added
Quote from: translation
Reads in a BMP document to see to AutoCAD in at a foreigner's forum,
may read a BMP document in AutoCAD.
Title: Re: BMP to Cad
Post by: It's Alive! on April 04, 2008, 10:11:30 AM
hehehehe
http://www.objectarx.net/bbs/viewthread.php?tid=1766&extra=page%3D1

added
Quote from: translation
Reads in a BMP document to see to AutoCAD in at a foreigner's forum,
may read a BMP document in AutoCAD.

Well, hot dang, I have finally written code that’s good enough to be …
Title: Re: BMP to Cad
Post by: It's Alive! on April 04, 2008, 10:14:22 AM
changing this line
DBPoint point = new DBPoint(new Point3d(i,j,0));
to
DBPoint point = new DBPoint(new Point3d(i,0-j,0));

seems to be a fix.

Awesome, Thank you! :-)
Title: Re: BMP to Cad
Post by: mjfarrell on April 04, 2008, 10:29:33 AM
Daniel, cool stuff for sure.


管理员



帖子794 精华1 积分4451 来自中国 个人空间 发
Title: Re: BMP to Cad
Post by: nlund1972 on April 04, 2008, 05:17:14 PM
I want to try this, but how do create the command in CAD?
Title: Re: BMP to Cad
Post by: It's Alive! on April 05, 2008, 10:46:55 AM
i know i'm asking a rather stupid question, but how do you use that coding. it's actually quite useful, i just don't understand what to do with the coding to get it to work.

I have attached a DLL that you can netload into AutoCAD and execute through lisp I.E
Code: [Select]
(BMPToCad "c:\\hal9000.bmp"  0)