Leaderboard
Popular Content
Showing content with the highest reputation on 01/21/2025 in all areas
-
(defun c:Circles_Chess_outl (/ oddp ent step radius vlist minx miny maxx maxy x y row pt osmant circulos creaMTEXT ) ;;----------------------------------------------- ;; THE FUNCTION OF CHECKING WHETHER THE NUMBER IS ODD ;;----------------------------------------------- (defun oddp (n) (= (logand (fix n) 1) 1) ) ;;----------------------------------------------- ;; Local auxiliary functions ;;----------------------------------------------- ;; Extracting a list of vertices (points) of a linear 2D polyline: (defun getPolyVertices (e / ed lst pts) (setq ed (entget e) ;; selecting all groups of the DXF = 10 code (coordinates of the vertices) lst (vl-remove-if-not '(lambda (x) (= (car x) 10)) ed ) ;; turning them into a regular list of points (x y) pts (mapcar 'cdr lst) ) (if (= (vlax-get-property (vlax-ename->vla-object e) "Closed") ':vlax-true) (append pts (list (car pts))) pts ) ) ;; Checking whether the pt point is located inside the linear polygon v list: ;;; (defun pointInPolygon (pt vlist / cnt i v1 v2) ;;; (setq cnt 0 ;;; i 0 ;;; ) ;;; ;; "Let's "block" the list so that we can bypass the pair (list[i], list[i+1]): ;;; (setq vlist (append vlist (list (car vlist)))) ;;; (repeat (1- (length vlist)) ;;; (setq v1 (nth i vlist) ;;; v2 (nth (1+ i) vlist) ;;; i (1+ i) ;;; ) ;;; (if (edgeIntersectsRay pt v1 v2) ;;; (setq cnt (1+ cnt)) ;;; ) ;;; ) ;;; ;; If the number of intersections with the ray is odd, the point inside ;;; (if (= (logand cnt 1) 1) ;;; T ;;; nil ;;; ) ;;; ) (defun comprobar_centralidad (pto lst_ptos_rto / pt_inters+ pt_inters- n pt1 pt2 inters_negat inters_posit ) (setq n 0) (repeat (- (length lst_ptos_rto) 1) (setq pt_inters+ (inters pto (list (+ (car pto) 100000) (cadr pto)) (setq pt1 (nth n lst_ptos_rto)) (setq pt2 (nth (+ n 1) lst_ptos_rto)) ) ) (if (and pt_inters+ (not (member (cons 10 pt_inters+) lst_ptos_rto)) ) (if inters_posit (setq inters_posit (+ inters_posit 1)) (setq inters_posit 1) ) ) (setq pt_inters- (inters pto (list (- (car pto) 100000) (cadr pto)) pt1 pt2 ) ) (if (and pt_inters- (not (member (cons 10 pt_inters-) lst_ptos_rto)) ) (if inters_negat (setq inters_negat (+ inters_negat 1)) (setq inters_negat 1) ) ) (setq n (+ n 1)) ) (if (and (= (rem (if (not inters_negat) 0 inters_negat ) 2 ) 0 ) (= (rem (if (not inters_posit) 0 inters_posit ) 2 ) 0 ) ) nil T ) ) (defun creaMTEXT (texto altura / vlaEnt) (setq vlaEnt (vla-AddMText (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) (vlax-3d-point ptx) 50 texto)) (vlax-put-property vlaEnt "Height" altura) ) (defun creaCIRCULO (pto radio / vlaEnt) (setq vlaEnt (vla-AddCircle (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) (vlax-3d-point pto) radio)) ) ;; Checking the intersection of the horizontal ray to the right of pt with the segment (v1,v2): (defun edgeIntersectsRay (pt v1 v2 / px py x1 y1 x2 y2) (setq px (car pt) py (cadr pt) x1 (car v1) y1 (cadr v1) x2 (car v2) y2 (cadr v2) ) ;; Let's ensure that (x1,y1) is "lower" than (x2,y2): (if (> y1 y2) (progn (setq x1 (car v2) y1 (cadr v2) x2 (car v1) y2 (cadr v1) ) ) ) ;; Intersection condition: (and ;; 1) py is strictly above the lower vertex and not higher than the upper one (> py y1) (<= py y2) ;; 2) px < abscissas of the intersection point of the ray with the segment (defun edgeIntersectsRay (pt v1 v2 / px py x1 y1 x2 y2 intersectX) (setq px (car pt) py (cadr pt) x1 (car v1) y1 (cadr v1) x2 (car v2) y2 (cadr v2) ) ) ;; Let's ensure that (x1,y1) is "lower" than (x2,y2) (if (> y1 y2) (setq x1 (car v2) y1 (cadr v2) x2 (car v1) y2 (cadr v1) ) ) ) ;; Counting the intersection coordinate (setq intersectX (if (/= y2 y1) (+ x1 (* (- py y1) (/ (- x2 x1) (- y2 y1)))) x1 ;; if the segment is horizontal, it is usually skipped. ) ) ;; We are returning (and ...), or nil (and (> py y1) ;; a point above the lower vertex (<= py y2) ;; and no higher than the top (> intersectX px) ) ) ;;----------------------------------------------- ;; the main part ;;----------------------------------------------- (setq ent (car (entsel "\nChoose a closed linear polyline: "))) (if (null ent) (progn (prompt "\nThe polyline is not selected. Completion.") (princ) ) (progn ;; 1) Step Request (setq step (getreal "\nEnter the step between the centers (??): ") ) (if (or (null step) (<= step 0.0)) (setq step 50.0) ;; the "backup" option ) ;; 2) Fixed radius (setq radius 25.0) ;; 3) List of vertices (minimum 3, otherwise not a polygon) (setq vlist (getPolyVertices ent)) (if (< (length vlist) 3) (progn (prompt "\nThe polyline has <3 vertices, and the contour is incorrect." ) (princ) ) (progn ;; 4) Defining bounding box (setq minx (apply 'min (mapcar 'car vlist)) maxx (apply 'max (mapcar 'car vlist)) miny (apply 'min (mapcar 'cadr vlist)) maxy (apply 'max (mapcar 'cadr vlist)) ) (prompt (strcat "\nboundary (bounding box) polyline:\n" " X: " (rtos minx 2 2) " ... " (rtos maxx 2 2) "\n Y: " (rtos miny 2 2) " ... " (rtos maxy 2 2) ) ) ;; 5) Building a grid "in a staggered manner" (setq row 0 y miny circulos 0 ) (setq osmant (getvar "osmode")) (setvar "osmode" 0) (while (<= y maxy) ;; For an odd row row, we shift X by step/2 (if (oddp row) (setq x (+ minx (/ step 2.0))) (setq x minx) ) (while (<= x maxx) (setq pt (list x y)) ;; If the center is inside the polyline, draw a circle. (if (comprobar_centralidad pt vlist) ;(pointInPolygon pt vlist) (progn ;;; (command "_.CIRCLE" pt radius) (creaCIRCULO pt radius) (setq circulos (+ circulos 1)) ) ) (setq x (+ x step)) ) (setq y (+ y step)) (setq row (1+ row)) ) (if (setq ptx (getpoint "\nPick insertion point for circle number text (right click or ENTER for skip)...")) (vla-AddText (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) (itoa circulos) (VLAX-3D-POINT ptx) radius) ;;; (vla-AddText (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) (strcat "Number of circles drawn: " (itoa circulos)) (VLAX-3D-POINT ptx) (/ radius 2.0)) ;;; (creaMTEXT (strcat "Count:\\P" (itoa circulos)) (/ radius 2.0)) ) (setvar "osmode" osmant) ) ) ) ) (princ) ) (defun c:WP-count (/ pl lstent points conj ptx creaMTEXT altura) (defun creaMTEXT (texto altura / vlaEnt) (setq vlaEnt (vla-AddMText (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) (vlax-3d-point ptx) 50 (strcat "Count:\\P" (itoa (sslength conj))))) (vlax-put-property vlaEnt "Height" altura) ) (if (setq pl (car (entsel "\nSelect border polyline..."))) (if (= "LWPOLYLINE" (cdr (assoc 0 (setq lstent (entget pl))))) (setq points (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) lstent ) ) ) ) ) (if points (progn (if (not altura1) (setq altura (getreal "\nHeight TEXT: ")) (setq altura (getreal (strcat "\nHeight TEXT (or ENTER for <" (rtos altura1 2 2) ">): "))) ) (if (not altura) (if altura1 (setq altura altura1) ) (setq altura1 altura) ) ) ) (if (and points altura (setq conj (ssget "_cp" points '((0 . "CIRCLE"))))) (if (setq ptx (getpoint (strcat "\nPick insertion point for objects number text <" (itoa (sslength conj)) "> (right click or ENTER for skip)..."))) (vla-AddText (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) (itoa (sslength conj)) (VLAX-3D-POINT ptx) altura) ) ) (princ) )1 point
-
1 point
-
One last thing: Steven is right. It's better not to use 'command'. The code runs slower and is vulnerable to the state of the "osmode" system variable. That's why I've updated your code so that the circles are generated faster. (defun c:Circles_Chess_outl (/ oddp ent step radius vlist minx miny maxx maxy x y row pt osmant circulos creaMTEXT ) ;;----------------------------------------------- ;; THE FUNCTION OF CHECKING WHETHER THE NUMBER IS ODD ;;----------------------------------------------- (defun oddp (n) (= (logand (fix n) 1) 1) ) ;;----------------------------------------------- ;; Local auxiliary functions ;;----------------------------------------------- ;; Extracting a list of vertices (points) of a linear 2D polyline: (defun getPolyVertices (e / ed lst pts) (setq ed (entget e) ;; selecting all groups of the DXF = 10 code (coordinates of the vertices) lst (vl-remove-if-not '(lambda (x) (= (car x) 10)) ed ) ;; turning them into a regular list of points (x y) pts (mapcar 'cdr lst) ) pts ) ;; Checking whether the pt point is located inside the linear polygon v list: ;;; (defun pointInPolygon (pt vlist / cnt i v1 v2) ;;; (setq cnt 0 ;;; i 0 ;;; ) ;;; ;; "Let's "block" the list so that we can bypass the pair (list[i], list[i+1]): ;;; (setq vlist (append vlist (list (car vlist)))) ;;; (repeat (1- (length vlist)) ;;; (setq v1 (nth i vlist) ;;; v2 (nth (1+ i) vlist) ;;; i (1+ i) ;;; ) ;;; (if (edgeIntersectsRay pt v1 v2) ;;; (setq cnt (1+ cnt)) ;;; ) ;;; ) ;;; ;; If the number of intersections with the ray is odd, the point inside ;;; (if (= (logand cnt 1) 1) ;;; T ;;; nil ;;; ) ;;; ) (defun comprobar_centralidad (pto lst_ptos_rto / pt_inters+ pt_inters- n pt1 pt2 inters_negat inters_posit ) (setq n 0) (repeat (- (length lst_ptos_rto) 1) (setq pt_inters+ (inters pto (list (+ (car pto) 100000) (cadr pto)) (setq pt1 (nth n lst_ptos_rto)) (setq pt2 (nth (+ n 1) lst_ptos_rto)) ) ) (if (and pt_inters+ (not (member (cons 10 pt_inters+) lst_ptos_rto)) ) (if inters_posit (setq inters_posit (+ inters_posit 1)) (setq inters_posit 1) ) ) (setq pt_inters- (inters pto (list (- (car pto) 100000) (cadr pto)) pt1 pt2 ) ) (if (and pt_inters- (not (member (cons 10 pt_inters-) lst_ptos_rto)) ) (if inters_negat (setq inters_negat (+ inters_negat 1)) (setq inters_negat 1) ) ) (setq n (+ n 1)) ) (if (and (= (rem (if (not inters_negat) 0 inters_negat ) 2 ) 0 ) (= (rem (if (not inters_posit) 0 inters_posit ) 2 ) 0 ) ) nil T ) ) (defun creaMTEXT (texto altura / vlaEnt) (setq vlaEnt (vla-AddMText (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) (vlax-3d-point ptx) 50 texto)) (vlax-put-property vlaEnt "Height" altura) ) (defun creaCIRCULO (pto radio / vlaEnt) (setq vlaEnt (vla-AddCircle (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) (vlax-3d-point pto) radio)) ) ;; Checking the intersection of the horizontal ray to the right of pt with the segment (v1,v2): (defun edgeIntersectsRay (pt v1 v2 / px py x1 y1 x2 y2) (setq px (car pt) py (cadr pt) x1 (car v1) y1 (cadr v1) x2 (car v2) y2 (cadr v2) ) ;; Let's ensure that (x1,y1) is "lower" than (x2,y2): (if (> y1 y2) (progn (setq x1 (car v2) y1 (cadr v2) x2 (car v1) y2 (cadr v1) ) ) ) ;; Intersection condition: (and ;; 1) py is strictly above the lower vertex and not higher than the upper one (> py y1) (<= py y2) ;; 2) px < abscissas of the intersection point of the ray with the segment (defun edgeIntersectsRay (pt v1 v2 / px py x1 y1 x2 y2 intersectX) (setq px (car pt) py (cadr pt) x1 (car v1) y1 (cadr v1) x2 (car v2) y2 (cadr v2) ) ) ;; Let's ensure that (x1,y1) is "lower" than (x2,y2) (if (> y1 y2) (setq x1 (car v2) y1 (cadr v2) x2 (car v1) y2 (cadr v1) ) ) ) ;; Counting the intersection coordinate (setq intersectX (if (/= y2 y1) (+ x1 (* (- py y1) (/ (- x2 x1) (- y2 y1)))) x1 ;; if the segment is horizontal, it is usually skipped. ) ) ;; We are returning (and ...), or nil (and (> py y1) ;; a point above the lower vertex (<= py y2) ;; and no higher than the top (> intersectX px) ) ) ;;----------------------------------------------- ;; the main part ;;----------------------------------------------- (setq ent (car (entsel "\nChoose a closed linear polyline: "))) (if (null ent) (progn (prompt "\nThe polyline is not selected. Completion.") (princ) ) (progn ;; 1) Step Request (setq step (getreal "\nEnter the step between the centers (??): ") ) (if (or (null step) (<= step 0.0)) (setq step 50.0) ;; the "backup" option ) ;; 2) Fixed radius (setq radius 25.0) ;; 3) List of vertices (minimum 3, otherwise not a polygon) (setq vlist (getPolyVertices ent)) (if (< (length vlist) 3) (progn (prompt "\nThe polyline has <3 vertices, and the contour is incorrect." ) (princ) ) (progn ;; 4) Defining bounding box (setq minx (apply 'min (mapcar 'car vlist)) maxx (apply 'max (mapcar 'car vlist)) miny (apply 'min (mapcar 'cadr vlist)) maxy (apply 'max (mapcar 'cadr vlist)) ) (prompt (strcat "\nboundary (bounding box) polyline:\n" " X: " (rtos minx 2 2) " ... " (rtos maxx 2 2) "\n Y: " (rtos miny 2 2) " ... " (rtos maxy 2 2) ) ) ;; 5) Building a grid "in a staggered manner" (setq row 0 y miny circulos 0 ) (setq osmant (getvar "osmode")) (setvar "osmode" 0) (while (<= y maxy) ;; For an odd row row, we shift X by step/2 (if (oddp row) (setq x (+ minx (/ step 2.0))) (setq x minx) ) (while (<= x maxx) (setq pt (list x y)) ;; If the center is inside the polyline, draw a circle. (if (comprobar_centralidad pt vlist) ;(pointInPolygon pt vlist) (progn ;;; (command "_.CIRCLE" pt radius) (creaCIRCULO pt radius) (setq circulos (+ circulos 1)) ) ) (setq x (+ x step)) ) (setq y (+ y step)) (setq row (1+ row)) ) (if (setq ptx (getpoint "\nPick insertion point for circle number text (right click or ENTER for skip)...")) (vla-AddText (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) (itoa circulos) (VLAX-3D-POINT ptx) (/ radius 2.0)) ;;; (vla-AddText (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) (strcat "Number of circles drawn: " (itoa circulos)) (VLAX-3D-POINT ptx) (/ radius 2.0)) ;;; (creaMTEXT (strcat "Count:\\P" (itoa circulos)) (/ radius 2.0)) ) (setvar "osmode" osmant) ) ) ) ) (princ) )1 point
-
Yes, everything is fine now! Thank you so much for your help! Dreams come true...1 point
-
(defun c:Circles_Chess_outl (/ oddp ent step radius vlist minx miny maxx maxy x y row pt osmant circulos creaMTEXT ) ;;----------------------------------------------- ;; THE FUNCTION OF CHECKING WHETHER THE NUMBER IS ODD ;;----------------------------------------------- (defun oddp (n) (= (logand (fix n) 1) 1) ) ;;----------------------------------------------- ;; Local auxiliary functions ;;----------------------------------------------- ;; Extracting a list of vertices (points) of a linear 2D polyline: (defun getPolyVertices (e / ed lst pts) (setq ed (entget e) ;; selecting all groups of the DXF = 10 code (coordinates of the vertices) lst (vl-remove-if-not '(lambda (x) (= (car x) 10)) ed ) ;; turning them into a regular list of points (x y) pts (mapcar 'cdr lst) ) pts ) ;; Checking whether the pt point is located inside the linear polygon v list: ;;; (defun pointInPolygon (pt vlist / cnt i v1 v2) ;;; (setq cnt 0 ;;; i 0 ;;; ) ;;; ;; "Let's "block" the list so that we can bypass the pair (list[i], list[i+1]): ;;; (setq vlist (append vlist (list (car vlist)))) ;;; (repeat (1- (length vlist)) ;;; (setq v1 (nth i vlist) ;;; v2 (nth (1+ i) vlist) ;;; i (1+ i) ;;; ) ;;; (if (edgeIntersectsRay pt v1 v2) ;;; (setq cnt (1+ cnt)) ;;; ) ;;; ) ;;; ;; If the number of intersections with the ray is odd, the point inside ;;; (if (= (logand cnt 1) 1) ;;; T ;;; nil ;;; ) ;;; ) (defun comprobar_centralidad (pto lst_ptos_rto / pt_inters+ pt_inters- n pt1 pt2 inters_negat inters_posit ) (setq n 0) (repeat (- (length lst_ptos_rto) 1) (setq pt_inters+ (inters pto (list (+ (car pto) 100000) (cadr pto)) (setq pt1 (nth n lst_ptos_rto)) (setq pt2 (nth (+ n 1) lst_ptos_rto)) ) ) (if (and pt_inters+ (not (member (cons 10 pt_inters+) lst_ptos_rto)) ) (if inters_posit (setq inters_posit (+ inters_posit 1)) (setq inters_posit 1) ) ) (setq pt_inters- (inters pto (list (- (car pto) 100000) (cadr pto)) pt1 pt2 ) ) (if (and pt_inters- (not (member (cons 10 pt_inters-) lst_ptos_rto)) ) (if inters_negat (setq inters_negat (+ inters_negat 1)) (setq inters_negat 1) ) ) (setq n (+ n 1)) ) (if (and (= (rem (if (not inters_negat) 0 inters_negat ) 2 ) 0 ) (= (rem (if (not inters_posit) 0 inters_posit ) 2 ) 0 ) ) nil T ) ) (defun creaMTEXT (texto altura / vlaEnt) (setq vlaEnt (vla-AddMText (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) (vlax-3d-point ptx) 50 texto)) (vlax-put-property vlaEnt "Height" altura) ) ;; Checking the intersection of the horizontal ray to the right of pt with the segment (v1,v2): (defun edgeIntersectsRay (pt v1 v2 / px py x1 y1 x2 y2) (setq px (car pt) py (cadr pt) x1 (car v1) y1 (cadr v1) x2 (car v2) y2 (cadr v2) ) ;; Let's ensure that (x1,y1) is "lower" than (x2,y2): (if (> y1 y2) (progn (setq x1 (car v2) y1 (cadr v2) x2 (car v1) y2 (cadr v1) ) ) ) ;; Intersection condition: (and ;; 1) py is strictly above the lower vertex and not higher than the upper one (> py y1) (<= py y2) ;; 2) px < abscissas of the intersection point of the ray with the segment (defun edgeIntersectsRay (pt v1 v2 / px py x1 y1 x2 y2 intersectX) (setq px (car pt) py (cadr pt) x1 (car v1) y1 (cadr v1) x2 (car v2) y2 (cadr v2) ) ) ;; Let's ensure that (x1,y1) is "lower" than (x2,y2) (if (> y1 y2) (setq x1 (car v2) y1 (cadr v2) x2 (car v1) y2 (cadr v1) ) ) ) ;; Counting the intersection coordinate (setq intersectX (if (/= y2 y1) (+ x1 (* (- py y1) (/ (- x2 x1) (- y2 y1)))) x1 ;; if the segment is horizontal, it is usually skipped. ) ) ;; We are returning (and ...), or nil (and (> py y1) ;; a point above the lower vertex (<= py y2) ;; and no higher than the top (> intersectX px) ) ) ;;----------------------------------------------- ;; the main part ;;----------------------------------------------- (setq ent (car (entsel "\nChoose a closed linear polyline: "))) (if (null ent) (progn (prompt "\nThe polyline is not selected. Completion.") (princ) ) (progn ;; 1) Step Request (setq step (getreal "\nEnter the step between the centers (??): ") ) (if (or (null step) (<= step 0.0)) (setq step 50.0) ;; the "backup" option ) ;; 2) Fixed radius (setq radius 25.0) ;; 3) List of vertices (minimum 3, otherwise not a polygon) (setq vlist (getPolyVertices ent)) (if (< (length vlist) 3) (progn (prompt "\nThe polyline has <3 vertices, and the contour is incorrect." ) (princ) ) (progn ;; 4) Defining bounding box (setq minx (apply 'min (mapcar 'car vlist)) maxx (apply 'max (mapcar 'car vlist)) miny (apply 'min (mapcar 'cadr vlist)) maxy (apply 'max (mapcar 'cadr vlist)) ) (prompt (strcat "\nboundary (bounding box) polyline:\n" " X: " (rtos minx 2 2) " ... " (rtos maxx 2 2) "\n Y: " (rtos miny 2 2) " ... " (rtos maxy 2 2) ) ) ;; 5) Building a grid "in a staggered manner" (setq row 0 y miny circulos 0 ) (setq osmant (getvar "osmode")) (setvar "osmode" 0) (while (<= y maxy) ;; For an odd row row, we shift X by step/2 (if (oddp row) (setq x (+ minx (/ step 2.0))) (setq x minx) ) (while (<= x maxx) (setq pt (list x y)) ;; If the center is inside the polyline, draw a circle. (if (comprobar_centralidad pt vlist) ;(pointInPolygon pt vlist) (progn (command "_.CIRCLE" pt radius) (setq circulos (+ circulos 1)) ) ) (setq x (+ x step)) ) (setq y (+ y step)) (setq row (1+ row)) ) (if (setq ptx (getpoint "\nPick insertion point for circle number text (right click or ENTER for skip)...")) (vla-AddText (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) (itoa circulos) (VLAX-3D-POINT ptx) (/ radius 2.0)) ;;; (vla-AddText (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) (strcat "Number of circles drawn: " (itoa circulos)) (VLAX-3D-POINT ptx) (/ radius 2.0)) ;;; (creaMTEXT (strcat "Count:\\P" (itoa circulos)) (/ radius 2.0)) ) (setvar "osmode" osmant) ) ) ) ) (princ) )1 point
-
Wait I just noticed that for some reason the website didn't update my edited code. I'll attach it again1 point
-
Please copy the code again It should write only the number in a single line text1 point
-
For the text content and its size you will have to edit the code yourself1 point
-
There is also another detail: in the command 'c:WP-count' you must change the selection mode from ' ssget "_wp" ' to ' ssget "_cp" ' so that it selects not only the objects that are fully included1 point
-
1 point
-
Im sorry I forgot to change something in the main command I attach the correction below (defun c:Circles_Chess_outl (/ oddp ent step radius vlist minx miny maxx maxy x y row pt osmant circulos creaMTEXT ) ;;----------------------------------------------- ;; THE FUNCTION OF CHECKING WHETHER THE NUMBER IS ODD ;;----------------------------------------------- (defun oddp (n) (= (logand (fix n) 1) 1) ) ;;----------------------------------------------- ;; Local auxiliary functions ;;----------------------------------------------- ;; Extracting a list of vertices (points) of a linear 2D polyline: (defun getPolyVertices (e / ed lst pts) (setq ed (entget e) ;; selecting all groups of the DXF = 10 code (coordinates of the vertices) lst (vl-remove-if-not '(lambda (x) (= (car x) 10)) ed ) ;; turning them into a regular list of points (x y) pts (mapcar 'cdr lst) ) pts ) ;; Checking whether the pt point is located inside the linear polygon v list: ;;; (defun pointInPolygon (pt vlist / cnt i v1 v2) ;;; (setq cnt 0 ;;; i 0 ;;; ) ;;; ;; "Let's "block" the list so that we can bypass the pair (list[i], list[i+1]): ;;; (setq vlist (append vlist (list (car vlist)))) ;;; (repeat (1- (length vlist)) ;;; (setq v1 (nth i vlist) ;;; v2 (nth (1+ i) vlist) ;;; i (1+ i) ;;; ) ;;; (if (edgeIntersectsRay pt v1 v2) ;;; (setq cnt (1+ cnt)) ;;; ) ;;; ) ;;; ;; If the number of intersections with the ray is odd, the point inside ;;; (if (= (logand cnt 1) 1) ;;; T ;;; nil ;;; ) ;;; ) (defun comprobar_centralidad (pto lst_ptos_rto / pt_inters+ pt_inters- n pt1 pt2 inters_negat inters_posit ) (setq n 0) (repeat (- (length lst_ptos_rto) 1) (setq pt_inters+ (inters pto (list (+ (car pto) 100000) (cadr pto)) (setq pt1 (nth n lst_ptos_rto)) (setq pt2 (nth (+ n 1) lst_ptos_rto)) ) ) (if (and pt_inters+ (not (member (cons 10 pt_inters+) lst_ptos_rto)) ) (if inters_posit (setq inters_posit (+ inters_posit 1)) (setq inters_posit 1) ) ) (setq pt_inters- (inters pto (list (- (car pto) 100000) (cadr pto)) pt1 pt2 ) ) (if (and pt_inters- (not (member (cons 10 pt_inters-) lst_ptos_rto)) ) (if inters_negat (setq inters_negat (+ inters_negat 1)) (setq inters_negat 1) ) ) (setq n (+ n 1)) ) (if (and (= (rem (if (not inters_negat) 0 inters_negat ) 2 ) 0 ) (= (rem (if (not inters_posit) 0 inters_posit ) 2 ) 0 ) ) nil T ) ) (defun creaMTEXT (texto altura / vlaEnt) (setq vlaEnt (vla-AddMText (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) (vlax-3d-point ptx) 50 (strcat "Count:\\P" texto))) (vlax-put-property vlaEnt "Height" altura) ) ;; Checking the intersection of the horizontal ray to the right of pt with the segment (v1,v2): (defun edgeIntersectsRay (pt v1 v2 / px py x1 y1 x2 y2) (setq px (car pt) py (cadr pt) x1 (car v1) y1 (cadr v1) x2 (car v2) y2 (cadr v2) ) ;; Let's ensure that (x1,y1) is "lower" than (x2,y2): (if (> y1 y2) (progn (setq x1 (car v2) y1 (cadr v2) x2 (car v1) y2 (cadr v1) ) ) ) ;; Intersection condition: (and ;; 1) py is strictly above the lower vertex and not higher than the upper one (> py y1) (<= py y2) ;; 2) px < abscissas of the intersection point of the ray with the segment (defun edgeIntersectsRay (pt v1 v2 / px py x1 y1 x2 y2 intersectX) (setq px (car pt) py (cadr pt) x1 (car v1) y1 (cadr v1) x2 (car v2) y2 (cadr v2) ) ) ;; Let's ensure that (x1,y1) is "lower" than (x2,y2) (if (> y1 y2) (setq x1 (car v2) y1 (cadr v2) x2 (car v1) y2 (cadr v1) ) ) ) ;; Counting the intersection coordinate (setq intersectX (if (/= y2 y1) (+ x1 (* (- py y1) (/ (- x2 x1) (- y2 y1)))) x1 ;; if the segment is horizontal, it is usually skipped. ) ) ;; We are returning (and ...), or nil (and (> py y1) ;; a point above the lower vertex (<= py y2) ;; and no higher than the top (> intersectX px) ) ) ;;----------------------------------------------- ;; the main part ;;----------------------------------------------- (setq ent (car (entsel "\nChoose a closed linear polyline: "))) (if (null ent) (progn (prompt "\nThe polyline is not selected. Completion.") (princ) ) (progn ;; 1) Step Request (setq step (getreal "\nEnter the step between the centers (??): ") ) (if (or (null step) (<= step 0.0)) (setq step 50.0) ;; the "backup" option ) ;; 2) Fixed radius (setq radius 25.0) ;; 3) List of vertices (minimum 3, otherwise not a polygon) (setq vlist (getPolyVertices ent)) (if (< (length vlist) 3) (progn (prompt "\nThe polyline has <3 vertices, and the contour is incorrect." ) (princ) ) (progn ;; 4) Defining bounding box (setq minx (apply 'min (mapcar 'car vlist)) maxx (apply 'max (mapcar 'car vlist)) miny (apply 'min (mapcar 'cadr vlist)) maxy (apply 'max (mapcar 'cadr vlist)) ) (prompt (strcat "\nboundary (bounding box) polyline:\n" " X: " (rtos minx 2 2) " ... " (rtos maxx 2 2) "\n Y: " (rtos miny 2 2) " ... " (rtos maxy 2 2) ) ) ;; 5) Building a grid "in a staggered manner" (setq row 0 y miny circulos 0 ) (setq osmant (getvar "osmode")) (setvar "osmode" 0) (while (<= y maxy) ;; For an odd row row, we shift X by step/2 (if (oddp row) (setq x (+ minx (/ step 2.0))) (setq x minx) ) (while (<= x maxx) (setq pt (list x y)) ;; If the center is inside the polyline, draw a circle. (if (comprobar_centralidad pt vlist) ;(pointInPolygon pt vlist) (progn (command "_.CIRCLE" pt radius) (setq circulos (+ circulos 1)) ) ) (setq x (+ x step)) ) (setq y (+ y step)) (setq row (1+ row)) ) (if (setq ptx (getpoint "\nPick insertion point for circle number text (right click or ENTER for skip)...")) ;;; (vla-AddText (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) (strcat "Number of circles drawn: " (itoa circulos)) (VLAX-3D-POINT ptx) (/ radius 2.0)) (creaMTEXT (strcat "Count:\\P" (itoa circulos)) (/ radius 2.0)) ) (setvar "osmode" osmant) ) ) ) ) (princ) )1 point
-
In the main function I have predefined the height of the MTEXT to half the radius of the circles. If you want to modify it you will have to go into the code and change it. I have also written a separate command. I hope it helps.1 point
-
(defun c:Circles_Chess_outl (/ oddp ent step radius vlist minx miny maxx maxy x y row pt osmant circulos creaMTEXT ) ;;----------------------------------------------- ;; THE FUNCTION OF CHECKING WHETHER THE NUMBER IS ODD ;;----------------------------------------------- (defun oddp (n) (= (logand (fix n) 1) 1) ) ;;----------------------------------------------- ;; Local auxiliary functions ;;----------------------------------------------- ;; Extracting a list of vertices (points) of a linear 2D polyline: (defun getPolyVertices (e / ed lst pts) (setq ed (entget e) ;; selecting all groups of the DXF = 10 code (coordinates of the vertices) lst (vl-remove-if-not '(lambda (x) (= (car x) 10)) ed ) ;; turning them into a regular list of points (x y) pts (mapcar 'cdr lst) ) pts ) ;; Checking whether the pt point is located inside the linear polygon v list: ;;; (defun pointInPolygon (pt vlist / cnt i v1 v2) ;;; (setq cnt 0 ;;; i 0 ;;; ) ;;; ;; "Let's "block" the list so that we can bypass the pair (list[i], list[i+1]): ;;; (setq vlist (append vlist (list (car vlist)))) ;;; (repeat (1- (length vlist)) ;;; (setq v1 (nth i vlist) ;;; v2 (nth (1+ i) vlist) ;;; i (1+ i) ;;; ) ;;; (if (edgeIntersectsRay pt v1 v2) ;;; (setq cnt (1+ cnt)) ;;; ) ;;; ) ;;; ;; If the number of intersections with the ray is odd, the point inside ;;; (if (= (logand cnt 1) 1) ;;; T ;;; nil ;;; ) ;;; ) (defun comprobar_centralidad (pto lst_ptos_rto / pt_inters+ pt_inters- n pt1 pt2 inters_negat inters_posit ) (setq n 0) (repeat (- (length lst_ptos_rto) 1) (setq pt_inters+ (inters pto (list (+ (car pto) 100000) (cadr pto)) (setq pt1 (nth n lst_ptos_rto)) (setq pt2 (nth (+ n 1) lst_ptos_rto)) ) ) (if (and pt_inters+ (not (member (cons 10 pt_inters+) lst_ptos_rto)) ) (if inters_posit (setq inters_posit (+ inters_posit 1)) (setq inters_posit 1) ) ) (setq pt_inters- (inters pto (list (- (car pto) 100000) (cadr pto)) pt1 pt2 ) ) (if (and pt_inters- (not (member (cons 10 pt_inters-) lst_ptos_rto)) ) (if inters_negat (setq inters_negat (+ inters_negat 1)) (setq inters_negat 1) ) ) (setq n (+ n 1)) ) (if (and (= (rem (if (not inters_negat) 0 inters_negat ) 2 ) 0 ) (= (rem (if (not inters_posit) 0 inters_posit ) 2 ) 0 ) ) nil T ) ) (defun creaMTEXT (texto altura / vlaEnt) (setq vlaEnt (vla-AddMText (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) (vlax-3d-point ptx) 50 (strcat "Count:\\P" (itoa (sslength conj))))) (vlax-put-property vlaEnt "Height" altura) ) ;; Checking the intersection of the horizontal ray to the right of pt with the segment (v1,v2): (defun edgeIntersectsRay (pt v1 v2 / px py x1 y1 x2 y2) (setq px (car pt) py (cadr pt) x1 (car v1) y1 (cadr v1) x2 (car v2) y2 (cadr v2) ) ;; Let's ensure that (x1,y1) is "lower" than (x2,y2): (if (> y1 y2) (progn (setq x1 (car v2) y1 (cadr v2) x2 (car v1) y2 (cadr v1) ) ) ) ;; Intersection condition: (and ;; 1) py is strictly above the lower vertex and not higher than the upper one (> py y1) (<= py y2) ;; 2) px < abscissas of the intersection point of the ray with the segment (defun edgeIntersectsRay (pt v1 v2 / px py x1 y1 x2 y2 intersectX) (setq px (car pt) py (cadr pt) x1 (car v1) y1 (cadr v1) x2 (car v2) y2 (cadr v2) ) ) ;; Let's ensure that (x1,y1) is "lower" than (x2,y2) (if (> y1 y2) (setq x1 (car v2) y1 (cadr v2) x2 (car v1) y2 (cadr v1) ) ) ) ;; Counting the intersection coordinate (setq intersectX (if (/= y2 y1) (+ x1 (* (- py y1) (/ (- x2 x1) (- y2 y1)))) x1 ;; if the segment is horizontal, it is usually skipped. ) ) ;; We are returning (and ...), or nil (and (> py y1) ;; a point above the lower vertex (<= py y2) ;; and no higher than the top (> intersectX px) ) ) ;;----------------------------------------------- ;; the main part ;;----------------------------------------------- (setq ent (car (entsel "\nChoose a closed linear polyline: "))) (if (null ent) (progn (prompt "\nThe polyline is not selected. Completion.") (princ) ) (progn ;; 1) Step Request (setq step (getreal "\nEnter the step between the centers (??): ") ) (if (or (null step) (<= step 0.0)) (setq step 50.0) ;; the "backup" option ) ;; 2) Fixed radius (setq radius 25.0) ;; 3) List of vertices (minimum 3, otherwise not a polygon) (setq vlist (getPolyVertices ent)) (if (< (length vlist) 3) (progn (prompt "\nThe polyline has <3 vertices, and the contour is incorrect." ) (princ) ) (progn ;; 4) Defining bounding box (setq minx (apply 'min (mapcar 'car vlist)) maxx (apply 'max (mapcar 'car vlist)) miny (apply 'min (mapcar 'cadr vlist)) maxy (apply 'max (mapcar 'cadr vlist)) ) (prompt (strcat "\nboundary (bounding box) polyline:\n" " X: " (rtos minx 2 2) " ... " (rtos maxx 2 2) "\n Y: " (rtos miny 2 2) " ... " (rtos maxy 2 2) ) ) ;; 5) Building a grid "in a staggered manner" (setq row 0 y miny circulos 0 ) (setq osmant (getvar "osmode")) (setvar "osmode" 0) (while (<= y maxy) ;; For an odd row row, we shift X by step/2 (if (oddp row) (setq x (+ minx (/ step 2.0))) (setq x minx) ) (while (<= x maxx) (setq pt (list x y)) ;; If the center is inside the polyline, draw a circle. (if (comprobar_centralidad pt vlist) ;(pointInPolygon pt vlist) (progn (command "_.CIRCLE" pt radius) (setq circulos (+ circulos 1)) ) ) (setq x (+ x step)) ) (setq y (+ y step)) (setq row (1+ row)) ) (if (setq ptx (getpoint "\nPick insertion point for circle number text (right click or ENTER for skip)...")) ;;; (vla-AddText (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) (strcat "Number of circles drawn: " (itoa circulos)) (VLAX-3D-POINT ptx) (/ radius 2.0)) (creaMTEXT (strcat "Count:\\P" (itoa (sslength conj))) (/ radius 2.0)) ) (setvar "osmode" osmant) ) ) ) ) (princ) ) (defun c:WP-count (/ pl lstent points conj ptx creaMTEXT altura) (defun creaMTEXT (texto altura / vlaEnt) (setq vlaEnt (vla-AddMText (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) (vlax-3d-point ptx) 50 (strcat "Count:\\P" (itoa (sslength conj))))) (vlax-put-property vlaEnt "Height" altura) ) (if (setq pl (car (entsel "\nSelect border polyline..."))) (if (= "LWPOLYLINE" (cdr (assoc 0 (setq lstent (entget pl))))) (setq points (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) lstent ) ) ) ) ) (if points (progn (if (not altura1) (setq altura (getreal "\nHeight MTEXT: ")) (setq altura (getreal (strcat "\nHeight MTEXT (or ENTER for <" (rtos altura1 2 2) ">): "))) ) (if (not altura) (if altura1 (setq altura altura1) ) (setq altura1 altura) ) ) ) (if (and points altura (setq conj (ssget "_wp" points '((0 . "CIRCLE"))))) (if (setq ptx (getpoint (strcat "\nPick insertion point for objects number text <" (itoa (sslength conj)) "> (right click or ENTER for skip)..."))) ;;; (vla-AddText (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) (strcat "Count: " (itoa (sslength conj))) (VLAX-3D-POINT ptx) (/ radius 2.0)) (creaMTEXT (strcat "Count:\\P" (itoa (sslength conj))) altura) ) ) (princ) )1 point
-
Such is the problem with cracked programs, they are not worth the price you paid.1 point
-
for creating entities if snapping is going to be a problem I'd use entmake or entmakex to draw what you need - especially a simple one like a circle. Saves worrying about setting system variables and resetting them after. For a count set a variable earlier in the code, say (setq acounter 0). For counting add a (setq acounter (+ acounter 1)) just after you draw the circle (you'll need to add a (progn for the 'if' too)... an easy count of how many circles were drawn1 point
-
Like that (defun c:Circles_Chess_outl (/ oddp ent step radius vlist minx miny maxx maxy x y row pt osmant ) ;;----------------------------------------------- ;; THE FUNCTION OF CHECKING WHETHER THE NUMBER IS ODD ;;----------------------------------------------- (defun oddp (n) (= (logand (fix n) 1) 1) ) ;;----------------------------------------------- ;; Local auxiliary functions ;;----------------------------------------------- ;; Extracting a list of vertices (points) of a linear 2D polyline: (defun getPolyVertices (e / ed lst pts) (setq ed (entget e) ;; selecting all groups of the DXF = 10 code (coordinates of the vertices) lst (vl-remove-if-not '(lambda (x) (= (car x) 10)) ed ) ;; turning them into a regular list of points (x y) pts (mapcar 'cdr lst) ) pts ) ;; Checking whether the pt point is located inside the linear polygon v list: ;;; (defun pointInPolygon (pt vlist / cnt i v1 v2) ;;; (setq cnt 0 ;;; i 0 ;;; ) ;;; ;; "Let's "block" the list so that we can bypass the pair (list[i], list[i+1]): ;;; (setq vlist (append vlist (list (car vlist)))) ;;; (repeat (1- (length vlist)) ;;; (setq v1 (nth i vlist) ;;; v2 (nth (1+ i) vlist) ;;; i (1+ i) ;;; ) ;;; (if (edgeIntersectsRay pt v1 v2) ;;; (setq cnt (1+ cnt)) ;;; ) ;;; ) ;;; ;; If the number of intersections with the ray is odd, the point inside ;;; (if (= (logand cnt 1) 1) ;;; T ;;; nil ;;; ) ;;; ) (defun comprobar_centralidad (pto lst_ptos_rto / pt_inters+ pt_inters- n pt1 pt2 inters_negat inters_posit ) (setq n 0) (repeat (- (length lst_ptos_rto) 1) (setq pt_inters+ (inters pto (list (+ (car pto) 100000) (cadr pto)) (setq pt1 (nth n lst_ptos_rto)) (setq pt2 (nth (+ n 1) lst_ptos_rto)) ) ) (if (and pt_inters+ (not (member (cons 10 pt_inters+) lst_ptos_rto)) ) (if inters_posit (setq inters_posit (+ inters_posit 1)) (setq inters_posit 1) ) ) (setq pt_inters- (inters pto (list (- (car pto) 100000) (cadr pto)) pt1 pt2 ) ) (if (and pt_inters- (not (member (cons 10 pt_inters-) lst_ptos_rto)) ) (if inters_negat (setq inters_negat (+ inters_negat 1)) (setq inters_negat 1) ) ) (setq n (+ n 1)) ) (if (and (= (rem (if (not inters_negat) 0 inters_negat ) 2 ) 0 ) (= (rem (if (not inters_posit) 0 inters_posit ) 2 ) 0 ) ) nil T ) ) ;; Checking the intersection of the horizontal ray to the right of pt with the segment (v1,v2): (defun edgeIntersectsRay (pt v1 v2 / px py x1 y1 x2 y2) (setq px (car pt) py (cadr pt) x1 (car v1) y1 (cadr v1) x2 (car v2) y2 (cadr v2) ) ;; Let's ensure that (x1,y1) is "lower" than (x2,y2): (if (> y1 y2) (progn (setq x1 (car v2) y1 (cadr v2) x2 (car v1) y2 (cadr v1) ) ) ) ;; Intersection condition: (and ;; 1) py is strictly above the lower vertex and not higher than the upper one (> py y1) (<= py y2) ;; 2) px < abscissas of the intersection point of the ray with the segment (defun edgeIntersectsRay (pt v1 v2 / px py x1 y1 x2 y2 intersectX) (setq px (car pt) py (cadr pt) x1 (car v1) y1 (cadr v1) x2 (car v2) y2 (cadr v2) ) ) ;; Let's ensure that (x1,y1) is "lower" than (x2,y2) (if (> y1 y2) (setq x1 (car v2) y1 (cadr v2) x2 (car v1) y2 (cadr v1) ) ) ) ;; Counting the intersection coordinate (setq intersectX (if (/= y2 y1) (+ x1 (* (- py y1) (/ (- x2 x1) (- y2 y1)))) x1 ;; if the segment is horizontal, it is usually skipped. ) ) ;; We are returning (and ...), or nil (and (> py y1) ;; a point above the lower vertex (<= py y2) ;; and no higher than the top (> intersectX px) ) ) ;;----------------------------------------------- ;; the main part ;;----------------------------------------------- (setq ent (car (entsel "\nChoose a closed linear polyline: "))) (if (null ent) (progn (prompt "\nThe polyline is not selected. Completion.") (princ) ) (progn ;; 1) Step Request (setq step (getreal "\nEnter the step between the centers (??): ") ) (if (or (null step) (<= step 0.0)) (setq step 50.0) ;; the "backup" option ) ;; 2) Fixed radius (setq radius 25.0) ;; 3) List of vertices (minimum 3, otherwise not a polygon) (setq vlist (getPolyVertices ent)) (if (< (length vlist) 3) (progn (prompt "\nThe polyline has <3 vertices, and the contour is incorrect." ) (princ) ) (progn ;; 4) Defining bounding box (setq minx (apply 'min (mapcar 'car vlist)) maxx (apply 'max (mapcar 'car vlist)) miny (apply 'min (mapcar 'cadr vlist)) maxy (apply 'max (mapcar 'cadr vlist)) ) (prompt (strcat "\nboundary (bounding box) polyline:\n" " X: " (rtos minx 2 2) " ... " (rtos maxx 2 2) "\n Y: " (rtos miny 2 2) " ... " (rtos maxy 2 2) ) ) ;; 5) Building a grid "in a staggered manner" (setq row 0 y miny ) (setq osmant (getvar "osmode")) (setvar "osmode" 0) (while (<= y maxy) ;; For an odd row row, we shift X by step/2 (if (oddp row) (setq x (+ minx (/ step 2.0))) (setq x minx) ) (while (<= x maxx) (setq pt (list x y)) ;; If the center is inside the polyline, draw a circle. (if (comprobar_centralidad pt vlist) ;(pointInPolygon pt vlist) (command "_.CIRCLE" pt radius) ) (setq x (+ x step)) ) (setq y (+ y step)) (setq row (1+ row)) ) (setvar "osmode" osmant) ) ) ) ) (princ) )1 point
-
Or write at the beginning of the code: (setvar "osmode" 0)1 point
-
As I told you before, turn off object snapping - it looks like it's on with endpoint and midpoint1 point
-
I think you haven't implemented it right. Try this one (defun c:Circles_Chess_outl (/ oddp ent step radius vlist minx miny maxx maxy x y row pt ) ;;----------------------------------------------- ;; THE FUNCTION OF CHECKING WHETHER THE NUMBER IS ODD ;;----------------------------------------------- (defun oddp (n) (= (logand (fix n) 1) 1) ) ;;----------------------------------------------- ;; Local auxiliary functions ;;----------------------------------------------- ;; Extracting a list of vertices (points) of a linear 2D polyline: (defun getPolyVertices (e / ed lst pts) (setq ed (entget e) ;; selecting all groups of the DXF = 10 code (coordinates of the vertices) lst (vl-remove-if-not '(lambda (x) (= (car x) 10)) ed ) ;; turning them into a regular list of points (x y) pts (mapcar 'cdr lst) ) pts ) ;; Checking whether the pt point is located inside the linear polygon v list: ;;; (defun pointInPolygon (pt vlist / cnt i v1 v2) ;;; (setq cnt 0 ;;; i 0 ;;; ) ;;; ;; "Let's "block" the list so that we can bypass the pair (list[i], list[i+1]): ;;; (setq vlist (append vlist (list (car vlist)))) ;;; (repeat (1- (length vlist)) ;;; (setq v1 (nth i vlist) ;;; v2 (nth (1+ i) vlist) ;;; i (1+ i) ;;; ) ;;; (if (edgeIntersectsRay pt v1 v2) ;;; (setq cnt (1+ cnt)) ;;; ) ;;; ) ;;; ;; If the number of intersections with the ray is odd, the point inside ;;; (if (= (logand cnt 1) 1) ;;; T ;;; nil ;;; ) ;;; ) (defun comprobar_centralidad (pto lst_ptos_rto / pt_inters+ pt_inters- n pt1 pt2 inters_negat inters_posit ) (setq n 0) (repeat (- (length lst_ptos_rto) 1) (setq pt_inters+ (inters pto (list (+ (car pto) 100000) (cadr pto)) (setq pt1 (nth n lst_ptos_rto)) (setq pt2 (nth (+ n 1) lst_ptos_rto)) ) ) (if (and pt_inters+ (not (member (cons 10 pt_inters+) lst_ptos_rto)) ) (if inters_posit (setq inters_posit (+ inters_posit 1)) (setq inters_posit 1) ) ) (setq pt_inters- (inters pto (list (- (car pto) 100000) (cadr pto)) pt1 pt2 ) ) (if (and pt_inters- (not (member (cons 10 pt_inters-) lst_ptos_rto)) ) (if inters_negat (setq inters_negat (+ inters_negat 1)) (setq inters_negat 1) ) ) (setq n (+ n 1)) ) (if (and (= (rem (if (not inters_negat) 0 inters_negat ) 2 ) 0 ) (= (rem (if (not inters_posit) 0 inters_posit ) 2 ) 0 ) ) nil T ) ) ;; Checking the intersection of the horizontal ray to the right of pt with the segment (v1,v2): (defun edgeIntersectsRay (pt v1 v2 / px py x1 y1 x2 y2) (setq px (car pt) py (cadr pt) x1 (car v1) y1 (cadr v1) x2 (car v2) y2 (cadr v2) ) ;; Let's ensure that (x1,y1) is "lower" than (x2,y2): (if (> y1 y2) (progn (setq x1 (car v2) y1 (cadr v2) x2 (car v1) y2 (cadr v1) ) ) ) ;; Intersection condition: (and ;; 1) py is strictly above the lower vertex and not higher than the upper one (> py y1) (<= py y2) ;; 2) px < abscissas of the intersection point of the ray with the segment (defun edgeIntersectsRay (pt v1 v2 / px py x1 y1 x2 y2 intersectX) (setq px (car pt) py (cadr pt) x1 (car v1) y1 (cadr v1) x2 (car v2) y2 (cadr v2) ) ) ;; Let's ensure that (x1,y1) is "lower" than (x2,y2) (if (> y1 y2) (setq x1 (car v2) y1 (cadr v2) x2 (car v1) y2 (cadr v1) ) ) ) ;; Counting the intersection coordinate (setq intersectX (if (/= y2 y1) (+ x1 (* (- py y1) (/ (- x2 x1) (- y2 y1)))) x1 ;; if the segment is horizontal, it is usually skipped. ) ) ;; We are returning (and ...), or nil (and (> py y1) ;; a point above the lower vertex (<= py y2) ;; and no higher than the top (> intersectX px) ) ) ;;----------------------------------------------- ;; the main part ;;----------------------------------------------- (setq ent (car (entsel "\nChoose a closed linear polyline: "))) (if (null ent) (progn (prompt "\nThe polyline is not selected. Completion.") (princ) ) (progn ;; 1) Step Request (setq step (getreal "\nEnter the step between the centers (??): ") ) (if (or (null step) (<= step 0.0)) (setq step 50.0) ;; the "backup" option ) ;; 2) Fixed radius (setq radius 25.0) ;; 3) List of vertices (minimum 3, otherwise not a polygon) (setq vlist (getPolyVertices ent)) (if (< (length vlist) 3) (progn (prompt "\nThe polyline has <3 vertices, and the contour is incorrect." ) (princ) ) (progn ;; 4) Defining bounding box (setq minx (apply 'min (mapcar 'car vlist)) maxx (apply 'max (mapcar 'car vlist)) miny (apply 'min (mapcar 'cadr vlist)) maxy (apply 'max (mapcar 'cadr vlist)) ) (prompt (strcat "\nboundary (bounding box) polyline:\n" " X: " (rtos minx 2 2) " ... " (rtos maxx 2 2) "\n Y: " (rtos miny 2 2) " ... " (rtos maxy 2 2) ) ) ;; 5) Building a grid "in a staggered manner" (setq row 0 y miny ) (while (<= y maxy) ;; For an odd row row, we shift X by step/2 (if (oddp row) (setq x (+ minx (/ step 2.0))) (setq x minx) ) (while (<= x maxx) (setq pt (list x y)) ;; If the center is inside the polyline, draw a circle. (if (comprobar_centralidad pt vlist);(pointInPolygon pt vlist) (command "_.CIRCLE" pt radius) ) (setq x (+ x step)) ) (setq y (+ y step)) (setq row (1+ row)) ) ) ) ) ) (princ) )1 point
-
I wouldn't rely on the attribute order, but rather acquire the attribute reference entity using its tag identifier, e.g.: (cond ( (not (setq ent (car (entsel))))) ( (/= "INSERT" (cdr (assoc 0 (setq enx (entget ent))))) (princ "Selected object is not a block.") ) ( (/= 1 (cdr (assoc 66 enx))) (princ "\nSelected block is not attributed.") ) ( (progn (setq att (entnext ent) atx (entget att) ) (while (and (= "ATTRIB" (cdr (assoc 0 atx))) (/= "AREA" (cdr (assoc 2 atx)))) (setq att (entnext att) atx (entget att) ) ) (= "SEQEND" (cdr (assoc 0 atx))) ) (princ "\nAREA attribute not found in selected block.") ) ( (LM:fieldobjects att) ) )1 point
-
@pkenewell its going to be 38c tomorrow, here in AUS, so going down the beach. Mind you they say thunderstorms will hits us in the afternoon. So we may get flooding, we are in our fire season I have bushland near my home so keep watch of what is going on. After California fires pointed out you have to be prepared.1 point
-
This is another that could be used as a start point just work out max rows and columns rather than enter. ; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/rectangular-array-creating-every-other-row-offset/td-p/9667120 ; array rows a 1/2 x spacings ; Enter -ve values to change direction. ;By AlanH info@alanh.com.au Aug 2020 (defun c:zigzag ( / ent ss ans hor ver numx numy x ) (setq ent (entsel "\nSelect object to array")) (setq ss (ssadd)) (ssadd (car ent) ss) (if (not AH:getvalsm)(load "Multi Getvals.lsp")) (setq ans (AH:getvalsm (list "Enter spacings " "Horizontal " 5 4 "100" "Vertical" 5 4 "50" "Num X " 5 4 "3" "Num Y" 5 4 "3"))) (setq hor (atof (nth 0 ans))) (setq ver (atof (nth 1 ans))) (setq numx (atoi (nth 2 ans))) (setq numy (atoi (nth 3 ans))) (setq x 1.0) (repeat (- numx 1) (command "copy" ent "" (list 0.0 0.0) (list (* x hor) 0.0) ) (ssadd (entlast) ss) (setq x (+ x 1)) ) (setq x 1.0) (while (< x numy) (command "copy" ss "" (list 0.0 0.0) (list (* 0.5 (- hor)) (* x ver))) (setq x (+ x 2)) ) (setq x 2.0) (while (< x numy) (command "copy" ss "" (list 0.0 0.0) (list 0.0 (* ver x))) (setq x (+ x 2)) ) (princ) ) (c:zigzag) Multi GETVALS.lsp1 point
-
Circles are created with 'command': this means that they are object-snap sensitive. Always turn off object-snap to avoid undesired results. Or modify your code to turn off object-snap at the beginning of code execution.1 point
-
Your 'pointInPolygon' function is not working as expected. I suggest you replace it with this one: (defun comprobar_centralidad (pto lst_ptos_rto / pt_inters+ pt_inters- n pt1 pt2 inters_negat inters_posit ) (setq n 0) (repeat (- (length lst_ptos_rto) 1) (setq pt_inters+ (inters pto (list (+ (car pto) 100000) (cadr pto)) (setq pt1 (nth n lst_ptos_rto)) (setq pt2 (nth (+ n 1) lst_ptos_rto)) ) ) (if (and pt_inters+ (not (member (cons 10 pt_inters+) lst_ptos_rto)) ) (if inters_posit (setq inters_posit (+ inters_posit 1)) (setq inters_posit 1) ) ) (setq pt_inters- (inters pto (list (- (car pto) 100000) (cadr pto)) pt1 pt2 ) ) (if (and pt_inters- (not (member (cons 10 pt_inters-) lst_ptos_rto)) ) (if inters_negat (setq inters_negat (+ inters_negat 1)) (setq inters_negat 1) ) ) (setq n (+ n 1)) ) (if (and (= (rem (if (not inters_negat) 0 inters_negat ) 2 ) 0 ) (= (rem (if (not inters_posit) 0 inters_posit ) 2 ) 0 ) ) nil T ) )1 point