.NET

Reply
Valued Contributor
RamanSBV
Posts: 86
Registered: ‎02-28-2012
Message 1 of 4 (280 Views)

Thumbnail is not generating after saving drawing file.

280 Views, 3 Replies
02-19-2013 03:24 AM

Hi,

 

I am facing an issue while generating the thumbnail of the drawing file.

Thumbnail is generating fine for drawing file.

Once drawing file is saved using below statement,

 

Database.SaveAs(filePath,DwgVersion.Current);

 

Thumbnail generation method is returning null as given below.

 

byte bytCnt = br.ReadByte();

if (bytCnt <= 1)    //Means bytCnt value is 1;

return null;

 

Please help me on this issue

 

Regards,

Raman

 

Moderator
Alexander.Rivilis
Posts: 1,398
Registered: ‎04-09-2008
Message 2 of 4 (277 Views)

Re: Thumbnail is not generating after saving drawing file.

02-19-2013 03:43 AM in reply to: RamanSBV

From Docs:

If the database executing the SaveAs() function is not the current database in the AutoCAD editor, then the thumbnail preview image is not saved to fileName. 

 To preserve previous thumbnail:

db.RetainOriginalThumbnailBitmap = true;
db.SaveAs (...);

 


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Valued Contributor
RamanSBV
Posts: 86
Registered: ‎02-28-2012
Message 3 of 4 (259 Views)

Re: Thumbnail is not generating after saving drawing file.

02-19-2013 05:32 AM in reply to: Alexander.Rivilis

Hi,

 

Thanks for giving your comments on this.

 

As you mentioned, I have coded as below

 

Database db = newDatabase(false, true);

db.RetainOriginalThumbnailBitmap =true;

db.ReadDwgFile(filePath, FileOpenMode.OpenForReadAndAllShare, true, "");

db.SaveAs(filePath,DwgVersion.Current);

db.Dispose();

 

But still same issue.... :smileysad:

 

Regards,

Raman

 

Moderator
Alexander.Rivilis
Posts: 1,398
Registered: ‎04-09-2008
Message 4 of 4 (245 Views)

Re: Thumbnail is not generating after saving drawing file.

02-19-2013 07:06 AM in reply to: RamanSBV

Tested with AutoCAD 2013:

static int Ver = AcAp.Application.Version.Major;
// AutoCAD 2007...2012
[DllImport("acblock.arx", CallingConvention = CallingConvention.Cdecl, EntryPoint = "acdbMakeDrawingPreview")]
extern static private Int32 acdbMakeDrawingPreview12(IntPtr db, [MarshalAs(UnmanagedType.U1)] bool bUnused);
// AutoCAD 2013...
[DllImport("acblock.crx", CallingConvention = CallingConvention.Cdecl, EntryPoint = "acdbMakeDrawingPreview")]
extern static private Int32 acdbMakeDrawingPreview13(IntPtr db, [MarshalAs(UnmanagedType.U1)] bool bUnused);
static public Int32 acdbMakeDrawingPreview(Database db, bool bUnused)
{
  return (Ver == 18) ? acdbMakeDrawingPreview12(db.UnmanagedObject, bUnused) : acdbMakeDrawingPreview13(db.UnmanagedObject, bUnused);
}

[CommandMethod("BoxView", CommandFlags.Modal)]
public static void CrossView()
{
  Autodesk.AutoCAD.Windows.OpenFileDialog dlg = new Autodesk.AutoCAD.Windows
      .OpenFileDialog("Select dwg-file:", "", "dwg", "",
      Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.AllowMultiple);
  DialogResult ds = dlg.ShowDialog();
  if (ds != DialogResult.OK) return;
  foreach (string path in dlg.GetFilenames()) {
    using (Database db = new Database(false, false)) {
      try {
        db.ReadDwgFile(path, FileOpenMode.OpenForReadAndReadShare, false, "");
        Point3d p1 = db.Extmin, p2 = db.Extmax;
        Point3d[] pts = new Point3d[4];
        pts[0] = new Point3d(p1.X, p1.Y, 0);  pts[1] = new Point3d(p1.X, p2.Y, 0);
        pts[2] = new Point3d(p2.X, p2.Y, 0);  pts[3] = new Point3d(p2.X, p1.Y, 0);

        using (BlockTableRecord btr = db.CurrentSpaceId.Open(OpenMode.ForWrite) as BlockTableRecord) {
          using (Polyline3d pl = new Polyline3d(Poly3dType.SimplePoly, new Point3dCollection(pts), true)) {
            btr.AppendEntity(pl);
          }
        }
        db.CloseInput(true);
        // acdbMakeDrawingPreview(db,true); // Making new preview
        db.RetainOriginalThumbnailBitmap = true;
        System.Drawing.Bitmap bm = db.ThumbnailBitmap;
        db.SaveAs(path, DwgVersion.Current);
      }
      catch (Autodesk.AutoCAD.Runtime.Exception ex) {
        Editor ed = Autodesk.AutoCAD.ApplicationServices.Application
                     .DocumentManager.MdiActiveDocument.Editor;
        ed.WriteMessage(ex.ToString());
      }
    }
  }
}

Preview has only previous Thumbnail, i.e. polyline is not visible in preview.
I've tried to using very old undocumented function acdbMakeDrawingPreview to make new preview but without success.




Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community