Leaderboard
Popular Content
Showing content with the highest reputation on 04/03/2025 in all areas
-
Hi @leo321, I'v been played with this and made: ; ************************************************************************************* ; Functions : TXTBL ; Subfunctions : - ; Description : Put the TEXT or MTEXT values into the tabel in model space ; Author : SAXLLE ; Date : April 03, 2025 ; ************************************************************************************* (prompt "\nTo run a LISP type: TXTBL") (princ) (defun c:TXTBL ( / header first_column second_column ent ptlist len i pt_num pt_num_lst def_len len_pt_num_lst output_vertex output_text_val dist ang npt_one angn npt_second ss ssn len_ss j dist_pos_ent_name_lst n ent_ssn ptlist_ssn ss_new text_val_pos dist_pos dist_pos_ent_name dist_pos_ent_name_lst vertex text_val acadObj doc pt numRows numColumns rowHeight colWidth txtHeightHeader txtHeightColumns row col modelSpace myTable) (setq header "SEGEMENT" first_column "VERTEX" second_column "SIDE" ) (prompt "\nSelect the GREEN Polyline:") (setq ent (ssget '((0 . "LINE,LWPOLYLINE") (8 . "LIXO") (62 . 3)))) (setq ptlist (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (ssname ent 0)))) len (length ptlist) i 1 ) (foreach n ptlist (setq pt_num (cons i n) pt_num_lst (cons pt_num pt_num_lst) ) (setq i (1+ i)) ) (setq pt_num_lst (reverse pt_num_lst)) (setq def_len 250 len_pt_num_lst (length pt_num_lst) i 0 output_vertex (list) output_text_val (list) ) (while (< i len_pt_num_lst) ;; start main if (if (not (equal (1+ i) len_pt_num_lst)) ;; start main progn (progn (setq dist (/ (distance (cdr (nth i pt_num_lst)) (cdr (nth (1+ i) pt_num_lst))) 2) ang (angle (cdr (nth i pt_num_lst)) (cdr (nth (1+ i) pt_num_lst))) npt_one (polar (cdr (nth i pt_num_lst)) ang dist) angn (+ ang (/ pi 2)) npt_second (polar npt_one angn def_len) ) (setq ss (ssget "_F" (list npt_one npt_second) '((0 . "TEXT,MTEXT") (8 . "LOTE")))) ;; start cond (cond ;; 1. cond ((equal ss nil) (setq ssn (ssget "_F" (list npt_one npt_second) '((0 . "LWPOLYLINE") (8 . "LOTE"))) len_ss (sslength ssn) j 0 dist_pos_ent_name_lst (list) n (1- len_ss) ) (repeat len_ss ;; start if (if (not (equal n -1)) ;; start progn (progn (setq ent_ssn (entget (ssname ssn n)) ptlist_ssn (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) ent_ssn)) ss_new (ssget "_WP" ptlist_ssn '((0 . "TEXT,MTEXT") (8 . "LOTE"))) text_val_pos (cdr (assoc 10 (entget (ssname ss_new j)))) dist_pos (distance npt_one text_val_pos) dist_pos_ent_name (list dist_pos (ssname ss_new j)) dist_pos_ent_name_lst (cons dist_pos_ent_name dist_pos_ent_name_lst) n (1- n) ) ) ;; end progn ) ;; end if ) ;; end repeat (setq dist_pos_ent_name_lst (vl-sort dist_pos_ent_name_lst (function (lambda (x1 x2) (< (car x1) (car x2)))))) ;; Sorting list from MIN to MAX Distance with entity (if (and (< (1+ i) 10) (< (+ i 2) 10)) (setq vertex (strcat "0" (itoa (1+ i)) " - " "0" (itoa (+ i 2))) text_val (cdr (assoc 1 (entget (car (cdr (nth j dist_pos_ent_name_lst)))))) output_vertex (cons vertex output_vertex) output_text_val (cons text_val output_text_val) ) (setq vertex (strcat (itoa (1+ i)) " - " (itoa (+ i 2))) text_val (cdr (assoc 1 (entget (car (cdr (nth j dist_pos_ent_name_lst)))))) output_vertex (cons vertex output_vertex) output_text_val (cons text_val output_text_val) ) ) ) ;; end 1. cond ;; 2. cond ((not (equal ss nil)) (if (and (< (1+ i) 10) (< (+ i 2) 10)) (setq vertex (strcat "0" (itoa (1+ i)) " - " "0" (itoa (+ i 2))) text_val (cdr (assoc 1 (entget (ssname ss 0)))) output_vertex (cons vertex output_vertex) output_text_val (cons text_val output_text_val) ) (setq vertex (strcat (itoa (1+ i)) " - " (itoa (+ i 2))) text_val (cdr (assoc 1 (entget (ssname ss 0)))) output_vertex (cons vertex output_vertex) output_text_val (cons text_val output_text_val) ) ) ) ;; end 2. cond ) ;; end cond ) ;; end main progn ) ;; end main if (setq i (1+ i)) ) ;; end while (setq last_i (1- i) i 0) ;; start repeat (repeat (1+ i) (setq dist (/ (distance (cdr (nth i pt_num_lst)) (cdr (nth last_i pt_num_lst))) 2) ang (angle (cdr (nth last_i pt_num_lst)) (cdr (nth i pt_num_lst))) npt_one (polar (cdr (nth last_i pt_num_lst)) ang dist) angn (+ ang (/ pi 2)) npt_second (polar npt_one angn def_len) ) (setq ss (ssget "_F" (list npt_one npt_second) '((0 . "TEXT,MTEXT") (8 . "LOTE")))) ;; start cond (cond ;; 1. cond ((equal ss nil) (setq ssn (ssget "_F" (list npt_one npt_second) '((0 . "LWPOLYLINE") (8 . "LOTE"))) len_ss (sslength ssn) j 0 dist_pos_ent_name_lst (list) n (1- len_ss) ) (repeat len_ss ;; start if (if (not (equal n -1)) ;; start progn (progn (setq ent_ssn (entget (ssname ssn n)) ptlist_ssn (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) ent_ssn)) ss_new (ssget "_WP" ptlist_ssn '((0 . "TEXT,MTEXT") (8 . "LOTE"))) text_val_pos (cdr (assoc 10 (entget (ssname ss_new j)))) dist_pos (distance npt_one text_val_pos) dist_pos_ent_name (list dist_pos (ssname ss_new j)) dist_pos_ent_name_lst (cons dist_pos_ent_name dist_pos_ent_name_lst) n (1- n) ) ) ;; end progn ) ;; end if ) ;; end repeat (setq dist_pos_ent_name_lst (vl-sort dist_pos_ent_name_lst (function (lambda (x1 x2) (< (car x1) (car x2)))))) ;; Sorting list from MIN to MAX Distance with entity (setq vertex (strcat (itoa (+ last_i 1)) " - " "0" (itoa (+ i 1))) text_val (cdr (assoc 1 (entget (car (cdr (nth j dist_pos_ent_name_lst)))))) output_vertex (cons vertex output_vertex) output_text_val (cons text_val output_text_val) ) ) ;; end 1. cond ;; 2. cond ((not (equal ss nil)) (setq vertex (strcat (itoa (+ last_i 1)) " - " "0" (itoa (+ i 1))) text_val (cdr (assoc 1 (entget (ssname ss 0)))) output_vertex (cons vertex output_vertex) output_text_val (cons text_val output_text_val) ) ) ;; end 2. cond ) ;; end cond ) ;; end repeat (setq output_vertex (reverse output_vertex)) (setq output_text_val (reverse output_text_val)) (setq acadObj (vlax-get-acad-object) doc (vla-get-ActiveDocument acadObj) ) (if (= 1 (getvar 'cvport)) (setvar 'ctab "MODEL") ) (setq pt (vlax-3d-point (getpoint "\nPick the insertation point for Table:")) numRows (+ (length output_vertex) 2) numColumns 2 rowHeight 14.00 colWidth 100.0 txtHeightHeader 7.50 txtHeightColumns 5.00 row 0 col 0 ) (setq modelSpace (vla-get-ModelSpace doc)) ;; Add a Header to Table (setq myTable (vla-Addtable modelSpace pt numRows numColumns rowHeight colWidth)) ;; Put the color of the tabel into the Cyan (vla-put-Color myTable acCyan) (vla-SetTextHeight2 myTable row col row txtHeightHeader) (vla-SetColumnWidth myTable col colWidth) (vla-SetText myTable row col header) ;; Add a Header to 1. column (vla-SetTextHeight2 myTable (1+ row) col (1+ row) txtHeightColumns) (vla-SetColumnWidth myTable col (/ colWidth 2)) (vla-SetText myTable (1+ row) col first_column) ;; Add a Header to 2. column (vla-SetTextHeight2 myTable (1+ row) (1+ col) (1+ row) txtHeightColumns) (vla-SetColumnWidth myTable (1+ col) (/ colWidth 2)) (vla-SetText myTable (1+ row) (1+ col) second_column) ;; Iterate trought the "output_vertex" and add a value to every row at 1. column ;; while start (while (< row (length output_vertex)) ;; start if (if (<= (1+ row) (length output_vertex)) ;; progn start (progn (vla-SetTextHeight2 myTable (+ row 2) col (+ row 2) txtHeightColumns) (vla-SetCellAlignment myTable (+ row 2) col acMiddleCenter) (vla-SetText myTable (+ row 2) col (nth row output_vertex)) ) ;; progn end ) ;; if end (setq row (1+ row)) ) ;; end while (setq row 0) ;; Reset the row number (setq col (1+ col)) ;; Go into the another column ;; Iterate trought the "output_text_val" and add a value to every row at 2. column ;; while start (while (< row (length output_text_val)) ;; start if (if (<= (1+ row) (length output_text_val)) ;; progn start (progn (vla-SetTextHeight2 myTable (+ row 2) col (+ row 2) txtHeightColumns) (vla-SetCellAlignment myTable (+ row 2) col acMiddleCenter) (vla-SetText myTable (+ row 2) col (nth row output_text_val)) ) ;; progn end ) ;; if end (setq row (1+ row)) ) ;; end while (prompt "\nThe Tabel with values is inserted in model space!") (princ) ) As you can see on the picture from belowed, the "output tabel using lisp" is what I get using lisp from above, but there is one thing, when formatting "VERTEX" column, I get "9 - 10" insted of "09 - 10" (you can see the red rectangle). Also, it isn't formatted as yours "Your tabel" from picture (I'm not yet familiar with all things about the Tabel formatting, sorry ). I didn't mention, I use this for "ssget" filter '((0 . "LINE,LWPOLYLINE") (8 . "LIXO") (62 . 3)))), '((0 . "TEXT,MTEXT") (8 . "LOTE")) and '((0 . "LWPOLYLINE") (8 . "LOTE")), if you have different layers names/colors, it wont work. I hope it will helpful for your purpose. If you have maybe larger drawing, please upload it, just for the test. Best regards.1 point
-
Everything possible to thwart basic attempts is mentioned in the links I posted. But, to add: Be sure to make the drawing a block and apply different scaling in the x and y directions to add a reproduction difficulty and then explode, make it an image (with just the minimum resolution to be of use and no more, etc. With the ability for AutoCAD to reconstruct exploded Texts/Mtexts (PDFSHXTEXT) using a difficult font to recreate would help (the above mentioned x/y scaling could help), if what's in the texts are important enough to be concerned. I can make a PDF an Image and use Raster Image on it fairly easily on standard Raster PDFs, so remember that when making the PDF.1 point
-
Mapcar and foreach are simply loops through a list (or in mapcar's case one or more lists). I've done a description of the main differences between the 2 here: http://www.cadtutor.net/forum/showthread.php?47026-Difference-between-foreach-and-mapcar&p=404821&viewfull=1#post404821 Apply, is a way of sending a list as arguments to a function. E.g. The following would give you the same result, as they do the same thing (+ 1 2 3) ; Returns 6 (apply '+ (list 1 2 3)) ; Returns 6 The reason you'd use apply instead of simply writing the normal call is, sometimes you don't know what contents are in the list or you obtain the list from somewhere else. Note also the single-quote before the +, this is a shorthand way of writing (apply (quote +) (list 1 2 3)) Quote is a bit difficult to understand at first. A way of thinking about it is that it sends the container and not the value. In lisp (especially AutoLisp) it's impossible to pass something "by-reference" as you can in some other languages. But the quote idea gets around that issue, by passing the container itself. That way you can even modify the container's contents. E.g. say you want to add 2 to the contents of any variable you send to your function: (defun Add2 (var) (set var (+ (eval var) 2)) (setq n1 5 n2 3) (Add2 'n1) ;Returns 7, but also sets n1's value to 7 (Add2 'n2) ;Returns 5, but also sets n2's value to 5 Note the use of eval. It's basically the reverse of quote. I.e. extract the value from the container. Lambda, is basically the same thing as defun - except you don't need to give the function a name. I.e. it's an anonymous function. This allows you to place the definition of such function directly where it's used. Function, simply optimizes a lambda so it performs as close as possible to a real defun - since a lambda is stored as a list which needs to be evaluated, but a defun/function is stored as a somewhat compiled piece of program. Also if you're using VLIDE then you can step inside a function-lambda during debugging, but not inside a non-optimized/quoted lambda. Also function already quotes the resulting optimized lambda so it can directly be passed as an argument. E.g. this would add 1 to each item in a list (not modifying the original list) and return the list of results (setq lst (list 1 2 3)) ;Creates a variable (lst) with its contents set to (1 2 3) (mapcar '1+ lst) ;Runs the 1+ function on each item in turn and returns (2 3 4) But if you wanted to add 2 to each, there's no pre-made function for that. So you have to make one: (defun 2+ (num) (+ num 2)) ;; And then you can call it the same way (mapcar '2+ lst) ; Returns (3 4 5) But rather than make all sorts of new functions which might clutter the namespace (i.e. all the symbols known to Lisp), you can incorporate the definition of the function directly in the same line as the mapcar by using lambda: (mapcar '(lambda (num) (+ num 2)) lst) ;Returns (3 4 5) And then if you want it to run as fast as possible and be able to debug it in VLIDE: (mapcar (function (lambda (num) (+ num 2))) lst) ;Returns (3 4 5)1 point