satishrajdev Posted June 24, 2016 Share Posted June 24, 2016 Hi, I not regularly use trans function in my routine, so quite new to understand this functions behavior. I have attached drawing contains two rectangles with at different planes or you can say UCS. I want to draw circle at the centroid of that rectangle, I have already mark centroid of that rectangles. Can anyone provide help with sample code? Test for Trans.dwg Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted June 24, 2016 Share Posted June 24, 2016 Do you want to draw circles or (entmake/entmakex) them? Quote Link to comment Share on other sites More sharing options...
satishrajdev Posted June 24, 2016 Author Share Posted June 24, 2016 I want to draw circles in that rectangle using entmake function Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted June 24, 2016 Share Posted June 24, 2016 (edited) Not tested : (defun c:cirec ( / s rec cen ) (prompt "\nPick rectangle...") (setq s (ssget "_+.:E:S" (list '(0 . "LWPOLYLINE") '(90 . 4) '(-4 . "<or") '(70 . 1) '(70 . 129) '(-4 . "or>")))) (while (or (not s) (not (vl-every '(lambda ( x ) (= (cdr x) 0.0)) (vl-remove-if-not '(lambda ( x ) (= (car x) 42)) (entget (ssname s 0)))))) (prompt "\nEmpty sel.set or picked LWPOLYLINE not polygonal - has arced segments... Retry selection pick again...") (setq s (ssget "_+.:E:S" (list '(0 . "LWPOLYLINE") '(90 . 4) '(-4 . "<or") '(70 . 1) '(70 . 129) '(-4 . "or>")))) ) (setq rec (ssname s 0)) (setq cen (trans (list (/ (+ (car (cdr (assoc 10 (entget rec)))) (car (cdr (assoc 10 (cdr (member (assoc 10 (cdr (member (assoc 10 (entget rec)) (entget rec)))) (entget rec))))))) 2.0) (/ (+ (cadr (cdr (assoc 10 (entget rec)))) (cadr (cdr (assoc 10 (cdr (member (assoc 10 (cdr (member (assoc 10 (entget rec)) (entget rec)))) (entget rec))))))) 2.0) (cdr (assoc 38 (entget rec)))) rec 0)) (entmake (list '(0 . "CIRCLE") '(100 . "AcDbEntity") '(100 . "AcDbCircle") (cons 8 "YourLayer") ;; <- change (cons 10 (trans cen 0 rec)) (cons 40 10.0) ;; <- change radius you want '(62 . 1) ;; <- change color from red to what you want or remove this line (assoc 210 (entget rec)) ) ) (princ) ) [EDIT : The code was tested and modified...] Edited June 24, 2016 by marko_ribar missed to input (cdr (assoc 38 (entget rec))) as Z coordinate of cen variable Quote Link to comment Share on other sites More sharing options...
satishrajdev Posted June 24, 2016 Author Share Posted June 24, 2016 It is giving weird result, Circles are getting drawn at wrong place... Can you please test it with my drawing Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted June 24, 2016 Share Posted June 24, 2016 I see it... It's now fine... HTH, M.R. Quote Link to comment Share on other sites More sharing options...
satishrajdev Posted June 24, 2016 Author Share Posted June 24, 2016 Wow....thanks a lot... really appreciated your effort Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 24, 2016 Share Posted June 24, 2016 (defun c:ccen ( / e i l s ) (if (setq s (ssget '((0 . "LWPOLYLINE") (90 . 4) (-4 . "&=") (70 . 1) (-4 . "<NOT") (-4 . "<>") (42 . 0.0) (-4 . "NOT>")))) (repeat (setq i (sslength s)) (setq e (entget (ssname s (setq i (1- i)))) l (apply 'mapcar (cons '+ (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) e))) ) (entmake (list '(000 . "CIRCLE") '(040 . 100.0) (append (mapcar '/ l '(4 4.0 4.0)) (list (cdr (assoc 38 e)))) (assoc 210 e) ) ) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
Roy_043 Posted June 24, 2016 Share Posted June 24, 2016 @ marko_ribar: The use of the trans function is superfluous here: (setq cen (trans ... rec 0)) ... (cons 10 (trans cen 0 rec)) Quote Link to comment Share on other sites More sharing options...
satishrajdev Posted June 24, 2016 Author Share Posted June 24, 2016 (defun c:ccen ( / e i l s ) (if (setq s (ssget '((0 . "LWPOLYLINE") (90 . 4) (-4 . "&=") (70 . 1) (-4 . "<NOT") (-4 . "<>") (42 . 0.0) (-4 . "NOT>")))) (repeat (setq i (sslength s)) (setq e (entget (ssname s (setq i (1- i)))) l (apply 'mapcar (cons '+ (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) e))) ) (entmake (list '(000 . "CIRCLE") '(040 . 100.0) (append (mapcar '/ l '(4 4.0 4.0)) (list (cdr (assoc 38 e)))) (assoc 210 e) ) ) ) ) (princ) ) Lee Sir, That was brilliant Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 24, 2016 Share Posted June 24, 2016 Lee Sir, That was brilliant Thank you Satish Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted June 24, 2016 Share Posted June 24, 2016 @ marko_ribar:The use of the trans function is superfluous here: (setq cen (trans ... rec 0)) ... (cons 10 (trans cen 0 rec)) Roy I know that, I only wanted to show to OP how (trans) can be used... I tend to convert points from OCS to WCS, then perform desired calculations with them and if its necessary (trans)late them back to OCS... Beside that using (vlax-curve-*) functions always return WCS coordinates, so better use to manipulate with WCS points and terms and code for such situations where you can't for sure rely on OCSs before you make desired (trans)lations... 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.