Greetings All,
I'm writing a lisp to move all objects in a drawing and would like to use the insert point of the title block as a base then move it to 0,0. Since the title block is in random areas in different drawings I can't always move from the same point A to point B. The ideal command line would be:
move all ins <blockname> 0,0
however when using an osnap AutoCAD is expecting a user input. The handle appears to be the same in all the drawings (but not always) so that could be used instead of the block name but AutoCAD won't accept either. It's been a while since I've lisped but the following is the code that I've come up with so far and I'm stuck:
(defun move_all (command "move" "all" ;;;FIND THE INSERT (setq ss (ssget "X" '((0 . "INSERT") (2 . "dsize") (66 . 1)))) (setq i (sslength ss)) "0,0") )
Attached is a sample file. Any suggestions?
Solved! Go to Solution.
Solved by rkmcswain. Go to Solution.
Perhaps something like this
(defun move_all (/ ss ss1) ;;;FIND THE INSERT (if (and (setq ss1 (ssget "X" (list '(0 . "INSERT") '(2 . "dsize") '(66 . 1) (cons 410 (getvar 'CTAB))))) (setq ss (ssget "X" (list (cons 410 (getvar 'CTAB))))) ) (command "_.move" ss "" (cdr (assoc 10 (entget (ssname ss1 0)))) "0,0") ) (princ) )
HTH
Henrique
Here is a quick and dirty way of doing it.
(defun c:foo ( / sset myblock myblockins) (setq sset (ssget "_X" '((0 . "INSERT")(2 . "SAMPLE")))) (if (eq (sslength sset) 1) (progn (setq myblock (ssname sset 0)) (setq myblockins (cdr (assoc 10 (entget myblock)))) (vl-cmdf "_move" myblock "" myblockins (list 0.0 0.0 0.0)) ) ) (princ) )
Hi,
I think you need to obtain the title block insertion point, if you have the name of the title block then this should help:
(setq tbss (ssget "w" '((0 . "INSERT)(2 . "DSIZE"))))
(if tbss
(progn
(setq tb (ssname tbss 0))
(setq tbInsPoint (cdr(assoc 10 (entget tb))))
)
)
Now in tbInsPoint you have the title block insertion point, and then you have to select the objects inside the title block maybe with a window selection, and so you can move those elements.
(setq elementsSS (ssget "w" p1 p2)); you have to obtain p1 and p2 from the extents of the title block
(if elementsSS
(command "move" elementsSS "" tbInspoint '(0 0 0))
)
Also if you are working with points you should set Osmode=0 before any operation in the drawing editor.
Gaston Nunez
Guys
Not a big deal , but i think you need to consider current UCS [though unlikely, but you'll never know]. Suggest you throw in the trans function within your codes.
vl-cmdf <--- prep for 2015 eh.. 🙂
Not sure what the trans function but the USC typically isn't an issue. Not alway though, of course.
Thanks to RkMCSWAIN, that did the trick.