Mugna101 Posted December 26, 2021 Posted December 26, 2021 Hi everyone. I have a simple question to which i hope there is a simple answer. What I want to achieve: 1)select a text entity (single line text) 2)Taking its location (for placing a Mleader afterwards) I have these following lines for a code im writing (setq obj (entsel)) (setq COORD (cdr obj)) (setq COORDX (rtos (car (car COORD))2)) (setq COORDY (rtos (car (cdr (car COORD)))2)) The issue: The Coordinates i get are from where i clicked on the text and not its own location. Ex; if the text is on 0,0 and it has an area of 2x4, i might and probably will click on it somewhere in the area of 0,0 but not exactly on it and it will be the coords i get. so the coords will be like 0.3,1.2 and it doesnt help me. I want it to be the exact location of the text entity. as no matter where on the text i click, i will get the absolute coords of the text's placement. how can i achieve that? Thx in advance I dunno if it will help understand but the idea of the entire code is to select multiple texts, manipulate their strings and replace them eventualy with a Mleader. Quote
hosneyalaa Posted December 26, 2021 Posted December 26, 2021 52 minutes ago, Mugna101 said: Hi everyone. I have a simple question to which i hope there is a simple answer. What I want to achieve: 1)select a text entity (single line text) 2)Taking its location (for placing a Mleader afterwards) I have these following lines for a code im writing (setq obj (entsel)) (setq COORD (cdr obj)) (setq COORDX (rtos (car (car COORD))2)) (setq COORDY (rtos (car (cdr (car COORD)))2)) The issue: The Coordinates i get are from where i clicked on the text and not its own location. Ex; if the text is on 0,0 and it has an area of 2x4, i might and probably will click on it somewhere in the area of 0,0 but not exactly on it and it will be the coords i get. so the coords will be like 0.3,1.2 and it doesnt help me. I want it to be the exact location of the text entity. as no matter where on the text i click, i will get the absolute coords of the text's placement. how can i achieve that? Thx in advance I dunno if it will help understand but the idea of the entire code is to select multiple texts, manipulate their strings and replace them eventualy with a Mleader. Hi Have you attached an example drawing? Quote
Mugna101 Posted December 26, 2021 Author Posted December 26, 2021 10 minutes ago, hosneyalaa said: Hi Have you attached an example drawing? Heres an example test.dwg Quote
hosneyalaa Posted December 26, 2021 Posted December 26, 2021 hi try ;;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-for-text-to-multileader/td-p/6264591 (defun c:am (/ newleader pt1 pt2 ss txt x w rjp-getbbwdth) (vl-load-com) (defun rjp-getbbwdth (obj / out ll ur) (vla-getboundingbox obj 'll 'ur) (setq out (mapcar 'vlax-safearray->list (list ll ur))) (distance (car out) (list (caadr out) (cadar out))) ) (if (setq ss (ssget '((0 . "*TEXT")))) (progn (setq txt (apply 'strcat (mapcar 'cdr (vl-sort (mapcar '(lambda (x) (cons (vlax-get x 'insertionpoint) (strcat (vlax-get x 'textstring) " ") ) ) (setq ss (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))) ) ) ) (function (lambda (y1 y2) (< (cadr (car y2)) (cadr (car y1)))) ) ) ) ) w (car (vl-sort (mapcar 'rjp-getbbwdth ss) '>)) txt (apply 'strcat (mapcar 'chr (reverse (cdr (reverse (vl-string->list txt))))) ) ) (mapcar 'vla-delete ss) ) ) (if (and (setq pt1 (getpoint "\nSpecify leader arrowhead location: ")) (setq pt2 (getpoint pt1 "\nSpecify landing location: ")) ) (progn (command "._MLEADER" pt1 pt2 "") (setq newleader (vlax-ename->vla-object (entlast))) (vla-put-textstring newleader txt) (vla-put-textwidth newleader w) ) ) (princ) ) 1 Quote
Mugna101 Posted December 26, 2021 Author Posted December 26, 2021 4 minutes ago, hosneyalaa said: hi try ;;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-for-text-to-multileader/td-p/6264591 (defun c:am (/ newleader pt1 pt2 ss txt x w rjp-getbbwdth) (vl-load-com) (defun rjp-getbbwdth (obj / out ll ur) (vla-getboundingbox obj 'll 'ur) (setq out (mapcar 'vlax-safearray->list (list ll ur))) (distance (car out) (list (caadr out) (cadar out))) ) (if (setq ss (ssget '((0 . "*TEXT")))) (progn (setq txt (apply 'strcat (mapcar 'cdr (vl-sort (mapcar '(lambda (x) (cons (vlax-get x 'insertionpoint) (strcat (vlax-get x 'textstring) " ") ) ) (setq ss (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))) ) ) ) (function (lambda (y1 y2) (< (cadr (car y2)) (cadr (car y1)))) ) ) ) ) w (car (vl-sort (mapcar 'rjp-getbbwdth ss) '>)) txt (apply 'strcat (mapcar 'chr (reverse (cdr (reverse (vl-string->list txt))))) ) ) (mapcar 'vla-delete ss) ) ) (if (and (setq pt1 (getpoint "\nSpecify leader arrowhead location: ")) (setq pt2 (getpoint pt1 "\nSpecify landing location: ")) ) (progn (command "._MLEADER" pt1 pt2 "") (setq newleader (vlax-ename->vla-object (entlast))) (vla-put-textstring newleader txt) (vla-put-textwidth newleader w) ) ) (princ) ) thanks for the code, tho i dont think it is helpful to me. this code collects all the texts ive chosen and appends them to a single Mleader. Id rather have every text turn into a Mleader on its own and without me choosing leader and landing places. as the insertion point of the text will be for the arrow and the landing will be somewhere around it in a fixed angle and distance. in example in my code i made the pt1 of the mleader to be the coords i got from the text and then 2nd will be like 5 units east and north to it so i add 5 to the coords and places them as pt2. is the (vlax-get x 'insertionpoint) what im looking for? if so, how can i apply it simply into what i did? cuz i dont understand any of these stuff that comes after a "lambda" P.S. I am not allowed to upload my entire script as it contains lots of names and stuff of the company im working for. Quote
hosneyalaa Posted December 26, 2021 Posted December 26, 2021 (edited) (setq exyz (cdr (ASSOC 10 (ENTGET(car (entsel "\nSelect" )))))) (setq exyz (vlax-get (vlax-ename->vla-object (car (entsel "\nSelect" ) )) 'insertionpoint) ) Edited December 26, 2021 by hosneyalaa dd 1 Quote
hosneyalaa Posted December 26, 2021 Posted December 26, 2021 SEE (defun c:QQQnewleader ( / C EXYZ NEWLEADER PTEN PTS_SS SS_LEN ) (setq pts_ss (ssget (list (cons 0 "*TEXT")))) (setq ss_len (sslength pts_ss)) (setq c 0) (while (< c ss_len) (progn (setq pten (ssname pts_ss c)) (setq exyz (cdr (ASSOC 10 (ENTGET pten)))) (command "._MLEADER" exyz (list (+ 0.5 (car exyz)) (+ 0.2 (cadr exyz)) (caddr exyz)) "") (setq newleader (vlax-ename->vla-object (entlast))) (vla-put-textstring newleader (cdr (ASSOC 1 (ENTGET pten)))) (setq c (+ c 1)) ) ) (princ) ) 2 Quote
Mugna101 Posted December 26, 2021 Author Posted December 26, 2021 (edited) 6 minutes ago, hosneyalaa said: SEE (defun c:QQQnewleader ( / C EXYZ NEWLEADER PTEN PTS_SS SS_LEN ) (setq pts_ss (ssget (list (cons 0 "*TEXT")))) (setq ss_len (sslength pts_ss)) (setq c 0) (while (< c ss_len) (progn (setq pten (ssname pts_ss c)) (setq exyz (cdr (ASSOC 10 (ENTGET pten)))) (command "._MLEADER" exyz (list (+ 0.5 (car exyz)) (+ 0.2 (cadr exyz)) (caddr exyz)) "") (setq newleader (vlax-ename->vla-object (entlast))) (vla-put-textstring newleader (cdr (ASSOC 1 (ENTGET pten)))) (setq c (+ c 1)) ) ) (princ) ) Now this is spot on! thanks alot buddy! Edited December 26, 2021 by Mugna101 didnt write the msg 1 Quote
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.