Jump to content

Block insertion / redefine


CadFrank

Recommended Posts

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

Link to comment
Share on other sites

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

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