Jump to content

Wierdness with rectangle command


DavidgGBS

Recommended Posts

I have the following code to draw a fixed-width rectangle with the length of a given line:

(command "RECTANGLE" (list (car start)                          (- (cadr start) 0.33))
             (list (+ (car start) (distance start end)) (+ (cadr start) 0.33)))

For some reason, though, the rectangles are starting at the line's start point rather than 0.33 units lower. My X and Y values are in the millions, in case that helps identify it as an overflow error.

Link to comment
Share on other sites

Try to take this code as basic,

then add your changes to the variables


(defun C:MREC (/ dxf ang ang+  dis elist em_list end ln  pi_2 pts 
pt_lr pt_ur  start)

(defun dxf (key alist)(cdr (assoc key 
alist)))

(while
(setq ln (entsel "\nSelect line: 
"))
     (progn
(setq ln (car 
ln)
      elist (entget 
ln)
      start (dxf 10 
elist)
      end (dxf 11 
elist)
      ang (angle start 
end)
      dis (distance start 
end)
      pi_2 (/ pi 
2.0)
      ang+    (+ ang 
pi_2)
pt_ur    (polar end ang+ 
dis)
pt_lr   (polar start ang+ 
dis))
      (setq pts (mapcar '(lambda(p)(list 
(car p) (cadr p)))
 (mapcar '(lambda(q) (trans q 1 0))(list start 
end pt_ur pt_lr))))


(setq em_list
  (append 

(list 
     '(0 . 
"LWPOLYLINE") 
     '(100 . 
"AcDbEntity") 
     '(100 . 
"AcDbPolyline")    
     ;(cons 
8 "0"))
     (cons 90 (length 
pts)) 
     (cons 70 
1)     
  )
 (mapcar '(lambda 
(p) (list 10 (car p) (cadr p)))pts)


)
  )


  (if (entmake em_list)
(entupd 
(entlast))
)
)
)
(princ)
 )

Link to comment
Share on other sites

This works fine for me:

;; <snip>
(if (and (setq start (trans (getpoint) 1 0))
        (not (initget 32))
        (setq end (trans (getpoint start) 1 0))
   )
 (command "RECTANGLE"
          (list (setq x (car start))
                (- (setq y (cadr start)) 0.33)
                (last start)
          )
          (list (+ x (distance start end)) (+ y 0.33) (last end))
 )
)
;; <snip>

 

** TRANS not required.

Link to comment
Share on other sites

But maybe off snap is required with the command call ! :lol:

 

You mean "_non"? Sure if you like.

 

[Edit] - Again, not required... The first point is the CENter of a circle.... Sorry, wrong thread.

Edited by BlackBox
Link to comment
Share on other sites

Sorry for my stupidity, perhaps like this


(if (and (setq start (trans (getpoint) 1 
0))
         (not (initget 
32))
         (setq end (trans 
(getpoint start) 1 0))
    )
 
(progn
  (command 
"RECTANGLE"
           
"_non" (list (setq x (car 
start))
                 
(- (setq y (cadr start)) 
0.33)
                 
(last 
start)
           
)
           
"_non"(list (+ x (distance start end)) (+ y 0.33) (last end))
  
)
 (command "_rotate" "L" "" "_non" start (/ (* (angle start end) 180) 
pi)))
)

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