CadFrank Posted August 15, 2012 Share Posted August 15, 2012 Hi, I am writting this code and I'm having a problem with it (defun NouveauCalque () (Command "_layer" "_n" "-LU BOIS" "_C" "41" "-LU BOIS" "" "") (Command "_layer" "_n" "-LU CONTREPLAQUÉ" "_C" "40" "-LU CONTREPLAQUÉ" "" "") ) (defun c:cofp (/ rep pt1 pt2 os blc1 blc2 blc3 rec1 rec2 rec3) (setq pt1 (getpoint "\nPointez le bas de la poutre ! ")) (setq pt2 (getpoint "\nPointer le haut de la poutre ! ")) (setq os (getvar 'OSMODE)) (setvar 'OSMODE 0) (bois) (initget 1 "G D") (setq rep (getkword "\nChoisir un côté de poutre [Gauche/Droite] ")) (if (= rep "G") (progn (setq pt3 (list (- (car pt2) 20) (- (cadr pt2) 20))) (setq pt4 (list (- (car pt1) 20) (cadr pt1))) (setq pt5 (list (- (car pt4) 90) (+ (cadr pt4) 20))) (setq pt6 (list (- (car pt4) 90) (cadr pt4))) (setq pt7 (list (car pt3) (- (cadr pt3) 38))) (setq pt8 (list (car pt3) (- (cadr pt3) 76))) (command "_insert" "2x4" pt6 "" "1" "") (setq blc1 (entlast)) (command "_insert" "2x4" pt7 "" "1" "") (setq blc2 (entlast)) (command "_insert" "2x4" pt8 "" "1" "") (setq blc3 (entlast)) );progn );if (if (= rep "D") (progn (setq pt3 (list (+ (car pt2) 20) (- (cadr pt2) 20))) (setq pt4 (list (+ (car pt1) 20) (cadr pt1))) (setq pt5 (list (+ (car pt4) 90) (+ (cadr pt4) 20))) (setq pt6 (list (+ (car pt4) 90) (cadr pt4))) (setq pt7 (list (car pt3) (- (cadr pt3) 38))) (setq pt8 (list (car pt3) (- (cadr pt3) 76))) (setq pt9 (list (+ (car pt6) 90) (cadr pt4))) (setq pt10 (list (car pt5) (- (cadr pt3) 38))) (setq pt11 (list (car pt5) (- (cadr pt3) 76))) (command "_insert" "2x4" pt9 "" "1" "") (setq blc1 (entlast)) (command "_insert" "2x4" pt10 "" "1" "") (setq blc2 (entlast)) (command "_insert" "2x4" pt11 "" "1" "") (setq blc3 (entlast)) );progn );if (NouveauCalque) (command "_rectangle" pt1 pt3) (setq rec1 (entlast)) (command "_rectangle" pt4 pt5) (setq rec2 (entlast)) (command "_rectangle" pt5 pt8) (setq rec3 (entlast)) (command "_chprop" blc1 blc2 blc3 rec3 "" "_la" "-LU BOIS" "" "") (command "_chprop" rec1 rec2 "" "_la" "-LU CONTREPLAQUÉ" "" "") (setvar 'OSMODE os) (princ) );defun c: (defun Bois (/ p1 p2 p3 bent1 bent2 bent3) (setq p1 '(0 0)) (setq p2 '(90 38)) (setq p3 (list (car p2) (cadr p1))) (setq p4 (list (car p1) (cadr p2))) (command "_rectangle" p1 "d" 90 38 p2) (setq bent1 (entlast)) (command "_line" p1 p2 "") (setq bent2 (entlast)) (command "_line" p3 p4 "") (setq bent3 (entlast)) (command "_block" "2x4" p3 bent1 bent2 bent3 "") ) My problem comes when i want to repeat the routine. It always asks me to redefine de block. So I Know that I need a condition somewhere but not sure how to put it down. All goes down with the sub-routine. I need to run it only if the block doesnt exist. So this is the help I need. And I do not want the answer just need to be pointed in the right direction please. Cheers & Beers ! Thanks in advance Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 15, 2012 Share Posted August 15, 2012 Before creating the block with your 'bois' function, check the block table using the tblsearch AutoLISP function to test whether the block already exists in the drawing. e.g.: (if (not (tblsearch "BLOCK" "<Your Block>")) (bois) ) Quote Link to comment Share on other sites More sharing options...
CadFrank Posted August 15, 2012 Author Share Posted August 15, 2012 Thanks Lee always the good anwser Quote Link to comment Share on other sites More sharing options...
David Bethel Posted August 15, 2012 Share Posted August 15, 2012 You can also look into the sysvar "EXPERT" -David 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.