Author Topic: search for exploded blocks  (Read 3165 times)

0 Members and 1 Guest are viewing this topic.

curmudgeon

  • Newt
  • Posts: 194
search for exploded blocks
« on: April 29, 2010, 02:33:49 PM »
I have a group of files which were created in R***t. They have been saved back into Autocad, and then back to release 2000. Mostly, what I want is the blocks which were the symbols. The exploded blocks which contained circles I have made code for, I can search for a circle of certain radius and then, with a little more sorting, use COND to determine what block needs to be inserted at that location. Fine.

But some of the text in the blocks exploded into line segments, and inconsistently at that. Sometimes an "H" was made of 3 segments, and sometimes 5. Which made me scratch my head.

What I think would be really cool would be to make a selection set of an example of an exploded block, and search for repetitions of that pattern.
The things I have thought of each kind of circle back on themselves, and I am left with a headache.

Any ideas would be greatly appreciated. I will be away from the keyboard for a bit - but it will be on my mind.

"His mill grinds slowly, but exceedingly dumb."
Never express yourself more clearly than you are able to think.

curmudgeon

  • Newt
  • Posts: 194
Re: search for exploded blocks
« Reply #1 on: April 30, 2010, 10:50:11 AM »
I was being silly. I was thinking in terms of geometry, and forgetting the nature of computers. NOT TESTED YET, but I bet the handles of exploded blocks are sequential. See where I am going?

<HR>

ah, yes. handles are sequential, which is a real cool tool, in this case.

now I am in need of a hexadecimal conversion.
or some distinctive cleverness which mimics a hexadecimal conversion.
« Last Edit: April 30, 2010, 11:43:45 AM by curmudgeon »
Never express yourself more clearly than you are able to think.

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: search for exploded blocks
« Reply #2 on: April 30, 2010, 06:49:24 PM »
now I am in need of a hexadecimal conversion.
or some distinctive cleverness which mimics a hexadecimal conversion.

Code: [Select]
(defun hex2dec ( str / foo ) ;; Lee Mac

  (defun foo ( l )   
    (if l (+ (* 16 (foo (cdr l)))
             (- (car l) (if (< (car l) 58) 48 55))) 0))
   
  (foo (reverse (vl-string->list (strcase str)))))

 :-)
« Last Edit: May 01, 2010, 06:49:43 AM by Lee Mac »

curmudgeon

  • Newt
  • Posts: 194
Re: search for exploded blocks
« Reply #3 on: April 30, 2010, 07:49:11 PM »
Code: [Select]
(defun hex2dec ( str / foo ) ;; Lee Mac

  (defun foo ( l / x )   
    (if l (+ (* 16 (foo (cdr l)))
             (- (car l) (if (< (car l) 58) 48 55))) 0))
   
  (foo (reverse (vl-string->list (strcase str)))))

Lee - thank you very much. That is recursive, yes?
I have never understood recursive for more than 10 seconds. But I really want to.
foo calls foo until it reaches the end of the list "l". Eloquent, I am going to try to get my head around it.
read: "comprehend"

It's later - what I have been able to find surfing is all LISP, even when it says "Autolisp", and I have to read harder. That's OK, but I don't see why you have "x" as a local variable for foo. So I took it out, and it works. But would you tell me why it was in there?

You are across the pond from me, so it is the middle of the night there, I think. I am going to write out the iterations for an example operation, and then I am going to attempt to write dec2hex.

Thanks.

roy

« Last Edit: April 30, 2010, 08:36:37 PM by curmudgeon »
Never express yourself more clearly than you are able to think.

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: search for exploded blocks
« Reply #4 on: May 01, 2010, 06:49:35 AM »
Lee - thank you very much. That is recursive, yes?
It's later - what I have been able to find surfing is all LISP, even when it says "Autolisp", and I have to read harder. That's OK, but I don't see why you have "x" as a local variable for foo. So I took it out, and it works. But would you tell me why it was in there?

