Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Move by INS of blockname

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
Volk359
415 Views, 5 Replies

Move by INS of blockname

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?

5 REPLIES 5
Message 2 of 6
hmsilva
in reply to: Volk359

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

EESignature

Message 3 of 6
rkmcswain
in reply to: Volk359

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)
)

 

R.K. McSwain     | CADpanacea | on twitter
Message 4 of 6
hgasty1001
in reply to: Volk359

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

 

 

 

Message 5 of 6
pbejse
in reply to: Volk359

 

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.

 

@rkmcswain 

     vl-cmdf <---  prep for 2015 eh.. 🙂

Message 6 of 6
Volk359
in reply to: pbejse

Not sure what the trans function but the USC typically isn't an issue.  Not alway though, of course.  Smiley Mad

Thanks to RkMCSWAIN, that did the trick.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost