Recent Posts

Pages: [1] 2 3 ... 10
1
.NET / Re: Previews or Thumbnails
« Last post by It's Alive! on Today at 09:18:40 PM »
Here a version in Python if your feeling adventurous  :mrgreen:
https://www.theswamp.org/index.php?topic=59527.msg621035#msg621035
2
.NET / Re: Previews or Thumbnails
« Last post by It's Alive! on Today at 09:06:35 PM »
It’s not a trivial task, but you could try to unpack the .NET BlockView sample.
From there you can grab View.GetSnapShot, which returns a bitmap.
3
.NET / Re: Previews or Thumbnails
« Last post by It's Alive! on Today at 09:01:13 PM »
Code - C#: [Select]
  1. using (Database db = new Database(false, true))
Is opening the drawing, so we have some ambiguity on this definition.

If we are good with opening the db, you would pass in the objectid that represents the block table record for the space
Either modelspace or paperspace   
4
.NET / Re: Previews or Thumbnails
« Last post by cmwade77 on Today at 08:35:20 PM »
How do I do that without opening the drawing and I want it in paperspace for specific layouts? Please keep in mind I am still very new to .NET
5
.NET / Re: Previews or Thumbnails
« Last post by It's Alive! on Today at 08:32:59 PM »
Isn’t there a function CMLContentSearchPreviews.GetBlockTRThumbnail(btr);
Just pass in model space
6
.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.  
7
.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.
8
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. 
9
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
10
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?
Pages: [1] 2 3 ... 10