Author Topic: Move selected attribute by distance  (Read 2642 times)

0 Members and 1 Guest are viewing this topic.

Pad

  • Bull Frog
  • Posts: 342
Move selected attribute by distance
« on: June 14, 2011, 09:35:51 AM »
Hello
I have been trying to modify this terrific lisp by Vovka so that the selected attribute is moved by a set distance.
The reason is to 'stack' the attributes when some of the other block attribute values are missing.
I wish to move the selected attributes -0.442 in the Y axis.

this is the lisp:
Code: [Select]
; Vovka http://www.theswamp.org/index.php?topic=21303.0


(defun C:MOVEATTXT (/ CE OS Ent EntProps LastPoint LastEnt *error*)
  (defun *error* (msg)
    (if OS
      (setvar 'OSMODE OS)
    )
    (if CE
      (setvar 'CMDECHO CE)
    )
    (if LastEnt
      (entdel LastEnt)
    )
    (vl-cmdf "._UNDO" "_END")
    (if (or (= msg "Function cancelled") (= msg "quit / exit abort"))
      (princ)
      (princ (strcat "\nError: " msg))
    )
  )
  (setq OS (getvar 'OSMODE)
CE (getvar 'CMDECHO)
  )
  (vl-cmdf "._UNDO" "_BEGIN")
  (setvar 'CMDECHO 0)
  (setvar 'OSMODE 0)
  (if
    (and
      (progn (while (not (and (setq Ent (nentsel "\nSelect an attribute/text: "))
      (= (length Ent) 2)
      (wcmatch (cdr (assoc 0 (setq EntProps (entget (car Ent)))))
       "ATTRIB,TEXT"
      )
)
    )
     )
     Ent
      )
      (= (cdr (assoc 0 EntProps)) "ATTRIB")
      (setq LastPoint (cadr Ent)
    LastEnt   (entmakex
(cons
  (cons 0 "TEXT")
  (subst
    (cons 73 (cdr (assoc 74 EntProps)))
    (assoc 74 EntProps)
    (subst
      (cons
10
(cdr
  (assoc
    (if
      (= 0 (cdr (assoc 72 EntProps)) (cdr (assoc 74 EntProps)))
       10
       11
    )
    EntProps
  )
)
      )
      (assoc 10 EntProps)
      (vl-remove-if
(function (lambda (g)
    (vl-position (car g) '(-1 0 2 5 70 73 100 280 330))
  )
)
EntProps
      )
    )
  )
)
      )
      )
    )
     (progn
       (setvar "LASTPOINT" LastPoint)
       (command "._MOVE" LastEnt "" (cadr Ent) PAUSE)
       (if (not (equal LastPoint (getvar "LASTPOINT")))
(progn (entmod
  (subst (assoc 11 (entget LastEnt))
(assoc 11 EntProps)
(subst (assoc 10 (entget LastEnt)) (assoc 10 EntProps) EntProps)
  )
)
(entupd (car Ent))
)
       )
       (entdel LastEnt)
     )
     (command "._MOVE" (car Ent) "" (cadr Ent) PAUSE)
  )
  (setvar 'OSMODE OS)
  (setvar 'CMDECHO CE)
  (vl-cmdf "._UNDO" "_END")
  (princ)
)


I hoped that changing these lines
       (command "._MOVE" LastEnt "" (cadr Ent) PAUSE)
&
     (command "._MOVE" (car Ent) "" (cadr Ent) PAUSE)

to something like:
 (command "._MOVE" (car Ent) "b" "0,0" "0,-0.442")

would do it, but it doesn't so I am a bit lost now.
Any help would be appreciated.
Thanks
P


ronjonp

  • Needs a day job
  • Posts: 7531
Re: Move selected attribute by distance
« Reply #1 on: June 14, 2011, 12:39:39 PM »
Give this a try:

Code: [Select]
; Vovka http://www.theswamp.org/index.php?topic=21303.0


(defun c:moveattxt (/ mvpt ce os ent entprops lastpoint lastent *error*)
  (defun *error* (msg)
    (if os
      (setvar 'osmode os)
    )
    (if ce
      (setvar 'cmdecho ce)
    )
    (if lastent
      (entdel lastent)
    )
    (vl-cmdf "._UNDO" "_END")
    (if (or (= msg "Function cancelled") (= msg "quit / exit abort"))
      (princ)
      (princ (strcat "\nError: " msg))
    )
  )
  (setq os (getvar 'osmode)
ce (getvar 'cmdecho)
  )
  (vl-cmdf "._UNDO" "_BEGIN")
  (setvar 'cmdecho 0)
  (setvar 'osmode 0)
  (if
    (and
      (progn
(while (not (and (setq ent (nentsel "\nSelect an attribute/text: "))
(= (length ent) 2)
(wcmatch (cdr (assoc 0 (setq entprops (entget (car ent))))) "ATTRIB,TEXT")
(setq mvpt (cadr ent)
       mvpt (list (car mvpt) (+ -0.442 (cadr mvpt)) (caddr mvpt))
)
    )
       )
)
ent
      )
      (= (cdr (assoc 0 entprops)) "ATTRIB")
      (setq lastpoint (cadr ent)
    lastent   (entmakex
(cons
  (cons 0 "TEXT")
  (subst
    (cons 73 (cdr (assoc 74 entprops)))
    (assoc 74 entprops)
    (subst
      (cons
10
(cdr (assoc (if (= 0 (cdr (assoc 72 entprops)) (cdr (assoc 74 entprops)))
      10
      11
    )
    entprops
     )
)
      )
      (assoc 10 entprops)
      (vl-remove-if
(function (lambda (g) (vl-position (car g) '(-1 0 2 5 70 73 100 280 330)))
)
entprops
      )
    )
  )
)
      )
      )
    )
     (progn (setvar "LASTPOINT" lastpoint)
    (command "._MOVE" lastent "" (cadr ent) mvpt)
    (if (not (equal lastpoint (getvar "LASTPOINT")))
      (progn (entmod (subst (assoc 11 (entget lastent))
    (assoc 11 entprops)
    (subst (assoc 10 (entget lastent)) (assoc 10 entprops) entprops)
     )
     )
     (entupd (car ent))
      )
    )
    (entdel lastent)
     )
     (command "._MOVE" (car ent) "" (cadr ent) mvpt)
  )
  (setvar 'osmode os)
  (setvar 'cmdecho ce)
  (vl-cmdf "._UNDO" "_END")
  (princ)
)
;;(nentsel)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Pad

  • Bull Frog
  • Posts: 342
Re: Move selected attribute by distance
« Reply #2 on: June 14, 2011, 01:39:29 PM »
Thats perfect.  It wasn't as straightforward as I thought.
Thank you very much Ron.

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Move selected attribute by distance
« Reply #3 on: June 14, 2011, 04:34:39 PM »
Thats perfect.  It wasn't as straightforward as I thought.
Thank you very much Ron.


 :-) You're welcome.

You could use something like this as well to shorten it up:
Code: [Select]
(defun c:moveatt (/ ent mvpt pt)
  (vl-load-com)
  (if (and (setq ent (nentsel "\nSelect an attribute/text: "))
   (wcmatch (cdr (assoc 0 (entget (car ent)))) "ATTRIB,TEXT")
   (setq pt (cadr ent))
   (setq mvpt (list (car pt) (- (cadr pt) 0.442) (caddr pt)))
      )
    (vlax-invoke (vlax-ename->vla-object (car ent)) 'move (cadr ent) mvpt)
  )
  (princ)
)
« Last Edit: June 14, 2011, 04:52:21 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Pad

  • Bull Frog
  • Posts: 342
Re: Move selected attribute by distance
« Reply #4 on: June 14, 2011, 05:35:57 PM »
wow that's quite a bit shorter
Cheers

Lee Mac

  • Seagull
  • Posts: 12922
  • London, England
Re: Move selected attribute by distance
« Reply #5 on: June 14, 2011, 05:49:54 PM »
Or maybe slightly shorter still...  :-P

Code: [Select]
(defun c:moveatt ( / e ) (vl-load-com)
  (if (and (setq e  (car (nentsel "\nSelect an attribute/text: ")))
           (wcmatch (cdr (assoc 0 (entget e))) "ATTRIB,TEXT"))
    (vlax-invoke (vlax-ename->vla-object e) 'move '(0. 0. 0.) '(0. -0.442 0.))
  )
  (princ)
)

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Move selected attribute by distance
« Reply #6 on: June 15, 2011, 10:38:05 AM »
And even shorter :P

Code: [Select]
(defun c:moveatt (/ e)
  (vl-load-com)
  (and (setq e (car (nentsel "\nSelect an attribute/text: ")))
       (wcmatch (cdr (assoc 0 (entget e))) "ATTRIB,TEXT")
       (vlax-invoke (vlax-ename->vla-object e) 'move '(0. 0. 0.) '(0. -0.442 0.))
  )
  (princ)
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Move selected attribute by distance
« Reply #7 on: June 15, 2011, 10:52:02 AM »
Or maybe slightly shorter still...  :-P
And even shorter :P
Funny if taken out of context.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Move selected attribute by distance
« Reply #8 on: June 15, 2011, 11:04:24 AM »
No grip edit if the attribute position is locked  :-D

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Move selected attribute by distance
« Reply #9 on: June 15, 2011, 11:05:59 AM »
No grip edit if the attribute position is locked  :-D
party pooper  :-P
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Pad

  • Bull Frog
  • Posts: 342
Re: Move selected attribute by distance
« Reply #10 on: June 15, 2011, 04:47:42 PM »
thanks guys.
The grip edit way is the way I was doing it before, after a few it becomes a bit tedious.
 :-)

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Move selected attribute by distance
« Reply #11 on: June 15, 2011, 04:50:13 PM »
thanks guys.
The grip edit way is the way I was doing it before, after a few it becomes a bit tedious.
 :-)
I'm sure it is. If this was something I had to do on a regular basis, I'd code it too.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox