plecs Posted March 8, 2015 Posted March 8, 2015 Thanks in advance for your help. lisp fail to bring in all the applications I need, but I leyer select the polyline and make a list of all points and the radius containing polyline close (defun c:test1 ( ); / e i n s x (if (setq s (ssget "x" '((0 . "LWPOLYLINE")(8 . "DDD")))) (progn (setq i 0 n (sslength s) ) (while (< i n) (setq e (ssname s i) x (cdr (assoc 10 (entget e))) i (1+ i) ) (print x) );end wile );end progn );end if (princ) );end defun I found the code below but I realize not be changed to help me I need that I give my points polyline arc radius close but not if it contains (defun getPolySegs (/ ent entl p1 pt bulge seg ptlst) (setvar "ERRNO" 0) ;; repeat request for polyline until user either picks ;; a polyline or exits without picking (while (and (not ent) (/= (getvar "ERRNO") 52)) (if (and (setq ent (car (entsel "\nSelect polyline: "))) (/= (cdr (assoc 0 (setq entl (entget ent)))) "LWPOLYLINE") ) (setq ent nil) ) ); end while (cond (ent ;; save start point if polyline is closed (if (= (logand (cdr (assoc 70 entl)) 1) 1) (setq p1 (cdr (assoc 10 entl))) ) ;; run thru entity list to collect list of segments (while (setq entl (member (assoc 10 entl) entl)) ;; if segment then add to list (if (and pt bulge) (setq seg (list pt bulge)) ); end if ;; save next point and bulge (setq pt (cdr (assoc 10 entl)) bulge (cdr (assoc 42 entl)) ) ;; if segment is build then add last point to segment ;; and add segment to list (if seg (setq seg (append seg (list pt)) ptlst (cons seg ptlst)) ); end if ;; reduce list and clear temporary segment (setq entl (cdr entl) seg nil ) ); end while ) ); end cond ;; if polyline is closed then add closing segment to list (if p1 (setq ptlst (cons (list pt bulge p1) ptlst))) ;; reverse and return list of segments (reverse ptlst) ); end defun And I also found lisp routine , list radius but no points (defun getArcInfo (segment / a p1 bulge p2 c c|2 gamma midp p phi r r2 s theta) ;; assign variables to values in argument (mapcar 'set '(p1 bulge p2) segment) ;; find included angle ;; remember that bulge is negative if drawn clockwise (setq theta (* 4.0 (atan (abs bulge)))) ;; output included angle (princ (strcat "\n Included angle: " (rtos theta)" rad ("(angtos theta 0)" degrees)")) ;; find height of the arc (setq c (distance p1 p2) s (* (/ c 2.0) (abs bulge))) ;; output height of arc (princ (strcat "\n Height of arc: " (rtos s))) ;; output chord length (princ (strcat "\n Chord length: " (rtos c))) ;; If this function is used without making sure that the segment ;; is not simply a line segment (bulge = 0.0), it will produce ;; a division-by-zero error in the following. Therefore we want ;; to be sure that it doesn't process line segments. (cond ((not (equal bulge 0.0 1E-6)) ;; find radius of arc ;; first find half the chord length (setq c|2 (/ c 2.0) ;; find radius with Pythagoras (used as output) r (/ (+ (expt c|2 2.0) (expt s 2.0)) (* s 2.0)) ;; find radius with trigonometry r2 (/ c|2 (sin (/ theta 2.0))) ) (princ (strcat "\n Radius of arc: " (rtos r))) ;; find center point of arc with angle arithmetic ;; (used as output) (setq gamma (/ (- pi theta) 2.0) phi (if (>= bulge 0) (+ (angle p1 p2) gamma) (- (angle p1 p2) gamma) ) p (polar p1 phi r) ) ;; find center point of arc with Pythagoras (setq a (sqrt (- (expt r 2.0) (expt c|2 2.0))) midp (polar p1 (angle p1 p2) c|2) p2 (if (>= bulge 0) (polar midp (+ (angle p1 p2) (/ pi 2.0)) a) (polar midp (- (angle p1 p2) (/ pi 2.0)) a) ) ) ;; output coordinates of center point (princ (strcat "\n Center of arc: "(rtos (car p))","(rtos (cadr p)))) ) (T (princ "\n Segment has no arc info")) ) (princ) ) (defun c:POLYARCS (/ a polysegs seg) ;; make a list of polyline segments of a ;; selected polyline (cond ((setq polysegs (getPolySegs)) ;; a is just an informative counter (setq a 0) ;; run thru each segment (foreach seg polysegs (setq a (1+ a)) ;; only process the segment if it's an arc ;; i.e. bulge /= 0.0 (cond ((not (zerop (cadr seg))) (princ (strcat "\nSegment " (itoa a) ": ")) ;; (getArcInfo seg) ) ) ) ) ) ) but fail to put them in one lisp to do what all together, I need to give me a lisp that all points and radius, all close polyline in a list Quote
BIGAL Posted March 8, 2015 Posted March 8, 2015 Just add another defun as per code below VLISP supports 'Coordinates as a property just like length and area. (defun plcords (/ ent obj plobs ) (vla-load-com) (defun getcoords (ent) (vlax-safearray->list (vlax-variant-value (vlax-get-property (vlax-ename->vla-object ent) "Coordinates" ) ) ) ) (defun co-ords2xy ( / I) ; convert now to a list of xy as co-ords are x y x y x y if 3d x y z x y z (setq numb (/ (length co-ords) 2)) (setq I 0) (repeat numb (setq xy (list (nth (+ I 1) co-ords)(nth I co-ords) )) (setq coordsxy (cons xy coordsxy)) (setq I (+ I 2)) ) ; end repeat ) (setq plobjs (ssget (list (cons 0 "lwpolyline")))) (setq numb1 (sslength plobjs)) (setq x numb1) (repeat numb1 (setq obj (ssname plobjs (setq x (- x 1)))) (setq co-ords (getcoords obj)) ) (co-ords2xy) (setq inc (length coordsxy)) (repeat (/ inc 2) (setq x (rtos (nth (setq inc (- inc 1)) co-ords) 2 3 )) (setq y (rtos (nth (setq inc (- inc 1)) co-ords) 2 3 )) (setq xy (strcat x "," y )) (princ xy) (princ "\n ") ) ) (plcords) 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.