Jump to content

Recommended Posts

Posted

I am trying to write a lisp to draw rectangle from center point

 

I use this lisp for giving the scale to all my lisp codes

( DEFUN C:SETSC ()
 (COMMAND "_PDMODE" "32"); point style
 (COMMAND "_PDSIZE" "0.5");point size
 (setvar "OSMODE" 
   (SETQ CURSC (getvar "useri1" ))
   (princ "scale is 1:")(princ cursc)
   (setq newsc (getint "\nNew scale  1:"))
   (setvar "useri1" newsc)
     (setq a1 (getvar "useri1"))
     (princ "\n the new scale is 1:")(princ newsc)(princ)
)

 

This is the rectangle lisp

 

(defun C:test()
(setvar "cmdecho" 0)
(COMMAND "_layer" "_m" "rectangle" "_c" "3" "" "_lw" "0.30" "" "")
(setq scl (getvar "useri1"))
(setq ht (* 0.09 scl))
ptc (GETPOINT "\nPick Center Of Rectangle : ")
hxy (/ ht 2.0)
ptll (list (- (car ptc) hxy) (- (cadr ptc) hxy))
ptur (list (+ (car ptll) ht) (+ (cadr ptll) ht))
(setvar "plinewid" 0.0)
(command ".PLINE" ptll "W" "0" "0" ".X" ptur ".Y" ptll ptur ".X" ptll ".Y" ptur "C" "")
(princ)
)

 

The problem with this lisp is that the first time works fine. When i try to pick another point to draw me the rectangle then draws again a new rectangle over the previous :? I don;t know why. Can any one help me ...

 

Thanks

Posted

Perhaps something like this

 

(defun C:test ( / echo ht ptc ptll ptur scl)
 (if (and (setq scl (getvar "useri1"))
          (not (zerop scl))
          (setq ptc (getpoint "\nPick Center Of Rectangle : "))
     )
   (progn
     (setq echo (getvar 'CMDECHO))
     (setvar "cmdecho" 0)
     (command "_layer" "_m" "rectangle" "_c" "3" "" "_lw" "0.30" "" "")
     (setq ht   (* 0.09 scl)
           hxy  (/ ht 2.0)
           ptll (list (- (car ptc) hxy) (- (cadr ptc) hxy))
           ptur (list (+ (car ptll) ht) (+ (cadr ptll) ht))
     )
     (setvar "plinewid" 0.0)
     (command ".PLINE" ptll "W" "0" "0" ".X" ptur ".Y" ptll ptur ".X" ptll ".Y" ptur "C")
     (setvar "cmdecho" echo)
   )
 )
 (princ)
)

 

Henrique

Posted

I think creating a Dynamic Block with width and length parameters would be the best solution to go through .

Posted
I am trying to write a lisp to draw rectangle from center point

 

I use this lisp for giving the scale to all my lisp codes

( DEFUN C:SETSC ()
 (COMMAND "_PDMODE" "32"); point style
 (COMMAND "_PDSIZE" "0.5");point size
 (setvar "OSMODE" 
   (SETQ CURSC (getvar "useri1" ))
   (princ "scale is 1:")(princ cursc)
   (setq newsc (getint "\nNew scale  1:"))
   (setvar "useri1" newsc)
     (setq a1 (getvar "useri1"))
     (princ "\n the new scale is 1:")(princ newsc)(princ)
)

 

This is the rectangle lisp

 

(defun C:test()
(setvar "cmdecho" 0)
(COMMAND "_layer" "_m" "rectangle" "_c" "3" "" "_lw" "0.30" "" "")
(setq scl (getvar "useri1"))
(setq ht (* 0.09 scl))
ptc (GETPOINT "\nPick Center Of Rectangle : ")
hxy (/ ht 2.0)
ptll (list (- (car ptc) hxy) (- (cadr ptc) hxy))
ptur (list (+ (car ptll) ht) (+ (cadr ptll) ht))
(setvar "plinewid" 0.0)
(command ".PLINE" ptll "W" "0" "0" ".X" ptur ".Y" ptll ptur ".X" ptll ".Y" ptur "C" "")
(princ)
)

 

The problem with this lisp is that the first time works fine. When i try to pick another point to draw me the rectangle then draws again a new rectangle over the previous :? I don;t know why. Can any one help me ...

 

Thanks

 

http://en.lmgtfy.com/?q=mprec.lsp

Posted

@ Henrique

 

You have set the width of the polyline two times . ;)

Posted

Yes my final code is this

 

(defun C:RCC (/ echo wide high ptc ptll ptur scl)
 (if (and (setq scl (getvar "useri1"))
          (not (zerop scl))
          (setq ptc (getpoint "\nPick Center Of Rectangle : "))
     )
   (progn
     (setq echo (getvar 'CMDECHO))
     (setvar "cmdecho" 0)
     (command "_layer" "_m" "exasf" "_c" "3" """")
     (setq wide (* 0.0894 scl)
           high (* 0.08975 scl)
           hwide (/ wide 2.0)
           hhigh (/ high 2.0)
           ptll (list (- (car ptc) hwide) (- (cadr ptc) hhigh))
           ptur (list (+ (car ptll) wide) (+ (cadr ptll) high))
     )
     (setvar "plinewid" 0.0)
     (command ".PLINE" ptll "W" "0" "0" ".X" ptur ".Y" ptll ptur ".X" ptll ".Y" ptur "C")
     (setvar "cmdecho" echo)
   )
 )
 (princ)
)

Posted
Yes my final code is this

 

Is it your codes to call it *my* ?

Posted

Come on Tharwat don't play with the words. Is the final code ok!!

Posted
@ Henrique

You have set the width of the polyline two times . ;)

 

 

It's the OP code, I did formatted the original code...

But you are correct, there is no need to set the width with setvar... :)

 

Henrique

Posted

Thanks hmsilva

You're welcome, prodromosm!

Just remove the

(setvar "plinewid" 0.0)

from the code...

 

Henrique

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