Brok Posted July 13, 2023 Share Posted July 13, 2023 Hi, I wrote this Lisp Script to place an arrow text next to selected texts (defun C:proj() (if (setq s (ssget)) (progn (setq i 0 n (sslength s) ) ;setq (while (< i n) (setq e (ssname s i) alignLeft (cdr (assoc 11 (entget e))) alignRight (cdr (assoc 10 (entget e))) textJust (cdr (assoc 72 (entget e))) text_length (strlen (cdr (assoc 1 (entget e)))) i (1+ i) ) ;setq (setq NEWP_L (LIST (+ (car alignLeft) 0.20) (+(cadr alignLeft) (/ text_length 2.7))) ) (setq NEWP_R (LIST (+ (car alignRight) 0.10) (-(cadr alignRight) 0.2 )) ) (setvar "CLAYER" "Layer") (if (= textJust 0) (command "_-TEXT" "i" "L" NEWP_L 0.5 0 " --> " "" "") (command "_-TEXT" "i" "R" NEWP_R 0.5 0 " <--" "" "") ) ; if ) ;while ) ;progn ) ;if (princ) ) NEWP_L and NEWP_R are the Location where the arrow should be placed depending on the Text Justification of the selected text The Insertion Point of the text with Justification Right is correct. But the with Justification Left it just uses the same point as the selected text In the Attached Screenshot, you can see Example 4 is correct and Example 3 it uses the Insert point of the Selected Text (Example 3) instead of NEWP_L I checked the Variable NEWP_L and the Coordinates are correct. The _-TEXT Command just does not seem to use it Quote Link to comment Share on other sites More sharing options...
fuccaro Posted July 13, 2023 Share Posted July 13, 2023 I can not test your program right now, but there is an AutoLisp function called TEXTBOX that returns the boundings of a text/mtext entity. Maybe that could help you? Quote Link to comment Share on other sites More sharing options...
SLW210 Posted July 13, 2023 Share Posted July 13, 2023 I get an error running the code. Quote ; error: AutoCAD variable setting rejected: "CLAYER" "Layer" Quote Link to comment Share on other sites More sharing options...
lastknownuser Posted July 13, 2023 Share Posted July 13, 2023 (edited) 1 hour ago, SLW210 said: I get an error running the code. You probably don't have layer called "Layer", I'm guessing But I don't understand what exactly should be result of this code, I can't figure out from the photo. I think you should just check text group code 72, test how its justified and then determine insertion point of arrow. Here you can see the codes: http://docs.autodesk.com/ACD/2014/ENU/index.html?url=files/GUID-62E5383D-8A14-47B4-BFC4-35824CAE8363.htm,topicNumber=d30e678406 Edit: here is some quick code, when you select text if its left justify it creates arrow on left that is right justified to point from left to text, if you choose right justified text it creates arrow from right that is justified left to point from right side to text. Depending on what you need you can modify that simple code, if I understood the problem correctly here. (setq text (car (entsel))) (setq textJust (cdr (assoc 72 (entget text)))) (cond ((= textJust 0);left (setq insertpt (cdr (assoc 10 (entget text)))) (command "_TEXT" "j" "R" insertpt 1 0 "-->") ) ((= textJust 2);right (setq insertpt (cdr (assoc 11 (entget text)))) (command "_TEXT" "j" "L" insertpt 1 0 "<--") ) );cond Edited July 13, 2023 by lastknownuser 1 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.