Author Topic: Recreate Thumbnail for saved Drawing  (Read 3365 times)

0 Members and 1 Guest are viewing this topic.

vegbruiser

  • Guest
Recreate Thumbnail for saved Drawing
« on: April 15, 2014, 07:28:37 AM »
Afternoon folks,

Maybe my search-fu has deserted me but am I correct in thinking that the only way to create/update the thumbnail for a .dwg file saved from a .NET application is to fake it by sending the save command to the Autocad command line and not via some fancy API-method?

If so, does someone have an example/link they can share that shows how to do this?

Thanks,

Alex.

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Recreate Thumbnail for saved Drawing
« Reply #1 on: April 15, 2014, 09:54:17 AM »
This blog post probably has the solution you are after.


http://through-the-interface.typepad.com/through_the_interface/2009/10/streamlined-quicksaveas-command-for-autocad-2010.html


I believe the required lines of code are something similar to this


Code - C#: [Select]
  1. Bitmap thumb = doc.CapturePreviewImage(320, 240);
  2. doc.Database.ThumbnailBitmap = thumb;

Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

vegbruiser

  • Guest
Re: Recreate Thumbnail for saved Drawing
« Reply #2 on: April 15, 2014, 10:00:14 AM »
Thanks Keith that's exactly what I need.

I can't count the number of times I've ultimately ended up back at Kean's site after umpteen fruitless searches elsewhere over the years. :)

Cheers,

Alex.

vegbruiser

  • Guest
Re: Recreate Thumbnail for saved Drawing
« Reply #3 on: April 15, 2014, 10:15:40 AM »
Actually, something's not right with this.

I get an error message stating that 'CapturePreviewImage is not a member of Autodesk.AutoCAD.ApplicationServices.Document'

I have AcCoreMgd and AcDbMgd both referenced for AutoCAD 2014

I've read the documentation - specifically arxmgd.chm - and it states that CapturePreviewImage is a member of the DocumentExtension Methods (along with CloseAndDiscard, CloseAndSave amongst others!)

What am I missing here?

EDIT: This post by Gile has the answer- because I'm using VB.NET I have to include this line to access the DocumentExtension Methods:

Code - vb.net: [Select]
  1. Imports Autodesk.AutoCAD.ApplicationServices.DocumentExtension
« Last Edit: April 15, 2014, 10:25:45 AM by AlexF »

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Recreate Thumbnail for saved Drawing
« Reply #4 on: April 15, 2014, 10:51:41 AM »
A good reason to switch to C#!
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

vegbruiser

  • Guest
Re: Recreate Thumbnail for saved Drawing
« Reply #5 on: April 15, 2014, 11:28:10 AM »
A good reason to switch to C#!
Agreed. :)

For (pretty much) everything else I've ever written I have used C# - the reason I plumped for VB.NET on this occasion was that I found this post which gave me a starting point to work from.

I now (finally!) have a solution which allows me to do the following to any drawing frames (that we have prior knowledge of):
  • Capture a before image (using the newly discovered CapturePreviewImage())
  • Map & Copy attributes from old to new drawing frame
  • Capture manual (sometimes multi-line) text entries and add them to the new drawing frame - with the added option of taking close-up snapshots for later reporting.
  • Move entities (primarily MText) away from the new drawing frame.
  • Sort, Remove, Append a Change Note, Date & Issue into the new drawing frame
  • Redefine Drawing Frame based on an updated block and AttSync using .NET
  • Add crossing lines to the finished drawing frame to denote empty attributes
  • Capture an "After" image
  • read & write to & from XML documents using a strongly typed object model - which moved me away from the original source for this quite substantially. Incidentally, the XSD2Code extension from the Visual Studio Gallery proved invaluable in this area.
  • Generate a report on the whole dataset using Microsoft report viewer

Along the way I've also figured out the necessary steps for autoloading any ApplicationPlugin for AutoCAD along with the bundling and an installer for the whole bl00dy thing. If I can find the time, I plan on dumping/sharing a whole bunch of things I've discovered (and in some cases rediscovered!) along the way.

:)

Locke

  • Guest
Re: Recreate Thumbnail for saved Drawing
« Reply #6 on: April 15, 2014, 02:18:46 PM »
Keith is in the zone today.

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Recreate Thumbnail for saved Drawing
« Reply #7 on: April 15, 2014, 02:35:00 PM »
The members at this site have helped me out immensely and I cannot even begin to thank them all.  Anytime i can find an answer for someone and can help them out then I make an effort to do so.  Plus searching for answers will almost always increase my knowledge.  Now if i can just find a way to stop it from leaking out.
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

WILL HATCH

  • Bull Frog
  • Posts: 450
Re: Recreate Thumbnail for saved Drawing
« Reply #8 on: April 15, 2014, 03:02:31 PM »
^ +1

Stack overflow

vegbruiser

  • Guest
Re: Recreate Thumbnail for saved Drawing
« Reply #9 on: April 16, 2014, 09:52:56 AM »
I've spent a bit of time this morning tweaking the report I generate from the XML output and I noticed that in some cases where the drawing frame was A4 before, and A3 after, that the CapturePreviewImage method hasn't updated the extents of the drawing- is a simple regen all that is needed to accomplish this?

vegbruiser

  • Guest
Re: Recreate Thumbnail for saved Drawing
« Reply #10 on: April 16, 2014, 06:37:55 PM »
It turns out the CapturePreviewImage() function merely captures the area defined by the (since PaperSpace is the only area I've used it) current Paperspace extents - by that I mean it captures an image of the sheet that would be plotted- if (as I did) you change the drawing frame from A4 to A3 for instance you also need to change the page setup to the new sheet size - a simple editor.regen() doesn't work.