Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Reply
Message 1 of 7
204squares
429 Views, 6 Replies

SUBST

Hello, I'm trying to do a simple lisp, but I'm doing something wrong

 

Idea is to select text, grab the Y value, and substitute the current text with the Y value.. Thanks

 

(DEFUN C:MOX()
(SETQ TXT (ENTSEL "\nSelect Text: "))
(SETQ TXTENT (ENTGET (CAR TXT)))
(SETQ INSPT (ASSOC 11 TXTENT))
(SETQ INSPTY (NTH 2 INSPT))
(SETQ TXTADDRESS (ASSOC 1 TXTENT))
(SETQ OLDTXT (CDR TXTADDRESS))
(SETQ INSPTXT (CONS 1 INSPTY))
(SETQ NEWENT (SUBST OLDTXT (RTOS INSPTXT) TXT))
(ENTMOD NEWENT)

Tags (1)
6 REPLIES 6
Message 2 of 7
_Tharwat
in reply to: 204squares

Have a look.

 

(defun c:Mox (/ txt get )
  (if (and (setq txt (car (entsel "\nSelect Text :")))
           (wcmatch (cdr (assoc 0 (setq get (entget txt)))) "TEXT,MTEXT")
           )
    (entmod (subst (cons 1 (rtos (cadr (cdr (assoc 10 get))))) (assoc 1 get) get))
    )
  (princ)
  )
Message 3 of 7
Kent1Cooper
in reply to: _Tharwat


_Tharwat wrote:

 

...
    (entmod (subst (cons 1 (rtos (cadr (cdr (assoc 10 get))))) (assoc 1 get) get))
...

Just a little thing -- the (c...r) functions can be nested.  You can replace

 

(cadr (cdr (assoc 10 get)))

 

with

 

(caddr (assoc 10 get))

 

BUT be aware of the quirk in Text insertion point entity data entries.  For MTEXT, (assoc 10) will always get you the insertion point [the place that Osnap INS will snap to].  For [plain] TEXT, it will get you the left end of the baseline, no matter what the justification is.  If it's Left-justified, that's what you want, but if it's any other justification, that will not be what Osnap INS would snap to.  That's (assoc 11) instead, as in the code in the first post, but you can't just use that outright unless the TEXT you use it on is never Left-justified, because if it's Left-justified, (assoc 11) will always get you 0,0,0.

 

Even if you never do this with MTEXT, you should still account for the difference in TEXT justifications.  If you want to do it with either, there should be something that uses 10 if it's MTEXT or Left-justified TEXT, and 11 if it's TEXT of any other justification.

 

Left-justified TEXT has (72 . 0) and (73 . 0) in its entity data.  For other justifications, one or both of those 72- and 73-code values will be other than 0.

Kent Cooper, AIA
Message 4 of 7
ВeekeeCZ
in reply to: 204squares

See differences... 

 

(DEFUN C:MOX( / TXT TXTENT) ;..... all as local variables
  (SETQ TXT (ENTSEL "\nSelect Text: "))
  (SETQ TXTENT (ENTGET (CAR TXT)))
  (SETQ INSPT (****OC 10 TXTENT)) ;see Kents note.
  (SETQ INSPTY (NTH 2 INSPT))
  (SETQ TXTADDRESS (ASSOC 1 TXTENT))
  (SETQ OLDTXT (CDR TXTADDRESS))
  (SETQ INSPTXT (CONS 1 (RTOS INSPTY)))
  (SETQ NEWENT (SUBST INSPTXT TXTADDRESS TXTENT)) ; (subst newitem (1 . "newText")  olditem (1 . "OldText") list  ((1 . "Text") (8. "Layer")... so on))
  (ENTMOD NEWENT)
(princ) ) ; Also, setq could be multiple... like this.. (DEFUN C:MOX() (SETQ TXT (ENTSEL "\nSelect Text: ") TXTENT (ENTGET (CAR TXT)) INSPT (ASSOC 10 TXTENT) INSPTY (NTH 2 INSPT) TXTADDRESS (ASSOC 1 TXTENT) OLDTXT (CDR TXTADDRESS) INSPTXT (CONS 1 (RTOS INSPTY)) NEWENT (SUBST INSPTXT TXTADDRESS TXTENT)) (ENTMOD NEWENT) )
Message 5 of 7
Kent1Cooper
in reply to: 204squares

The selection might as well be able to be multiple, too.  Here's a version [in simplest terms -- no error handling, etc. yet] that does that, and uses VLA Properties instead of (subst)/(entmod) with entity data [lightly tested]:

 

(vl-load-com); if needed
(defun C:TCYC (/ textss tobj); = Text [or Mtext] Content = its Y Coordinate (if (setq textss (ssget ":L" '((0 . "*TEXT")))) (repeat (setq n (sslength textss)); then (setq tobj (vlax-ename->vla-object (ssname textss (setq n (1- n))))) (vla-put-TextString tobj (rtos (cadr ; Y coordinate (vlax-get tobj (if (and (= (vla-get-ObjectName tobj) "AcDbText") (/= (vlax-get tobj 'Alignment) 0)) ; plain Text other than left-justified? 'TextAlignmentPoint ; then [= (assoc 11)] 'InsertionPoint ; else [= (assoc 10)] ); if ); vlax-get ); cadr ); rtos ); vla-put.... ); repeat ); if ); defun
Kent Cooper, AIA
Message 6 of 7
204squares
in reply to: 204squares

Awesome, thanks all

Message 7 of 7
204squares
in reply to: 204squares

 

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

Post to forums  

Autodesk Design & Make Report

”Boost