danglar Posted December 6, 2018 Share Posted December 6, 2018 I find in my storage stuff (I don't know who create it) routine for Break a text object selected at the character it is selected into two text objects, with them being in the same location as they were when they were one text object. (see attached lisp) it working properly for my purposes but I want to add an option to place the "second part " of text string in a place selected by user... something like this: (defun c:tsb (/ acode actdoc idx ipt ll obj obj2 objlen objul ofs ofs2 pickdist pt rot sel str str2 textlen ur) ;; Breaks a text object selected at the character it is selected into two text objects, with them being ;; in the same location as they were when they were one text object. ;; Works with all justifications except Fit & Align (defun *error* (msg) (vla-endundomark ActDoc) (prompt (strcat "\n Error--> " msg)) ) ;--------------------------------------------------------------------- (setq ActDoc (vla-get-activedocument (vlax-get-acad-object))) (vla-endundomark ActDoc) (vla-startundomark ActDoc) (defun RTD (A) (/ (* A 180.0) pi)) ;end RTD ;degrees to radians (defun DTR (A) (* pi (/ A 180.0))) ;end defun dtr (setq TH (cdr (assoc 40 Obj))) ;(setq INSPT (cdr (assoc 10 Obj))) (if (and (setq Sel (entsel "\n Select text object to break (in the end of the character to break at): " ) ) (setq Obj (vlax-ename->vla-object (car Sel))) (= (vla-get-objectname Obj) "AcDbText") (setq Str (vla-get-textstring Obj)) (setq Rot (vla-get-rotation Obj)) (setq Pt (trans (cadr Sel) 1 0)) (vl-position (vla-get-alignment Obj) '(0 1 2 4 6 7 8 9 10 11 12 13 14)) ) (progn (setq Ipt (safearray-value (vlax-variant-value(vla-get-insertionpoint obj)))) (setq pickdist (distance Ipt pt)) (vla-put-rotation obj 0.0) (setq Ipt (safearray-value (vlax-variant-value(vla-get-insertionpoint obj)))) (setq obj2 (vlax-invoke Obj 'Copy)) (vla-getboundingbox Obj 'll 'ur) (setq ll (safearray-value ll) ur (safearray-value ur) objul (list (car ll) (cadr ur)) objlen (distance ur objul)) (setq idx (strlen str) str2 str textlen (1+ pickdist) ) (while (> textlen pickdist) (setq str (substr str 1 (setq idx (1- idx)))) (vla-put-textstring Obj str) (vla-getboundingbox Obj 'll 'ur) (setq ll (safearray-value ll) ur (safearray-value ur)) (setq textlen (distance (list (car ll) (cadr ur)) ur)) ) (setq str2 (substr str2 (1+ (strlen str)))) (vla-put-textstring obj2 str2) (vla-getboundingbox Obj2 'll 'ur) (setq ll (safearray-value ll) ur (safearray-value ur) ofs2 (- objlen (distance ll (list (car ur)(cadr ll))))) (setq Ipt1 (safearray-value (vlax-variant-value(vla-get-insertionpoint obj)))) ; (setq Ipt2 (safearray-value (vlax-variant-value(vla-get-insertionpoint obj2)))) (setq Ipt2 (getpoint "\n\nPick insertion point for 2nd text entity: Press <CR> to place below 1st text: " ) ; end of getpoint ) ; end of setq (if (not Ipt2) (setq Ipt2 (polar Pt (DTR (- Rot 90.0)) (* 1.6666 TH) ) ; end of polar ) ; end of setq ) ;end if (command "_.copy" (cdr (assoc -1 Obj)) "" Ipt1 Ipt2 ) ; end of command (vla-put-rotation obj rot) (vla-put-rotation obj2 rot) (setq acode (vla-get-alignment Obj)) (cond ((vl-position aCode '(0 6 9 12)) ; Left (vla-move obj2 (vlax-3d-point objul)(vlax-3D-point (polar objul rot ofs2))) ) ((vl-position aCode '(1 4 7 10 13)) ; Center (vla-move obj (vlax-3d-point objul)(vlax-3D-point (polar objul (+ rot pi) (distance ipt ipt1)))) (vla-move obj2 (vlax-3d-point objul)(vlax-3D-point (polar objul rot (distance ipt ipt2)))) ) ((vl-position aCode '(2 8 11 14)) ;Right (vla-move obj (vlax-3d-point objul)(vlax-3D-point (polar objul (+ rot pi) (distance ipt ipt1)))) ) ) ; end cond stmt ) (cond ((not Sel) (prompt "\n No object selected.") ) ((not Str) (prompt "\n Object selected was not a plain text object.") ) (t (prompt "\n Text object selected does not have an alignment that would work." ) ) ) ) (vla-endundomark ActDoc) (princ) ) I did some efforts to add this option to the script, but the final solution don't working properly Where I did a mistake? Text String Break - TSB-original.lsp Quote Link to comment Share on other sites More sharing options...
rlx Posted December 7, 2018 Share Posted December 7, 2018 You mix enames with vla-objects. You can't use entget on a vla-object. So you can't use (cdr (assoc ... on a vla-object one (not very sophisticated) possible way (adding to the original lisp code) : .... ) ) (move_text) ; <- *** add this line just before the vla-endundomark in the original lisp file (vla-endundomark ActDoc) (princ) ) ; add this subfunction to the end of the original lisp file (defun move_text ( / 1st_text 2nd_text input p1 p2 p3 th) (if (and sel (setq 1st_text (car sel)) (setq 2nd_text (entlast))) (progn (princ "\n\nPick point for 2nd text, return places below 1st text, exit with any other key : ") (setq input (grread)) (cond ((or (equal input '(2 13)) (= (car input) 25)); return (setq p1 (cdr (assoc 10 (entget 1st_text))) p2 (cdr (assoc 10 (entget 2nd_text))) th (cdr (assoc 40 (entget 2nd_text))) p3 (polar p1 (* pi 1.5) (* th 1.66))) (command "_move" 2nd_text "" p2 p3)) ((= (car input) 3) (command "_move" 2nd_text "" (cdr (assoc 10 (entget 2nd_text))) (cadr input))) (t (princ "\nGoodBye")) ) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
danglar Posted December 7, 2018 Author Share Posted December 7, 2018 Thank you very much rlx your suggestions are very acceptable and your post is very helpful for me Quote Link to comment Share on other sites More sharing options...
danglar Posted December 9, 2018 Author Share Posted December 9, 2018 just a little modification: (setvar "SHORTCUTMENU" 3) (move_text) (setvar "SHORTCUTMENU" 0) (vla-endundomark ActDoc) (princ) ) (defun move_text ( / 1st_text 2nd_text input p1 p2 p3 th) (if (and sel (setq 1st_text (car sel)) (setq 2nd_text (entlast))) (progn (princ "\n\nPick point for 2nd text, return places below 1st text, exit with any other key : ") (setq input (grread)) (cond ((or (equal input '(2 13)) (= (car input) 25)); return (setq p1 (cdr (assoc 10 (entget 1st_text))) p2 (cdr (assoc 10 (entget 2nd_text))) th (cdr (assoc 40 (entget 2nd_text))) p3 (polar p1 (* pi 1.5) (* th 1.66))) (command "_move" 2nd_text "" p2 p3)) ((= (car input) 3) (command "_move" 2nd_text "" p2 p3)) (t (princ "\nGoodBye")) ) ) ) (princ) ) shortcutmenu system variable changing in order to apply <ENTER> during operation.. and little modification of (move_text) subroutine Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.