Guest Posted March 17, 2015 Share Posted March 17, 2015 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 Quote Link to comment Share on other sites More sharing options...
hmsilva Posted March 17, 2015 Share Posted March 17, 2015 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 Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted March 17, 2015 Share Posted March 17, 2015 Here, download attachment from this link, but I strongly suggest that you read whole topic and view all attachments... http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/select-rectangles-to-change-their-lenths-and-widths-at-once/m-p/5481233/highlight/true#M329296 HTH, M.R. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted March 17, 2015 Share Posted March 17, 2015 I think creating a Dynamic Block with width and length parameters would be the best solution to go through . Quote Link to comment Share on other sites More sharing options...
ROBP Posted March 17, 2015 Share Posted March 17, 2015 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 Quote Link to comment Share on other sites More sharing options...
Guest Posted March 18, 2015 Share Posted March 18, 2015 Thank you all , I use hmsilva code Thanks hmsilva Quote Link to comment Share on other sites More sharing options...
Tharwat Posted March 18, 2015 Share Posted March 18, 2015 @ Henrique You have set the width of the polyline two times . Quote Link to comment Share on other sites More sharing options...
Guest Posted March 18, 2015 Share Posted March 18, 2015 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) ) Quote Link to comment Share on other sites More sharing options...
Tharwat Posted March 18, 2015 Share Posted March 18, 2015 Yes my final code is this Is it your codes to call it *my* ? Quote Link to comment Share on other sites More sharing options...
Guest Posted March 18, 2015 Share Posted March 18, 2015 Come on Tharwat don't play with the words. Is the final code ok!! Quote Link to comment Share on other sites More sharing options...
hmsilva Posted March 18, 2015 Share Posted March 18, 2015 @ HenriqueYou 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 Quote Link to comment Share on other sites More sharing options...
hmsilva Posted March 18, 2015 Share Posted March 18, 2015 Thanks hmsilva You're welcome, prodromosm! Just remove the (setvar "plinewid" 0.0) from the code... Henrique 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.