TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: GDF on May 06, 2020, 11:25:13 AM

Title: Move block's Insertion Point
Post by: GDF on May 06, 2020, 11:25:13 AM
The routine below works for me. I am wondering if there is a better way to write it.
Thanks for any tips...

Code - Auto/Visual Lisp: [Select]
  1. (defun MoveSHT_OptionsDRHorton (/ inspt cmde)
  2.   (setq cmde (getvar "cmdecho"))
  3.   (setvar "cmdecho" 0)
  4.   (setq inspt (cdr (assoc 10 (entget (ssname (ssget "_X" '((2 . "SHT_OptionsDRHorton*"))) 0)))))
  5.   (command "move" (ssget "X" '((2 . "SHT_OptionsDRHorton*"))) "" inspt "0,0")
  6.   (setvar "cmdecho" cmde)
  7.   (princ))
  8.  
  9. ;;(MoveSHT_OptionsDRHorton)
  10.  
Title: Re: Move block's Insertion Point
Post by: tombu on May 06, 2020, 11:32:09 AM
Lee Mac has a few related routines
http://www.lee-mac.com/changeblockinsertion.html
&
http://www.lee-mac.com/justifybasepoint.html
Title: Re: Move block's Insertion Point
Post by: GDF on May 06, 2020, 11:54:03 AM
Lee Mac has a few related routines
http://www.lee-mac.com/changeblockinsertion.html
&
http://www.lee-mac.com/justifybasepoint.html

Yes, I saw those routines...very nice.
But they change the base point within the block. I just want to move the block to the correct insertion point only.
Title: Re: Move block's Insertion Point
Post by: Lee Mac on May 06, 2020, 12:41:00 PM
A few minor things off the bat:

Code - Auto/Visual Lisp: [Select]
  1. (defun MoveSHT_OptionsDRHorton ( / c e s )
  2.     (if (setq s
  3.             (ssget "_X"
  4.                 (list
  5.                    '(0 . "INSERT")
  6.                    '(2 . "SHT_OptionsDRHorton*")
  7.                     (if (= 1 (getvar 'cvport))
  8.                         (cons 410 (getvar 'ctab))
  9.                        '(410 . "Model")
  10.                     )
  11.                 )
  12.             )
  13.         )
  14.         (progn
  15.             (setq c (getvar 'cmdecho)
  16.                   e (ssname s 0)
  17.             )
  18.             (setvar 'cmdecho 0)
  19.             (command "_.move" s "" (trans (cdr (assoc 10 (entget e))) e 1) "0,0")
  20.             (setvar 'cmdecho c)
  21.         )
  22.     )
  23.     (princ)
  24. )
You could of course abandon the MOVE command and use entmod or vla-put-insertionpoint.

This all assumes that your block is non-dynamic.
Title: Re: Move block's Insertion Point
Post by: GDF on May 06, 2020, 02:50:34 PM
Thanks Lee