tefached2809 Posted March 25, 2023 Posted March 25, 2023 hi everyone. i have someone made this lisp and i want it modified what it does: it extracts the length and width of rectangles (length as horizontal dimension width as vertical dimension) and the ref ID inside the rectangle and puts it into excel what i wanted: sometimes there are multiple ID ref inside the rectangle, i want to include all ID's on the cell (defun c:Test ( / int sel cad ent lst ref one two out csv get) (and (princ "\nSelect closed polylines with four corners : ") (setq int -1 sel (ssget '((0 . "*POLYLINE") (-4 . "<AND") (-4 . "&=") (70 . 1) (90 . 4) (-4 . "AND>")))) (or (vla-zoomextents (setq cad (vlax-get-acad-object))) t) (while (setq int (1+ int) ent (ssname sel int)) (setq lst nil) (foreach p (entget ent) (if (= (car p) 10) (setq lst (cons (cdr p) lst))) ) (and (setq ref (ssget "_CP" lst '((0 . "TEXT")))) (setq one (distance (car lst) (cadr lst)) two (distance (car lst) (last lst)) ) (if (equal (cadar lst) (cadadr lst) 1e-4) (setq len one wid two) (setq len two wid one) ) (setq out (cons (list len wid (cdr (assoc 1 (entget (ssname ref 0))))) out)) ) ) (or (vla-zoomprevious cad) t) (setq csv (getfiled "Specify file name" (getvar 'DWGPREFIX) "csv" 1)) (setq get (open csv "w")) (write-line "L,W,ID" get) (foreach itm out (write-line (strcat (rtos (car itm) 2 2) "," (rtos (cadr itm) 2 2) "," (caddr itm)) get) ) (close get) ) (princ) ) (vl-load-com) Quote
BIGAL Posted March 25, 2023 Posted March 25, 2023 (edited) You get a selection set of text, 1 or more so convert the text into a string you would use something like this then write to file (setq tstr "") (repeat (setq x (sslength ref)) (setq str (cdr (assoc 1 (entget (ssname ref (setq x (1- x))))))) (setq tstr (strcat tstr "," str)) ) Just a comment you can write direct to Excel no need to use a csv. Edited March 26, 2023 by BIGAL 1 Quote
Tharwat Posted March 26, 2023 Posted March 26, 2023 On 3/25/2023 at 10:36 AM, tefached2809 said: hi everyone. i have someone made this lisp and i want it modified Why did you remove my name from my codes ? Did you pay me to say that you had someone made this program for you ? Quote
hosneyalaa Posted March 26, 2023 Posted March 26, 2023 (edited) Hi Can you attached example drawing Looking at this https://www.cadtutor.net/forum/topic/70418-length-and-width-of-rectangles-with-id-to-excel/ Edited March 26, 2023 by hosneyalaa Quote
devitg Posted March 26, 2023 Posted March 26, 2023 On 3/25/2023 at 3:36 AM, tefached2809 said: hi everyone. i have someone made this lisp and i want it modified what it does: it extracts the length and width of rectangles (length as horizontal dimension width as vertical dimension) and the ref ID inside the rectangle and puts it into excel what i wanted: sometimes there are multiple ID ref inside the rectangle, i want to include all ID's on the cell (defun c:Test ( / int sel cad ent lst ref one two out csv get) (and (princ "\nSelect closed polylines with four corners : ") (setq int -1 sel (ssget '((0 . "*POLYLINE") (-4 . "<AND") (-4 . "&=") (70 . 1) (90 . 4) (-4 . "AND>")))) (or (vla-zoomextents (setq cad (vlax-get-acad-object))) t) (while (setq int (1+ int) ent (ssname sel int)) (setq lst nil) (foreach p (entget ent) (if (= (car p) 10) (setq lst (cons (cdr p) lst))) ) (and (setq ref (ssget "_CP" lst '((0 . "TEXT")))) (setq one (distance (car lst) (cadr lst)) two (distance (car lst) (last lst)) ) (if (equal (cadar lst) (cadadr lst) 1e-4) (setq len one wid two) (setq len two wid one) ) (setq out (cons (list len wid (cdr (assoc 1 (entget (ssname ref 0))))) out)) ) ) (or (vla-zoomprevious cad) t) (setq csv (getfiled "Specify file name" (getvar 'DWGPREFIX) "csv" 1)) (setq get (open csv "w")) (write-line "L,W,ID" get) (foreach itm out (write-line (strcat (rtos (car itm) 2 2) "," (rtos (cadr itm) 2 2) "," (caddr itm)) get) ) (close get) ) (princ) ) (vl-load-com) You ask for the same topic about 3 years ago Length and Width of Rectangles With ID to excel Quote
tefached2809 Posted April 2, 2023 Author Posted April 2, 2023 On 3/26/2023 at 1:00 PM, Tharwat said: Why did you remove my name from my codes ? Did you pay me to say that you had someone made this program for you ? sorry i lost that account and just received the code from another guy and copy paste everything. i did not pay anyone, nor i claim to make any code. i lost the account i can not remember the names of persons involved in the code creation. On 3/27/2023 at 2:27 AM, devitg said: You ask for the same topic about 3 years ago Length and Width of Rectangles With ID to excel thanks for the link! i lost that account. iirc one code there does get all text but have issues about the len and wid, but the other code gets the len and wid properly but not all text. On 3/26/2023 at 10:28 PM, hosneyalaa said: Hi Can you attached example drawing Looking at this https://www.cadtutor.net/forum/topic/70418-length-and-width-of-rectangles-with-id-to-excel/ yes that one exactly thank you Quote
tefached2809 Posted April 2, 2023 Author Posted April 2, 2023 On 3/26/2023 at 2:59 AM, BIGAL said: You get a selection set of text, 1 or more so convert the text into a string you would use something like this then write to file (setq tstr "") (repeat (setq x (sslength ref)) (setq str (cdr (assoc 1 (entget (ssname ref (setq x (1- x))))))) (setq tstr (strcat tstr "," str)) ) Just a comment you can write direct to Excel no need to use a csv. thank you so much 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.