Recent Posts

Pages: [1] 2 3 ... 10
1
.NET / Re: Previews or Thumbnails
« Last post by cmwade77 on Today at 04:50:17 PM »
I think I must be missing something here, here is the code I have:

Code - C#: [Select]
  1.  public static Bitmap? Thumbnail(this Database db)
  2.  {
  3.      try
  4.      {
  5.          Bitmap? thumbnail = db.ThumbnailBitmap;
  6.          if (thumbnail == null)
  7.          {
  8.              db.SafeSave(true);
  9.              if (thumbnail == null)
  10.              {
  11.                  return PlaceholderThumbnail();
  12.              }
  13.          }
  14.          return thumbnail;
  15.      }
  16.      catch (System.Exception ex)
  17.      {
  18.          Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage($"\nError extracting thumbnail: {ex.Message}");
  19.          return null;
  20.      }
  21.  }
  22.  
  23.  private static Bitmap PlaceholderThumbnail()
  24.  {
  25.      // Create a simple placeholder thumbnail
  26.      Bitmap thumbnail = new Bitmap(256, 256);
  27.      using (Graphics g = Graphics.FromImage(thumbnail))
  28.      {
  29.          g.Clear(Color.Gray);
  30.  
  31.          string text = "No Preview";
  32.          Font font = new Font("Arial", 24);
  33.          SizeF textSize = g.MeasureString(text, font);
  34.  
  35.          // Calculate the position to center the text
  36.          float x = (thumbnail.Width - textSize.Width) / 2;
  37.          float y = (thumbnail.Height - textSize.Height) / 2;
  38.  
  39.          g.DrawString(text, font, Brushes.White, new PointF(x, y));
  40.      }
  41.      return thumbnail;
  42.  }
  43.  
  44.  public static bool SafeSave(this Database db, bool KeepDate = false)
  45.  {
  46.      string filenameToMatch = db.Filename;
  47.  
  48.      try
  49.      {
  50.          DateTime Old = File.GetLastWriteTime(filenameToMatch);
  51.          if (!filenameToMatch.IsFileLocked())
  52.          {
  53.              db.SaveAs(filenameToMatch, true, DwgVersion.Current, null); // Overwrite the original file
  54.              return true;
  55.          }
  56.          else
  57.          {
  58.              Document activeDoc = Application.DocumentManager.MdiActiveDocument;
  59.              if (string.Equals(filenameToMatch, activeDoc.Database.Filename, StringComparison.OrdinalIgnoreCase))
  60.              {
  61.                  activeDoc.SendStringToExecute("_.qsave\n", false, false, false);
  62.                  return true;
  63.              }
  64.          }
  65.          if (KeepDate)
  66.          {
  67.              File.SetLastWriteTime(filenameToMatch, Old);
  68.          }
  69.      }
  70.      catch (Autodesk.AutoCAD.Runtime.Exception ex)
  71.      {
  72.          Application.ShowAlertDialog($"Error saving file: {ex.Message}");
  73.      }
  74.      return false;
  75.  }
  76.  
2
.NET / Re: Previews or Thumbnails
« Last post by retsameht on Today at 04:26:13 PM »
If you don't see a thumbnail in Windows, it means there is no thumbnail for the file. That can happen if you open the DWG using ReadDwgFile() and save it without using the correct overload and arguments to SaveAs():

Code: [Select]
public void SaveAs(
    string fileName,
    bool bBakAndRename,    /// Must pass true for this argument.
    DwgVersion version,
    Autodesk.AutoCAD.DatabaseServices.SecurityParameters security
);

Sheet Set Manager must be generating the thumbnail in that case.
3
AutoLISP (Vanilla / Visual) / Re: most common value in a list (mode)
« Last post by hmspe on Today at 04:17:54 PM »
The mode is the most common value in a list.  I don't recall ever hearing the term in any of my math classes, but my grandchildren know it well.

Thanks for the link. 
4
AutoLISP (Vanilla / Visual) / Re: most common value in a list (mode)
« Last post by JohnK on Today at 03:41:23 PM »
Not quite sure I understand either but it sounds like you'd want to build a "Run Length Encoding" or something of that nature (something to count the instances of each entry) to find the highest number, next highest, lowest, etc.
https://www.theswamp.org/index.php?topic=57274.0#top
5
AutoLISP (Vanilla / Visual) / Re: most common value in a list (mode)
« Last post by ribarm on Today at 03:39:02 PM »
What is mode of a list?
6
AutoLISP (Vanilla / Visual) / most common value in a list (mode)
« Last post by hmspe on Today at 03:25:26 PM »
I'm looking for a lisp function to find the mode of a list.  The list is numeric and represents distances between inserts in a drawing.  I'm having no luck finding anything useful.  Any help would be appreciated.  Online search is no help at all.
7
.NET / Re: AutoCAD2025 and loading dependency dll's
« Last post by cmwade77 on Today at 03:15:09 PM »
Most, if not all Autodesk 2025 products have moved to .NET 8.0
8
.NET / Previews or Thumbnails
« Last post by cmwade77 on Today at 02:40:45 PM »
I am trying to extract a preview or thumbnail from drawings without opening them, I have code that does well if the thumbnail is saved (i.e. it shows up in Windows Explorer), but if it isn't saved, it doesn't show up.

Yet, it sheet set manager, a preview can be shown just fine for the same drawing, so there has to be something that I am missing here. Here is my code as it stands:
Code - C#: [Select]
  1.  public static Bitmap? Thumbnail(this string drawingFilePath)
  2.  {
  3.      try
  4.      {
  5.          using (Database db = new Database(false, true))
  6.          {
  7.              db.ReadDwgFile(drawingFilePath, FileOpenMode.OpenForReadAndAllShare, true, null);
  8.              Bitmap? thumbnail = db.ThumbnailBitmap;
  9.              if (thumbnail == null)
  10.              {
  11.                  return PlaceholderThumbnail();
  12.              }
  13.              return thumbnail;
  14.          }
  15.      }
  16.      catch (System.Exception ex)
  17.      {
  18.          Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage($"\nError extracting thumbnail: {ex.Message}");
  19.          return null;
  20.      }
  21.  }

Any ideas would be greatly appreciated.
9
.NET / What’s new in C# 13
« Last post by It's Alive! on Today at 04:07:48 AM »
10
AutoLISP (Vanilla / Visual) / Re: Lisp to count text in drawing
« Last post by HOSNEYALAA on Today at 12:37:13 AM »
Can you attached example drawing

try replace

;;(setq s (ssget "_X" '((0 . "TEXT,MTEXT"))))


(setq s (ssget "_X" '((0 . "TEXT,MTEXT")(1 . "*GL1A*"))))
Pages: [1] 2 3 ... 10