Recent Posts

Pages: [1] 2 3 ... 10
1
AutoLISP (Vanilla / Visual) / Re: most common value in a list (mode)
« Last post by JohnK on Today at 10:59:28 PM »
Sorry, no time to look at code but what happens in the following situation?

11, 11, 33, 33, 54

Should be: (11, 33)
2
AutoLISP (Vanilla / Visual) / Re: most common value in a list (mode)
« Last post by hmspe on Today at 10:31:25 PM »
I found an old function by John Uhden in the Autocad forums and modified it slightly.  I changed a couple of single character variables to meaningful names and I return a value instead of a list containing all the instances of the most common value. 

Code - Auto/Visual Lisp: [Select]
  1. (defun @mode (lst fuzz / index count item items mode)
  2.   (setq index 0
  3.         count 0
  4.   )
  5.   (repeat (length lst)
  6.     (setq item (nth index lst)
  7.           items (vl-remove-if-not '(lambda (x)(equal x item fuzz)) lst)
  8.           index (1+ index)
  9.     )
  10.     (if (> (length items) count)
  11.       (setq count (length items) mode items)
  12.     )
  13.   )
  14.   (car mode)
  15. )
  16.  

Test:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:tx ()
  2.   (setq l (list 1.0 5.6 9.3.5 6.6 3 4 8 7 6 2 1 3 5 4 56 8 45 123 545 1 235 15 35 135 1 5 6 7 8 9.3 9.3 9.3 9.3 9.3 9.3 9.3 9.3 9.3 5 1 2 2))
  3.   (print (@mode l  0.01))
  4.   (princ)
  5. )
  6.  

Returns:
9.3

Thanks for the suggestions.
3
AutoLISP (Vanilla / Visual) / Re: most common value in a list (mode)
« Last post by rayakmal on Today at 09:41:43 PM »
Welcome back, YMG.

Just use count items by Lee Mac

4
AutoLISP (Vanilla / Visual) / Re: most common value in a list (mode)
« Last post by ymg on Today at 09:30:34 PM »
From https://www.investopedia.com/terms/m/mode.asp#:~:text=The%20mode%20in%20statistics%20refers,the%20numbers%20in%20the%20set.

The Bottom Line:
In statistics, the mode is the number that occurs most often. A data set can have one or more modes. The mode is different from the mean, which is the average of the numbers in a set; it's also different from the median, which is the midpoint of a set. Finding the mode in a set of numbers can tell you which data points occur most commonly, which can be useful information when analyzing statistics.


Just use count items by Lee Mac

Code: [Select]
;; Count Items  -  Lee Mac
;; Returns a list of dotted pairs detailing the number of
;; occurrences of each item in a supplied list.

(defun LM:CountItems ( l / c x )
    (if (setq x (car l))
        (progn
            (setq c (length l)
                  l (vl-remove x (cdr l))
            )
            (cons (cons x (- c (length l))) (LM:CountItems l))
        )
    )
)

Examples:

Code: [Select]
(LM:CountItems '("A" "B" "B" "B" "C" "C" "D" "E" "E" "E" "E"))
=>  (("A" . 1) ("B" . 3) ("C" . 2) ("D" . 1) ("E" . 4))


(LM:CountItems '(1 2 3 3 3 4 5 6 6 7 8 8 8 8))
=>  ((1 . 1) (2 . 1) (3 . 3) (4 . 1) (5 . 1) (6 . 2) (7 . 1) (8 . 4))
5
.NET / Re: Previews or Thumbnails
« Last post by It's Alive! on Today at 09:25:46 PM »
One last thing, if you’re going to reuse these in a GUI. You may wish to store the images in a SQL database
In SQLite you can store them as a blob, it’s wicked fast (Boston accent)  :lmao:
I store a timestamp, name, path, and image as a blob
6
.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
7
.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.
8
.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   
9
.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
10
.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
Pages: [1] 2 3 ... 10