Author Topic: Ex: Show Thumbnail in PictureBox VB.NET  (Read 21334 times)

0 Members and 1 Guest are viewing this topic.

Jeff H

  • Needs a day job
  • Posts: 6149
Re: Ex: Show Thumbnail in PictureBox VB.NET
« Reply #15 on: September 19, 2010, 04:53:59 PM »

jgr

  • Guest
Re: Ex: Show Thumbnail in PictureBox VB.NET
« Reply #16 on: September 19, 2010, 05:36:47 PM »

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8690
  • AKA Daniel
Re: Ex: Show Thumbnail in PictureBox VB.NET
« Reply #17 on: September 20, 2010, 02:33:00 AM »
I think the blockIcon command  generates  32x32x8bpp bitmaps,  I was able to create them via AcGsDevice/ AcGsView && MFC. 
http://www.theswamp.org/index.php?topic=33116.msg401299#msg401299

For .net have a look at Autodesk.AutoCAD.GraphicsSystem.GetSnapshot(Rectangle rectangle); You should be able to render the block and take a snapshot,  I think you can do this via OffScreenDevice so you're not capturing off a control like I did

Jeff H

  • Needs a day job
  • Posts: 6149
Re: Ex: Show Thumbnail in PictureBox VB.NET
« Reply #18 on: September 20, 2010, 03:02:24 AM »
I use PreviewIcon with no problem
but this was a reply for CapturePreviewImage which broke in 2011 and the drawing does not have to be active
Quote
The behavior has been already reported. The current status for the Change Request is fixed and it should be available in the upcoming AutoCAD update.
As a workaround, The property “Layout.Thumbnail” should give you the layout/paper space thumbnail bitmap.”

Or if you need a thumbnail of the model space you can use the code I provided in my initial reply.


It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8690
  • AKA Daniel
Re: Ex: Show Thumbnail in PictureBox VB.NET
« Reply #19 on: September 20, 2010, 03:05:43 AM »
DoH! sorry, my mistake, just ignore me   :whistle:

Jeff H

  • Needs a day job
  • Posts: 6149
Re: Ex: Show Thumbnail in PictureBox VB.NET
« Reply #20 on: September 20, 2010, 03:07:05 AM »
This one brings up a dialog box though

Quote

 <DllImport("acad.exe", CallingConvention:=CallingConvention.Cdecl, CharSet:=CharSet.Unicode)> _
Private Shared Function acedCommand(ByVal type1 As Integer, ByVal command As String, ByVal type2 As Integer, ByVal blockName As String, ByVal [end] As Integer) As Integer

        If btr.PreviewIcon Is Nothing Then
            acedCommand(5005, "BLOCKICON", 5005, blkName, 5000)

Jeff H

  • Needs a day job
  • Posts: 6149
Re: Ex: Show Thumbnail in PictureBox VB.NET
« Reply #21 on: September 20, 2010, 03:08:36 AM »
Did you figure out in .NET another way for blocks with out having to call BlockIcon 

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8690
  • AKA Daniel
Re: Ex: Show Thumbnail in PictureBox VB.NET
« Reply #22 on: September 20, 2010, 03:28:57 AM »
Not with .NET, but I assume you can use the classes within Autodesk.AutoCAD.GraphicsSystem to render, view, or get a snapshot of any entity(s) just as you can with the underlying AcGs classes.

Jeff H

  • Needs a day job
  • Posts: 6149
Re: Ex: Show Thumbnail in PictureBox VB.NET
« Reply #23 on: September 20, 2010, 04:02:09 AM »
That NameSpace does not like me every thing I played around with in it has crashed or just leaves a bunch of stuff all over the screen including code from ADN but I am pretty sure it has to do with I have no idea what I doing?

Jeff H

  • Needs a day job
  • Posts: 6149
Re: Ex: Show Thumbnail in PictureBox VB.NET
« Reply #24 on: September 20, 2010, 05:30:15 AM »
The Database.ThumbnailBitmap reads like 200 out of 200 iterating through a folder

