Rain0923 Posted November 4, 2014 Share Posted November 4, 2014 I try to write the lisp about rectangs change to circles(circle can assign size) but I do not know how to write to get rectangs center. Have anyone help??Thanks a lot!! Quote Link to comment Share on other sites More sharing options...
MSasu Posted November 4, 2014 Share Posted November 4, 2014 Please check the INTERS function; use rectangle's corners as arguments. (inters corner1st corner3rd corner2nd corner4th) Quote Link to comment Share on other sites More sharing options...
Tharwat Posted November 4, 2014 Share Posted November 4, 2014 (edited) Removed due to ignorance from the OP Edited November 5, 2014 by Tharwat Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted November 4, 2014 Share Posted November 4, 2014 (circle can assign size) i hope OP can understand simple & easier code which simply using command PEDIT ;;;rectang-> circle (defun c:test (/ p e r c ) ;hanhphuc (if (and (setq e (car (entsel))) (=(cdr (assoc 0 (entget e)))"LWPOLYLINE") (vl-cmdf "_.PEDIT" e "fit" "") (setq c (entsel "\nPick circle to modify radius.. ")) (setq p (osnap (cadr c) "_cen")) (vl-cmdf "_.PEDIT" e "decurve" "") (setq r ([color="blue"]getdist[/color] p "\nRadius.. ")) ) ;_ end of and (command "_.CIRCLE" p r) ) ;_ end of if (princ) ) ;_ end of defun Quote Link to comment Share on other sites More sharing options...
Rain0923 Posted November 4, 2014 Author Share Posted November 4, 2014 Please check the INTERS function; use rectangle's corners as arguments. (inters corner1st corner3rd corner2nd corner4th) Can you give me some example?? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 4, 2014 Share Posted November 4, 2014 Here's another example, using the rectangular bounding box of the polyline vertices: (defun c:p2c ( / a b e i l s ) (if (setq s (ssget "_:L" '((0 . "LWPOLYLINE")))) (repeat (setq i (sslength s)) (setq e (entget (ssname s (setq i (1- i)))) l (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) e)) a (apply 'mapcar (cons 'min l)) b (apply 'mapcar (cons 'max l)) ) (if (entmake (append '((0 . "CIRCLE")) (LM:defaultprops e) (list (cons 010 (mapcar '/ (mapcar '+ a b) '(2 2))) (cons 040 (/ (distance a b) 2)) (assoc 210 e) ) ) ) (entdel (cdr (assoc -1 e))) ) ) ) (princ) ) ;; Default Properties - Lee Mac ;; Returns a list of DXF properties for the supplied DXF data, ;; substituting default values for absent DXF groups (defun LM:defaultprops ( enx ) (mapcar '(lambda ( x ) (cond ((assoc (car x) enx)) ( x ))) '( (006 . "BYLAYER") (008 . "0") (039 . 0.0) (048 . 1.0) (062 . 256) (370 . -1) ) ) ) (princ) Quote Link to comment Share on other sites More sharing options...
Rain0923 Posted November 5, 2014 Author Share Posted November 5, 2014 It is good choice that can use PEDIT but this circle can't change size. Anyway I learn a new way.Thanks a lot!! i hope OP can understand simple & easier code whichsimply using command PEDIT ;;;rectang-> circle (defun c:test (/ p e r c ) ;hanhphuc (if (and (setq e (car (entsel))) (=(cdr (assoc 0 (entget e)))"LWPOLYLINE") (vl-cmdf "_.PEDIT" e "fit" "") (setq c (entsel "\nPick circle to modify radius.. ")) (setq p (osnap (cadr c) "_cen")) (vl-cmdf "_.PEDIT" e "decurve" "") (setq r ([color=blue]getdist[/color] p "\nRadius.. ")) ) ;_ end of and (command "_.CIRCLE" p r) ) ;_ end of if (princ) ) ;_ end of defun Quote Link to comment Share on other sites More sharing options...
Rain0923 Posted November 5, 2014 Author Share Posted November 5, 2014 It is good example for me. I just learn lisp recently and no one can teach me , I tried to write the same lisp but I can't success . It really difficult to me. Thanks for your share...... Here's another example, using the rectangular bounding box of the polyline vertices: (defun c:p2c ( / a b e i l s ) (if (setq s (ssget "_:L" '((0 . "LWPOLYLINE")))) (repeat (setq i (sslength s)) (setq e (entget (ssname s (setq i (1- i)))) l (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) e)) a (apply 'mapcar (cons 'min l)) b (apply 'mapcar (cons 'max l)) ) (if (entmake (append '((0 . "CIRCLE")) (LM:defaultprops e) (list (cons 010 (mapcar '/ (mapcar '+ a b) '(2 2))) (cons 040 (/ (distance a b) 2)) (assoc 210 e) ) ) ) (entdel (cdr (assoc -1 e))) ) ) ) (princ) ) ;; Default Properties - Lee Mac ;; Returns a list of DXF properties for the supplied DXF data, ;; substituting default values for absent DXF groups (defun LM:defaultprops ( enx ) (mapcar '(lambda ( x ) (cond ((assoc (car x) enx)) ( x ))) '( (006 . "BYLAYER") (008 . "0") (039 . 0.0) (048 . 1.0) (062 . 256) (370 . -1) ) ) ) (princ) Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted November 5, 2014 Share Posted November 5, 2014 It is good choice that can use PEDIT but this circle can't change size!! Invoke program -> Pick the entity the circle is polyline -> then pick the entity again, it will prompt you to modify radius or osnap If you want to learn coding, I suggest you study Tharwat & Lee's code [edit] I use PEDIT just bcos you are newbie so just make it simpler Quote Link to comment Share on other sites More sharing options...
Rain0923 Posted November 5, 2014 Author Share Posted November 5, 2014 That is true, I really can understand how to use "PEDIT" for my needed. Thanks for your suggetion, I will try to learn more. Invoke program -> Pick the entity the circle is polyline -> then pick the entity again, it will prompt you to modify radius or osnap If you want to learn coding, I suggest you study Tharwat & Lee's code [edit] I use PEDIT just bcos you are newbie so just make it simpler Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted November 5, 2014 Share Posted November 5, 2014 I will try to learn more. me too, learning is endless be happy coding Quote Link to comment Share on other sites More sharing options...
MSasu Posted November 5, 2014 Share Posted November 5, 2014 Can you give me some example?? To ilustrate my suggestion, please find an example with comments: (if (setq ssetPLine (ssget "_:S:E" '((0 . "LWPOLYLINE")))) ;ask user to select a polyline (progn (setq listPLine (entget (ssname ssetPLine 0)) ;retrive entity's list listCorners '()) (while (setq listPLine (member (assoc 10 listPLine) listPLine)) ;cycle until all vertexes (corners) were found (setq listCorners (cons (cdar listPLine) ;and retain them in a list listCorners) listPLine (cdr listPLine)) ;skip first entry to allow locating next vertex ) (print (inters (nth 0 listCorners) (nth 2 listCorners) ;get intersection of diagonals (nth 1 listCorners) (nth 3 listCorners))) ) ) Please note that the above works for rectangles only; you will need later to add a SSGET filter (please check Tharwat's code) or a post-selection validation. Quote Link to comment Share on other sites More sharing options...
Rain0923 Posted November 6, 2014 Author Share Posted November 6, 2014 It's so goooood to me, Thanks for your explained:D To ilustrate my suggestion, please find an example with comments: (if (setq ssetPLine (ssget "_:S:E" '((0 . "LWPOLYLINE")))) ;ask user to select a polyline (progn (setq listPLine (entget (ssname ssetPLine 0)) ;retrive entity's list listCorners '()) (while (setq listPLine (member (assoc 10 listPLine) listPLine)) ;cycle until all vertexes (corners) were found (setq listCorners (cons (cdar listPLine) ;and retain them in a list listCorners) listPLine (cdr listPLine)) ;skip first entry to allow locating next vertex ) (print (inters (nth 0 listCorners) (nth 2 listCorners) ;get intersection of diagonals (nth 1 listCorners) (nth 3 listCorners))) ) ) Please note that the above works for rectangles only; you will need later to add a SSGET filter (please check Tharwat's code) or a post-selection validation. Quote Link to comment Share on other sites More sharing options...
MSasu Posted November 6, 2014 Share Posted November 6, 2014 You're welcome, Rain0923! Good luck in your learning. Quote Link to comment Share on other sites More sharing options...
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.