Author Topic: move attrib lisp modification  (Read 2522 times)

0 Members and 1 Guest are viewing this topic.

Least

  • Guest
move attrib lisp modification
« 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
« Last Edit: February 08, 2008, 12:28:08 PM by CAB »

VovKa

  • Water Moccasin
  • Posts: 1626
  • Ukraine
Re: move attrib lisp modification
« Reply #1 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)
)
« Last Edit: February 08, 2008, 01:03:34 PM by VovKa »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: move attrib lisp modification
« Reply #2 on: February 08, 2008, 12:29:04 PM »
Thanks, link updated.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Least

  • Guest
Re: move attrib lisp modification
« Reply #3 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

VovKa

  • Water Moccasin
  • Posts: 1626
  • Ukraine
Re: move attrib lisp modification
« Reply #4 on: February 08, 2008, 01:04:19 PM »
my previous post updated to suit your needs :)

daron

  • Guest
Re: move attrib lisp modification
« Reply #5 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.

Least

  • Guest
Re: move attrib lisp modification
« Reply #6 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.  :-)


Pad

  • Bull Frog
  • Posts: 342
Re: move attrib lisp modification
« Reply #7 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)
)