nano Posted April 12, 2020 Posted April 12, 2020 Hello I would like to know if it is possible having texts that are relative coordinates with their corresponding prefix E: and N :, select those texts, identify the numerical values and perform the operations to transform them into absolute ones, giving the angle of rotation that would be from point 0 , 0, and the displacement distances and replace the original texts, I have managed to make an application that inserts the values in a leader, but I wanted to do the above but it is beyond my knowledge. I attach the application that I have made and a drawing with what I would like to achievesorry for my English Cheers coordinates_transf.dwg desplaz_coordenada.lsp Quote
Jonathan Handojo Posted April 13, 2020 Posted April 13, 2020 10 hours ago, nano said: having texts that are relative coordinates with their corresponding prefix E: and N :, select those texts I'm still failing to understand this. Which text exactly? Relative to what? I'm still not quite sure what those values in the "initial" text represent. And the "result" coordinates is not even close in comparison to the actual coordinates in AutoCAD. Quote
nano Posted April 13, 2020 Author Posted April 13, 2020 Hi, thanks for answering, the initial texts indicate relative coordinates, but from a schematic point, specifically from an isometric drawing, not real they are simply informative, and what I wanted is that numerical value to apply the transformation to absolute coordinates Thanks Quote
Jonathan Handojo Posted April 13, 2020 Posted April 13, 2020 I'm still not understanding a few things... From the looks of things, they appear to be surveying points. Why is the value in your LISP command set to a fixed value? What angle are you talking about? So the E:value indicates the number of units offset from the "schematic point" in the x-axis, and the N:value in the y-axis? By absolute, you mean AutoCAD's coordinate values, or a value that you simply provide as a reference to an absolute coordinate? If you can maybe explain it a bit better in detail (I know English is not your first language), then I'll be able to help you out. Posting a detailed example of what you want to achieve will help me evaluate a bit better Quote
nano Posted April 13, 2020 Author Posted April 13, 2020 Hello againcoordinates_transf.dwg, Jeje i am sorry. The Points E: and N: are the X and Y coordinates. Absolute value i mean coordinate UTM (or WCS) They are coordinates of points in an isometric drawing. The lisp that I did was so that from a real point in relative coordinates (or UCS personal), I put the real coordinates (WCS). But in this case what I would like is that a series of texts that represent X and Y coordinates, but in relative values, will perform a transformation operation, given the angle, and the displacement in X and Y. That in the lisp that I made those values are: Angle: 35º with base point 0,0 X (H) 676083590 Y (K) 2388293870 But they could be changed. What I had thought was, that when applying the lisp, it would read the values that contain E: and N: and identify them as X and Y coordinates respectively, and apply the transformation to the numerical value, and substitute that value The problem is that I don't know how to extract the values and then apply the formula to them and then substitute them. The transformation formula I have applied in the lisp, but I attach an excel with the values. Maybe it's a little complicated hehe Thanks COORDENADAS DESPLAZAMIENTO - copia.xlsx Quote
Jonathan Handojo Posted April 13, 2020 Posted April 13, 2020 (edited) Took me a while to understand it... I believe I'm interpreting this right based on your example: I thought the base angle was 0,0 in terms of WCS, but it's to the original point Edited April 13, 2020 by Jonathan Handojo Quote
Jonathan Handojo Posted April 13, 2020 Posted April 13, 2020 5 minutes ago, nano said: Hello, it's more like that So where is x" and y"? It looks similar to how I sketched it Quote
nano Posted April 13, 2020 Author Posted April 13, 2020 Yes, the x and y coordinates are exactly where you indicate, but what you have set as the original point would be 0.0 Quote
Jonathan Handojo Posted April 13, 2020 Posted April 13, 2020 It won't yield the result you pointed out in Excel. The one I sketched is literally drawn to scale. If the original point was at 0,0 the new point yielded will be way too far from the result in your Excel. In any case, after many thinking and evaluation, I've come up with a solution for you: (defun c:yourcommand ( / ang angoff dist eastlabel newpoint newval northlabel orgpoint srche srchn txt txtlab vale valescale valn valnscale x y) (setq eastlabel "E:" northlabel "N:" orgpoint (progn (initget 1) (getpoint "\nSpecify absolute original point (Use hashtag \"#\" to determine absolute coordinate): ")) ) ;; Get values for "E:" and "N:" (while (progn (setq txtlab (entsel "\nSelect text with relative coordinates: ")) (cond ((null txtlab) (princ "\nNothing selected")) ((null (wcmatch (cdr (assoc 0 (entget (car txtlab)))) "TEXT,MTEXT")) (princ "\nObject selected is not text")) ((null (and (setq srche (vl-string-search eastlabel (setq txt (cdr (assoc 1 (entget (car txtlab))))))) (setq srchn (vl-string-search northlabel txt)) ) ) (princ (strcat "\nText \"" eastlabel "\" and \"" northlabel "\" not found")) ) (T (setq vale (atof (substr txt (+ srche (strlen eastlabel) 1))) valn (atof (substr txt (+ srchn (strlen northlabel) 1))) ) nil ) ) ) ) ;; Get angle: (initget 1) (setq angoff (getangle "\nSpecify angle translation: ")) ;; Calculations (setq ang (angle '(0 0) (list vale valn)) dist (distance '(0 0) (list vale valn)) newpoint (polar '(0 0) (+ angoff ang) dist) newval (mapcar '+ orgpoint newpoint) ) ;; Replace text (mapcar '(lambda (x y) (setq txt (vl-string-subst (rtos x) (rtos y) txt)) ) newval (list vale valn) ) (entmod (subst (cons 1 txt) (assoc 1 (entget (car txtlab))) (entget (car txtlab)) ) ) (princ) ) Make sure that the units for the coordinates and displacement are the same, else the result will be wrong Quote
nano Posted April 13, 2020 Author Posted April 13, 2020 Thank you, you are very kind, I have tried it and it does not make the substitution of the texts, after introducing the angle it does nothing, but I think that with your work I will try to do something.Thank you very much again Quote
nano Posted April 13, 2020 Author Posted April 13, 2020 (edited) Sorry, I have tried another dwg and change it perfectly, it must be a variable problemThank you very much Edited April 13, 2020 by nano Quote
Jonathan Handojo Posted April 13, 2020 Posted April 13, 2020 (edited) Apologies, it must be due to the effect of dimzin, text may be playing a bit wrong. Also, ensure your text is not in a locked layer. Here's an updated one with the help of Lee's Parse Numbers function that I tweaked a little bit. I hope the calculations are right: (defun c:yourcommand (/ ang angoff dist eastlabel newpoint newval northlabel orgpoint srche srchn txt txtlab vale valescale valetxt valn valnscale valntxt x y) (setq eastlabel "E:" northlabel "N:" orgpoint (progn (initget 1) (getpoint "\nSpecify absolute original point (Use hashtag \"#\" to determine absolute coordinate): ")) ) ;; Get values for "E:" and "N:" (while (progn (setq txtlab (entsel "\nSelect text with relative coordinates: ")) (cond ((null txtlab) (princ "\nNothing selected")) ((null (wcmatch (cdr (assoc 0 (entget (car txtlab)))) "TEXT,MTEXT")) (princ "\nObject selected is not text")) ((null (and (setq srche (vl-string-search eastlabel (setq txt (cdr (assoc 1 (entget (car txtlab))))))) (setq srchn (vl-string-search northlabel txt)) ) ) (princ (strcat "\nText \"" eastlabel "\" and \"" northlabel "\" not found")) ) (T (setq valetxt (car (LM-JH:parsenumbers->str (substr txt (+ srche (strlen eastlabel) 1)))) vale (atof valetxt) valntxt (car (LM-JH:parsenumbers->str (substr txt (+ srchn (strlen northlabel) 1)))) valn (atof valntxt) ) nil ) ) ) ) ;; Get angle: (initget 1) (setq angoff (getangle "\nSpecify angle translation: ")) ;; Calculations (setq ang (angle '(0 0) (list vale valn)) dist (distance '(0 0) (list vale valn)) newpoint (polar '(0 0) (+ angoff ang) dist) newval (mapcar '+ orgpoint newpoint) ) ;; Replace text (mapcar '(lambda (x y) (setq txt (vl-string-subst (rtos x) y txt)) ) newval (list valetxt valntxt) ) (entmod (subst (cons 1 txt) (assoc 1 (entget (car txtlab))) (entget (car txtlab)) ) ) (princ) ) ;; LM-JH:parsenumbers->str --> Jonathan Handojo (Reference: Lee Mac (Parse Numbers)) ;; Parses a list of numbers from a string, returning the list in strings instead of numbers. ;; To account for effects of dimzin as a result of atof, find and replace numbers in text. ;; Original: (LM:parsenumbers "-5.56345678436ty8.2t6.") --> (-5.56346 8.2 6) depending on dimzin ;; This code is originally from Lee Mac, tweaked a few lines to adjust. (defun LM-JH:parsenumbers->str (str) ((lambda (x) (vl-remove "" (read (strcat "(\"" (vl-list->string (apply 'append (mapcar '(lambda (w y z / ) (cond ((or (<= 48 y 57) (and (= y 45) (<= 48 z 57) (not (<= 48 w 57))) (and (= y 46) (<= 48 w 57)) ) (list y) ) ((and (<= 48 w 57) (null (<= 48 y 57))) (list 34 32 34) ) ) ) (cons nil x) x (append (cdr x) '(nil)) ) ) ) "\")" ) ) ) ) (vl-string->list str) ) ) Edited April 13, 2020 by Jonathan Handojo Quote
nano Posted April 13, 2020 Author Posted April 13, 2020 Hello, works really well, thanksOne last question, if I wanted to search all the texts at once, should I use something similar to this?:(setq txtlab (ssget "_X" (list (cons 1 "* E: *, * N: *"))))or it would be too complicated Quote
Jonathan Handojo Posted April 13, 2020 Posted April 13, 2020 Then you should do something like this: (defun c:yourcommand ( / ang angoff dist eastlabel ent i newpoint newval northlabel orgpoint srchfilter ss txt vale valetxt valn valntxt) (setq eastlabel "E:" northlabel "N:" srchfilter ((lambda (y z) (apply 'strcat (append (list z (car y)) (mapcar '(lambda (x) (strcat z x)) (cdr y)) (list z)))) (list eastlabel northlabel) "*" ) ) (princ "\nSelect relative texts") (if (setq ss (ssget "_:L" (list (cons 1 srchfilter)))) ;; Get all texts matching *E:*N:* (progn (setq orgpoint (progn (initget 1) (getpoint "\nSpecify absolute original point (Use hashtag \"#\" to determine absolute coordinate): ")) angoff (progn (initget 1) (getangle "\nSpecify angle translation: ")) ) (repeat (setq i (sslength ss)) (setq txt (cdr (assoc 1 (entget (setq ent (ssname ss (setq i (1- i))))))) valetxt (car (LM-JH:parsenumbers->str (substr txt (+ (vl-string-search eastlabel txt) (strlen eastlabel) 1)))) vale (atof valetxt) valntxt (car (LM-JH:parsenumbers->str (substr txt (+ (vl-string-search northlabel txt) (strlen northlabel) 1)))) valn (atof valntxt) ang (angle '(0 0) (list vale valn)) dist (distance '(0 0) (list vale valn)) newpoint (polar '(0 0) (+ angoff ang) dist) newval (mapcar '+ orgpoint newpoint) ) (mapcar '(lambda (x y) (setq txt (vl-string-subst (rtos x) y txt)) ) newval (list valetxt valntxt) ) (entmod (subst (cons 1 txt) (assoc 1 (entget ent)) (entget ent) ) ) ) ) ) (princ) ) ;; LM-JH:parsenumbers->str --> Jonathan Handojo (Reference: Lee Mac (Parse Numbers)) ;; Parses a list of numbers from a string, returning the list in strings instead of numbers. ;; To account for effects of dimzin as a result of atof, find and replace numbers in text. ;; Original: (LM:parsenumbers "-5.56345678436ty8.2t6.") --> (-5.56346 8.2 6) depending on dimzin ;; This code is originally from Lee Mac, tweaked a few lines to adjust. (defun LM-JH:parsenumbers->str (str) ((lambda (x) (vl-remove "" (read (strcat "(\"" (vl-list->string (apply 'append (mapcar '(lambda (w y z / ) (cond ((or (<= 48 y 57) (and (= y 45) (<= 48 z 57) (not (<= 48 w 57))) (and (= y 46) (<= 48 w 57)) ) (list y) ) ((and (<= 48 w 57) (null (<= 48 y 57))) (list 34 32 34) ) ) ) (cons nil x) x (append (cdr x) '(nil)) ) ) ) "\")" ) ) ) ) (vl-string->list str) ) ) It's actually shorter since I can easily exclude texts on locked layers, plus texts are filtered, and I don't have to use a while loop. Quote
nano Posted April 14, 2020 Author Posted April 14, 2020 Hello, yes, perfect, thank you very much I have learned a few things to useCheers 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.