pietrow Posted September 12, 2022 Share Posted September 12, 2022 Hi I'm searching for lisp that creates pline between base oint if the selected mtext and all other mtext that contain selected mtext. For example I clicked mtext "c1" and there are 3 mtext "c1-22" "c1-12" and "c2-13", so the lisp creates two pline, one "c1" - "c1-22" and second "c1" - "c1-12". Thanks in advance. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted September 12, 2022 Share Posted September 12, 2022 Try this UNTESTED program. NOTE: Be sure is that your Mtext objects are NOT formatted otherwise another approach with more functions is required to achieve that goal. (defun c:Test (/ str int sel ent get ins ) ;;----------------------------------------------------;; ;; Author : Tharwat Al Choufi ;; ;; website: https://autolispprograms.wordpress.com ;; ;;----------------------------------------------------;; (and (setq str (car (entsel "\nSelect text to search for similar content or as prefixed : "))) (or (wcmatch (cdr (assoc 0 (setq get (entget str)))) "TEXT,MTEXT") (alert "Invalid object selected. Try again") ) (or (setq ins (cdr (assoc 10 get)) int -1 sel (ssget "_X" (list '(0 . "TEXT,MTEXT") (cons 1 (strcat (cdr (assoc 01 get)) "*")) (cons 410 (getvar 'CTAB))))) (alert "Nno similar contents nor as prefixed string found <!>") ) (while (setq int (1+ int) ent (ssname sel int)) (or (equal str ent) (entmake (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") '(90 . 2) '(70 . 0) (cons 10 ins) (cons 10 (cdr (assoc 10 (entget ent)))))) ) ) ) (princ) ) 1 Quote Link to comment Share on other sites More sharing options...
pietrow Posted September 12, 2022 Author Share Posted September 12, 2022 Great I will try this later. I have a question, is it hard to edit that code to write that longer mtext in the first column and the length of the pline in the second column in the txt file or better - first column the mtext, second - the X component of the pline, third - the Y component of the pline? Quote Link to comment Share on other sites More sharing options...
Tharwat Posted September 12, 2022 Share Posted September 12, 2022 Generally speaking, its very possible so if you can give an example with a DWG then this would clarify the goal of the program and I will see if time serves then will not hesitate to help you for sure. 1 Quote Link to comment Share on other sites More sharing options...
pietrow Posted September 12, 2022 Author Share Posted September 12, 2022 Here is the dwg file and the txt file. There is an example in the dwg for mtext "C2" with magenta plines and X/Y components as dimensions - these are not particularly necessary expecially dimensions. There is information in the txt files that I need to get from other dwg files.CreatingPlines.txtCreatingPlines.dwg Quote Link to comment Share on other sites More sharing options...
Tharwat Posted September 12, 2022 Share Posted September 12, 2022 I think your magenta polylines are not that accurate since they are not connected in the center of Mtext objects nor they are connected from the insertion point of each Mtext, so is it okay to get the X and Y from the insertion point of Mtexts ? otherwise you need to specify how did you get that base point that you connected from the original text C2 to the other texts. 1 Quote Link to comment Share on other sites More sharing options...
pietrow Posted September 12, 2022 Author Share Posted September 12, 2022 It's ok to create and measure pline from the center to center. Sorry for low accuracy in the dwg, but I don't sleep for quite a long time Quote Link to comment Share on other sites More sharing options...
pietrow Posted September 13, 2022 Author Share Posted September 13, 2022 I'hve manage to finishe lisp with good results. Thank you Tharwat for your help with starting lisp. Have a nice day. 1 Quote Link to comment Share on other sites More sharing options...
Tharwat Posted September 13, 2022 Share Posted September 13, 2022 I was modifying the codes to work with the center point of Mtexts along with exporting info to text file. Try it now and let me know. (defun c:Test (/ *error* str int sel ent get ins xpo ypo pos lst txt opn dim rtn rot wid ) ;;----------------------------------------------------;; ;; Author : Tharwat Al Choufi ;; ;; website: https://autolispprograms.wordpress.com ;; ;;----------------------------------------------------;; (defun *error* (msg) (and dim (setvar 'DIMZIN dim)) (and opn (close opn)) (and msg (not (wcmatch (strcase msg) "*CANCEL*,*EXIT*,*BREAK*")) (princ (strcat "\nError =>: " msg)) ) (princ "\nThis AutoLISP program was written by Tharwat Al Choufi" ) (princ) ) (and (setq str (car (entsel "\nSelect text to search for similar content or as prefixed : " ) ) ) (or (wcmatch (cdr (assoc 0 (setq get (entget str)))) "TEXT,MTEXT" ) (alert "Invalid object selected. Try again") ) (or (setq ins (assoc 10 get) xpo (car (cdr ins)) ypo (cadr (cdr ins)) int -1 sel (ssget "_X" (list '(0 . "TEXT,MTEXT") (cons 1 (strcat (cdr (assoc 01 get)) "*")) (cons 410 (getvar 'CTAB)) ) ) ) (alert "Nno similar contents nor as prefixed string found <!>" ) ) (setq dim (getvar 'DIMZIN)) (setvar 'DIMZIN 0) (setq rot (cdr (assoc 50 get)) ins (polar (polar (cdr ins) rot (/ (cdr (assoc 42 get)) 2.0)) (- rot (* pi 0.5)) (/ (cdr (assoc 40 get)) 2.0) ) ) (while (setq int (1+ int) ent (ssname sel int) ) (or (equal str ent) (and (setq get (entget ent) pos (assoc 10 get) wid (cdr (assoc 42 get)) rot (cdr (assoc 50 get)) ) (setq cnt (polar (polar (cdr pos) rot (/ wid 2.0)) (- rot (* pi 0.5)) (/ (cdr (assoc 40 get)) 2.0) ) ) (entmake (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") '(90 . 2) '(70 . 0) (cons 10 ins) (cons 10 (setq pos (polar (polar (cdr pos) rot (/ wid 2.0)) (- rot (* pi 0.5)) (/ (cdr (assoc 40 get)) 2.0) ) ) ) ) ) (setq lst (cons (list (cdr (assoc 1 get)) (rtos (abs (- xpo (car pos))) 2 4) (rtos (abs (- ypo (cadr pos))) 2 4) ) lst ) ) ) ) ) (setq txt (getfiled "Save as." (getvar 'DWGPREFIX) "txt" 1)) (setq opn (open txt "w")) (write-line "MTEXT\tX\tY" opn) (setq lst (vl-sort lst (function (lambda (j k) (< (car j) (car k))))) ) (while (setq rtn (car lst)) (write-line (strcat (car rtn) "\t" (cadr rtn) "\t" (caddr rtn)) opn ) (setq lst (cdr lst)) ) ) (*error* nil) (princ) ) (vl-load-com) 1 Quote Link to comment Share on other sites More sharing options...
pietrow Posted September 13, 2022 Author Share Posted September 13, 2022 Wow, amazing, exactly was i asked for. Thanks a lot again. 1 Quote Link to comment Share on other sites More sharing options...
Tharwat Posted September 13, 2022 Share Posted September 13, 2022 1 minute ago, pietrow said: Wow, amazing, exactly was i asked for. Thanks a lot again. Excellent, you are most welcome. 1 Quote Link to comment Share on other sites More sharing options...
pietrow Posted December 26, 2022 Author Share Posted December 26, 2022 Hi Tharwat I try to understand your code and wonder how exactly work "or" and "and" in code above. I read some other post where you were mentioned as person who use this "style" a lot. Only thing I think I fiugred out is that, when you use "or" and several functions inside, then function are executed one by one until one function returns nil. Could you tell me more about using "or" and "and" not only for conditional tests? 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.