Author Topic: insert of last block not correct  (Read 1342 times)

0 Members and 1 Guest are viewing this topic.

andrew_nao

  • Guest
insert of last block not correct
« on: July 30, 2014, 02:19:54 PM »
i attached a sample dwg of my BOM with multiple blocks of the same name.

im trying to find the insert point of the last block inserted.
here is the code im using
Code: [Select]
(setq elist (entget (ssname (ssget "x" (list '(0 . "INSERT") '(2 . "bmline2"))) 0)))
(setq ip (cdr (assoc 10 elist)))
(setq INP (list (+ (car ip))(+ (cadr ip))))

i noted in the dwg the insert point its giving me as the last block insert point but thats incorrect.
would anyone know why is pointing to the wrong block?

thanks

kpblc

  • Bull Frog
  • Posts: 396
Re: insert of last block not correct
« Reply #1 on: July 31, 2014, 01:42:24 AM »
Perhaps this code can help you:
Code: [Select]
(defun _kpblc-conv-string-hex-to-dec (hexstr / n i a s)
                                     ;|
*    http://www.autocad.ru/cgi-bin/f1/board.cgi?t=29431LT
|;

  (setq n 0.0
        i 0
        ) ;_ end of setq
  (setq hexstr (strcase hexstr))
  (while (> (strlen hexstr) 0)
    (setq s (substr hexstr (strlen hexstr) 1)
          a (ascii s)
          ) ;_ end of setq
    (cond
      ((<= (ascii "0") a (ascii "9")) (setq a (- a (ascii "0"))))
      ((<= (ascii "A") a (ascii "F")) (setq a (+ 10. (- a (ascii "A")))))
      ) ;_ end of cond
    (setq n (+ n (* a (expt 16. i)))
          i (1+ i)
          ) ;_ end of setq
    (setq hexstr (substr hexstr 1 (1- (strlen hexstr))))
    ) ;_ end of while
  n
  ) ;_ end of defun

(defun tt (/ selset)
  (if (setq selset (ssget "_X" '((0 . "INSERT"))))
    (car (vl-sort
           ((lambda (/ tab item)
              (repeat (setq tab  nil
                            item (sslength selset)
                            ) ;_ end setq
                (setq tab (cons (ssname selset (setq item (1- item))) tab))
                ) ;_ end of repeat
              tab
              ) ;_ end of LAMBDA
            )
           (function
             (lambda (a b)
               (> (_kpblc-conv-string-hex-to-dec (cdr (assoc 5 (entget a))))
                  (_kpblc-conv-string-hex-to-dec (cdr (assoc 5 (entget b))))
                  ) ;_ end of <
               ) ;_ end of lambda
             ) ;_ end of function
           ) ;_ end of vl-sort
         ) ;_ end of vl-sort
    ) ;_ end of if
  ) ;_ end of defun
To get last inserted block call (tt) function.
Sorry for my English.