Jump to content

Problem With Trans Function


satishrajdev

Recommended Posts

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

Trans01.JPG

Link to comment
Share on other sites

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 by marko_ribar
missed to input (cdr (assoc 38 (entget rec))) as Z coordinate of cen variable
Link to comment
Share on other sites

It is giving weird result, Circles are getting drawn at wrong place... Can you please test it with my drawing

Link to comment
Share on other sites

(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)
)

Link to comment
Share on other sites

@ marko_ribar:

The use of the trans function is superfluous here:

(setq cen (trans ... rec 0))
...
(cons 10 (trans cen 0 rec))

Link to comment
Share on other sites

(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 :shock:

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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