Jump to content

Problem with consistency


pttr
 Share

Recommended Posts

Hi I have a program that checks for at LOT of BLOCKS PLINES, and HATCHES and if the program gets a match it places it. 

 

The problem is the placing works the 3rd time I use it, and I can´t understand why... 

Some time the PLINES insertion is a bit off and sometimes it´s the blocks, but mostly it´s the Frame i create to place the Hatch in.

 

Here is a small peice of it

;;----HATCH----;;
    (if (setq blockss (ssget "_X" '( (0 . "HATCH") (8 . "B-B-U0013") (410 . "Model")))) ;Check if Hatch B-B-U0013 exist in model
      (progn
	(setq co (list (car co) (- (cadr co)6)))
	(setq ip1 (list (car ip1) (- (cadr ip1)6)))
	(setq ip2 (list (car ip2) (- (cadr ip2)6)))

	(setq rip1 (list (-(car co)2) (- (cadr co)3)))   
	(setq rip2 (list (+(car co)3) (+ (cadr co)2)))
	(setq hip (list (+(car co)1) (- (cadr co)2)))

  	(command "RECTANG" rip1 rip2) ; places rectangle "boundry for Hatch (frame)
  	(command "-HATCH" "LA" "B-B-U0013" "P" "S" hip "") ;Places hatch B-B-U0013but need boundrys (frame) and IP
	(command "-HATCH" "LA" "." "") ;Reset hatch command to avoid next hatch been predetermed
	(command "-MTEXT" ip1 "H" "1.6" "J" "ML" ip2 "Utrymningsväg" "")
      )
     )
    (if (setq blockss (ssget "_X" '( (0 . "HATCH") (8 . "B-B-A105") (410 . "Model")))) ;Check if Hatch B-B-A105 exist in model
      (progn
	(setq co (list (car co) (- (cadr co)6)))
	(setq ip1 (list (car ip1) (- (cadr ip1)6)))
	(setq ip2 (list (car ip2) (- (cadr ip2)6)))

	(setq rip1 (list (-(car co)2) (- (cadr co)3)))   
	(setq rip2 (list (+(car co)3) (+ (cadr co)2)))
	(setq hip (list (+(car co)1) (- (cadr co)2)))

  	(command "RECTANG" rip1 rip2) ; places rectangle "boundry for Hatch (frame)
  	(command "-HATCH" "LA" "B-B-A105" "P" "S" hip "") ;Places hatch B-B-A105 but need boundrys (frame) and IP
	(command "-HATCH" "LA" "." "") ;Reset hatch command to avoid next hatch been predetermed
	(command "-MTEXT" ip1 "H" "1.6" "J" "ML" "W" "34" "Område som ej omfattas av brandprojekteringen" "")
      )
     )

 

If I use less parts of the code everything works fine. 

 

Any ideas?

Thanks!

Link to comment
Share on other sites

Where/how is co, ip1, ip2 being set? This is probably your issue.

 

--edit

Another way of calculating the different points.

(setq co (mapcar '+ co '(0 -6 0)))
(setq ip1 (mapcar '+ ip1 '(0 -6 0)))
(setq ip2 (mapcar '+ ip2 '(0 -6 0)))
(setq rip1 (mapcar '+ co '(-2 -3 0)))
(setq rip2 (mapcar '+ co '(3 2 0)))
(setq hip (mapcar '+ co '(1 -2 0)))

 

Edited by mhupp
  • Like 1
Link to comment
Share on other sites

I keep being second to answer after Mhupp..

 

I spent a lot of time getting things wrong, still do, one thing that sometimes happens for me is that I set a global variable after I have used it, so on the second pass it picks up the value but in the first it doesn't do anything.

For example

  (defun c:anexample ( / )
    (setq MyNextBlockName "AThing")
    (if (= MyBlockName "AThing") (princ MyBlockName) )
    (setq MyBlockName MyNextBlockName)
    (princ)
  )

Run it once, nothing, run it again and it displays "AThing" int he command line

 

The other thing that often happens is it picks up a global variable from another unrelated LISP and tries to use that first off.

For example I often use 'acount' in loops so if LISP 1 sets acount to 10 then LIPS2 might be:

For example

(defun c:Lisp1 ( / )

  (setq acount 10)

)

(defun c:anexample ( / )

  (while (< acount 5)

    (princ "\n")

    (princ acount)

    (setq (+ acount 1))

  )

  (setq acount 0) ;;reset counter for next use

 

Welcome to world of debugging a LISP! Frustrates me when in my head it all works OK, but my fingers decide to type other things in

Oh, last thing.. spelling mistakes...

  • Like 2
Link to comment
Share on other sites

Posted (edited)

Thanks! I´ll have to try all of this later, I´ll get a crack at it after the summer :)

Edited by pttr
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
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.

 Share

×
×
  • Create New...