Author Topic: Move block's Insertion Point  (Read 1554 times)

0 Members and 1 Guest are viewing this topic.

GDF

  • Water Moccasin
  • Posts: 2081
Move block's Insertion Point
« 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.  
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

tombu

  • Bull Frog
  • Posts: 288
  • ByLayer=>Not0
Re: Move block's Insertion Point
« Reply #1 on: May 06, 2020, 11:32:09 AM »
Tom Beauford P.S.M.
Leon County FL Public Works - Windows 7 64 bit AutoCAD Civil 3D

GDF

  • Water Moccasin
  • Posts: 2081
Re: Move block's Insertion Point
« Reply #2 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.
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Move block's Insertion Point
« Reply #3 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. )
  • Include the entity type (INSERT) in the selection set filter list.
  • Check for the existence of a selection set before doing anything.
  • Only obtain the selection set once.
  • Since you are using the MOVE command, only operate on objects in the current layout/viewport.
  • Transform the insertion point to be relative to the active UCS when using points in a command call.
  • Only change CMDECHO if a selection set exists.
You could of course abandon the MOVE command and use entmod or vla-put-insertionpoint.

This all assumes that your block is non-dynamic.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Move block's Insertion Point
« Reply #4 on: May 06, 2020, 02:50:34 PM »
Thanks Lee
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64