This one read 0 out of a 200

Code: [Select]

        [System.Security.SuppressUnmanagedCodeSecurity(), DllImport("acdb18.dll", CallingConvention = CallingConvention.Cdecl,
         EntryPoint = "?acdbGetPreviewBitmap@@YAPEAUtagBITMAPINFO@@PEB_W@Z")]
        private static extern IntPtr acdbGetPreviewBitmap([MarshalAs(UnmanagedType.LPWStr)] string sFilename);

        System.Drawing.Bitmap GetBitmapFromDwg(string filename)
        {
            IntPtr bmpInfo = acdbGetPreviewBitmap(filename);
            return Autodesk.AutoCAD.Runtime.Marshaler.BitmapInfoToBitmap(bmpInfo);
        }

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8690
  • AKA Daniel
Re: Ex: Show Thumbnail in PictureBox VB.NET
« Reply #25 on: September 20, 2010, 06:14:45 AM »
I'm a little confused are you trying to get the PreviewBitmap for the drawing or the PreviewIcon(still bitmaps) from the BlockTableRecord?

Jeff H

  • Needs a day job
  • Posts: 6149
Re: Ex: Show Thumbnail in PictureBox VB.NET
« Reply #26 on: September 20, 2010, 12:49:04 PM »
Sorry
There all thrown together
Basically I have no problems getting either a BlockTableRecord's or "drawings or layout's" bitmap's closed or open, but I have not found a stable method for generating one if it does not exist.


It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8690
  • AKA Daniel
Re: Ex: Show Thumbnail in PictureBox VB.NET
« Reply #27 on: September 21, 2010, 03:57:39 AM »
Simple, use the  AcGsVew classes as I mentioned earlier

here is a snippit of a form, just use your block or any other entity

Code: [Select]
namespace ExecMethod
{
  public partial class ViewFrm : Form
  {
    AcGs.Manager manager = null;
    AcGs.Device device = null;
    AcGs.Model model = null;
    AcGs.View view = null;

    public ViewFrm()
    {

      InitializeComponent();

      manager = AcAp.Application.DocumentManager.MdiActiveDocument.GraphicsManager;
      device = manager.CreateAutoCADDevice(this.Handle);
      device.OnSize(new System.Drawing.Size(300, 300));
      model = manager.CreateAutoCADModel();

      // you can use your block ref for this
      view = manager.CreateAutoCADView(new Line(new Point3d(0, 0, 0), new Point3d(300, 300, 0)));
      device.Add(view);
      view.ZoomExtents(new Point3d(0, 0, 0), new Point3d(300, 300, 0));

      //Bitmap bmp = view.GetSnapshot(new System.Drawing.Size(300, 300)) <<<<<------------------------
    }

    private void ViewFrm_Paint(object sender, PaintEventArgs e)
    {
      view.Invalidate();
      view.Update();
    }
  }
}


Jeff H

  • Needs a day job
  • Posts: 6149
Re: Ex: Show Thumbnail in PictureBox VB.NET
« Reply #28 on: September 21, 2010, 04:22:29 AM »
Finally I used that class without crashing
Once again Thank you

AHH!
It just crashed in the background


*EDIT*
 After I close the form about 5 to 10 seconds later it crashes


*EDIT*
http://forums.autodesk.com/t5/AutoCAD-2007/Unhandled-Access-Violaton-Writing-0x0014-Exception-at-7788fc47h/td-p/2674073
Is the same error
It might be something with my system
Thanks again for the code
« Last Edit: September 21, 2010, 04:42:39 AM by fro2001 »

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8690
  • AKA Daniel
Re: Ex: Show Thumbnail in PictureBox VB.NET
« Reply #29 on: September 21, 2010, 05:52:58 AM »
Sorry, it was only indented to give you an idea, you probably need to do a bit of disposing