TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Least on February 08, 2008, 07:08:57 AM

Title: move attrib lisp modification
Post by: Least on February 08, 2008, 07:08:57 AM
hi
i am hoping somebody could help me modify this lisp which a kind fellow posted on this website a few months ago.
This lisp allows you to move a single attrib with 2 clicks, i'd like to modify it so that it will also move unattributed text.
I could use the move command but the reason is that often i have this lisp running so it will be a lot quicker to use this rather than cancel and start a new command.

Thanks

here is the lisp:

Code: [Select]
(defun C:MOVEATT (/ Ent EntProps LastPoint LastEnt *error*)
  (defun *error* (msg)
    (if LastEnt
      (entdel LastEnt)
    )
    (vl-cmdf "._UNDO" "_END")
    (if (or (= msg "Function cancelled") (= msg "quit / exit abort"))
      (princ)
      (princ (strcat "\nError: " msg))
    )
  )
  (setvar "CMDECHO" 0)
  (vl-cmdf "._UNDO" "_BEGIN")
  (if
    (and
      (progn (while (not
      (and (setq Ent (nentsel "\nSelect an attribute: "))
   (= (cdr (assoc 0 (setq EntProps (entget (car Ent))))) "ATTRIB")
      )
    )
     )
     Ent
      )
      (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

(setq os ( getvar "osmode")) ;;Get current osnap
(setvar "OSMODE" 0) ;;Osnaps off

       (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)
     )
  )
  (vl-cmdf "._UNDO" "_END")

(setvar "osmode" os) ;;Set Osnap back to original

  (princ)
)

Code tags added
Original posting: <I think - CAB>
http://www.theswamp.org/index.php?topic=19881.msg242230#msg242230
Title: Re: move attrib lisp modification
Post by: VovKa on February 08, 2008, 12:02:47 PM
Code: [Select]
(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)
)
Title: Re: move attrib lisp modification
Post by: CAB on February 08, 2008, 12:29:04 PM
Thanks, link updated.
Title: Re: move attrib lisp modification
Post by: Least on February 08, 2008, 12:37:44 PM
Thanks again Vovka for your lisp

I've been doing a fair bit of head scratching.
With the prevoius lisp i just slotted in:

(setq os ( getvar "osmode"))         ;;Get current osnap
(setvar "OSMODE" 0)            ;;Osnaps off

and then reset the osmode variable at the end.
(setvar "osmode" os)            ;;Set Osnap back to original

With this lisp i cannot find the correct place to put these commands.

Thanks again
Title: Re: move attrib lisp modification
Post by: VovKa on February 08, 2008, 01:04:19 PM
my previous post updated to suit your needs :)
Title: Re: move attrib lisp modification
Post by: daron on February 08, 2008, 01:05:35 PM
>>>(setq os ( getvar "osmode"))         ;;Get current osnap
Usually you gather information at the Beginning of your program.

>>>(setvar "osmode" os)            ;;Set Osnap back to original
This is usually done at the end of your program. It also can be placed in an error function.

>>>(setvar "OSMODE" 0)            ;;Osnaps off
This or any other "mode" you want it to be is placed anywhere you wish to alter these settings.
Title: Re: move attrib lisp modification
Post by: Least on February 08, 2008, 01:17:35 PM
Thanks again Vovka, you're a star.

Daron, that is how i have previously gone about it but with this lisp it resulted in a syntax error.
I'm not sure why..

Its working just how i want it now, so many thanks.  :-)

Title: Re: move attrib lisp modification
Post by: Pad on May 15, 2015, 04:59:06 AM
Hi

I have recently upgraded to 2015 and this lisp now doesn't work for attributes.
It wont let me select an attribute,  it works fine for text.  Any idea of a fix please?

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

;;; move single attribute AS

(defun c:AS nil (C:MOVEATTXT))
(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)
)