Jump to content

How to get rectangs center--Rectangs change to circles(circle can assign size)


Recommended Posts

Posted

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!! :cry:

Posted

Please check the INTERS function; use rectangle's corners as arguments.

(inters corner1st corner3rd corner2nd corner4th)

Posted (edited)
Removed due to ignorance from the OP

Edited by Tharwat
Posted
(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

Posted
Please check the INTERS function; use rectangle's corners as arguments.

(inters corner1st corner3rd corner2nd corner4th)

 

Can you give me some example??

Posted

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)

Posted

It is good choice that can use PEDIT but this circle can't change size.

Anyway I learn a new way.Thanks a lot!!:shock:

 

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

Posted

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.:oops:

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)

Posted
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

Posted

That is true, I really can understand how to use "PEDIT" for my needed.:P

Thanks for your suggetion, I will try to learn more.:D

 

 

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

Posted

I will try to learn more.:D

me too, learning is endless be happy coding :)

Posted
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.

Posted

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.

Posted

You're welcome, Rain0923! Good luck in your learning.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...