.NET

.NET

Reply
Valued Contributor
88 Posts
0 Kudos
Registered: ‎02-28-2012
Post 1 of 5

Thumbnail is not generating after saving drawing file.

342 Views, 4 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
1,467 Posts
277 Kudos
Registered: ‎04-09-2008
Post 2 of 5

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
88 Posts
0 Kudos
Registered: ‎02-28-2012
Post 3 of 5

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
1,467 Posts
277 Kudos
Registered: ‎04-09-2008
Post 4 of 5

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

New Member
1 Posts
0 Kudos
Registered: ‎07-09-2013
Post 5 of 5

Re: Thumbnail is not generating after saving drawing file.

10-28-2014 01:50 PM in reply to: Alexander.Rivilis

Hi, works for me very well in combination with db.Wblock.

I'm creating new database, zoom to extents within a transaction, and write the tumbnail as seen above after the zoom-transaction.

True uses view of current database, False uses the newly created view in the side database.

 

    public static bool Wblock(string strFile, Point3d ptPoint, ObjectIdCollection lstObj)
    {
      bool isSuc = false;
      if (lstObj.Count > 0)
      {
        Database oDbSource = lstObj[0].Database;

        try
        {
          using (Database oNewDb = new Database(true, false))
          {
            oDbSource.Wblock(oNewDb, lstObj, ptPoint, DuplicateRecordCloning.Ignore);

            TransactionHelper.RunIn(oNewDb, delegate(Transaction oTrans)
            {
              oNewDb.ZoomExtents(1.05);
            });
// nothing else then acdbMakeDrawingPreview13 CreateDrawingPreview(oNewDb, false); oNewDb.SaveAs(strFile, DwgVersion.Newest); } isSuc = true; } catch { } } return isSuc; }

 Thanks for the sample.

 

Regards, Fred

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!