Oh, apologies, that 'x' should not be there - I think it must be a remnant from when I wrote it differently  :-(

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: search for exploded blocks
« Reply #5 on: May 01, 2010, 07:19:09 AM »
I suppose the reverse might be something along these lines:

Code: [Select]
(defun dec2hex ( num / foo bar ) ;; Lee Mac

  (defun foo ( n )
    (if (< 0 (/ n 16))
      (strcat (foo (/ (- n (rem n 16)) 16)) (bar (rem n 16)))
      (bar (rem n 16))))

  (defun bar ( n ) (chr (+ n (if (< n 10) 48 55))))

  (foo num))

I'm sure it could be written better  :-(

curmudgeon

  • Newt
  • Posts: 194
Re: search for exploded blocks
« Reply #6 on: May 01, 2010, 01:01:42 PM »
Yours is much nicer than mine. I traced return values from your previous because I was having a hard time grasping it.
Sat down this morning and wrote this to compare non-recursive looping:

Code: [Select]
(defun dec2hex (n)
  (setq count 1 them (list))
  (while (> n 16)
    (setq n (/ n 16.0)
  count (1+ count)
    )
  )
  (while (> count 0)
    (setq them (append them (list (fix n)))
  n (* (- n (fix n)) 16)
  count (1- count)
    )
  )
  (vl-list->string (mapcar '(lambda (x) (+ 48 (if (< 9 x) 7 0) x )) them))
)

The lovely wife thinks I am goofing off. Maybe she is right, but I am not yet convinced of it.
I greatly appreciate your help, and I will study your second example when she's not looking.

 8-)
Never express yourself more clearly than you are able to think.

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: search for exploded blocks
« Reply #7 on: May 01, 2010, 01:28:06 PM »
Nice one :-)

Another possible way to approach it:

Code: [Select]
(defun dec2hex ( num / foo bar ) ;; Lee Mac

  (defun foo ( n )
    (if (< 16 n)
      (strcat
        (bar
          (/ n
            (setq b
              (expt 16
                (fix
                  (/ (log n) (log 16))
                )
              )
            )
          )
        )
        (foo (- n (* b (/ n b))))
      )
      (bar n)
    )
  )

  (defun bar ( n ) (chr (+ n (if (< n 10) 48 55))))

  (foo num))

VovKa

  • Water Moccasin
  • Posts: 1632
  • Ukraine
Re: search for exploded blocks
« Reply #8 on: May 01, 2010, 01:48:27 PM »
Code: [Select]
(defun vk_Dec2Hex (Dec /)
  (if (< Dec 10)
    (itoa Dec)
    (if (> Dec 15)
      (strcat (vk_Dec2Hex (/ Dec 16)) (vk_Dec2Hex (rem Dec 16)))
      (chr (+ Dec 55))
    )
  )
)

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: search for exploded blocks
« Reply #9 on: May 01, 2010, 02:09:04 PM »
awesome VovKa   8-)

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: search for exploded blocks
« Reply #10 on: May 01, 2010, 02:24:39 PM »
I suppose you could convert to and from any base  :wink:

I used your method VovKa, I hope you don't mind - it is brilliant  :-)

Code: [Select]
(defun toBase ( str from to / -> <- toChar ) ;; Lee Mac

  (defun -> ( n / b x )
    (if (<= to n)
      (strcat (-> (/ n to)) (-> (rem n to)))
      (toChar n)
    )
  )

  (defun <- ( l )
    (if l
      (+ (* from (<- (cdr l))) (car l)) 0
    )
  )

  (defun toChar ( n ) (chr (+ n (if (< n 10) 48 55))))

  (->
    (<-
      (mapcar
        (function
          (lambda ( x )
            (- x (if (< x 58) 48 55))
          )
        )
        (reverse
          (vl-string->list str)
        )
      )
    )
  )
)
 
« Last Edit: May 01, 2010, 02:29:07 PM by Lee Mac »

VovKa

  • Water Moccasin
  • Posts: 1632
  • Ukraine
Re: search for exploded blocks
« Reply #11 on: May 01, 2010, 03:21:06 PM »
I hope you don't mind - it is brilliant  :-)
of course i don't, Lee
it's always a pleasure to stand someone in good stead :)

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: search for exploded blocks
« Reply #12 on: May 01, 2010, 03:25:25 PM »
This is how it looks in my mind  :-)