Jump to content

Why is this not working correct?


j_spawn_h

Recommended Posts

This does what I want except for one thing. I am not sure how to change it. I only want it to ask me once what the spacing is, but it is asking me each line for spacing.

 

;Version 1.00
(defun c:cs (/)
 
(and (setq ss (ssget "_:L" '((0 . "LINE"))))
           (while (setq en (ssname ss 0))
           (setq ed (entget en))
           (setq p10 (cdr (assoc 10 ed)))
           (setq p11 (cdr (assoc 11 ed)))
           (setq mpt (mapcar '(lambda (a b) (* (+ a b) 0.5)) p10 p11))
           (setq d2d (distance (cdr (reverse p10)) (cdr (reverse p11))))
           ;(setq d1d (/ d2d 12.))
           ;(setq d1c (fix (+ d1d 0.501)))
 
 (setq c (getstring "\nWhat is the spacing? (24,16,12): "))
  (if (= c "24")
      (cond  ((<= d2d 118)(setq e "2x6"))
       ((and(>= d2d 118.01)(<= d2d 150))(setq e "2x8"))
              ((and(>= d2d 150.01)(<= d2d 177))(setq e "2x10"))
              ((and(>= d2d 177.01)(<= d2d 209))(setq e "2x12"))
       ((and(>= d2d 209.01)(<= d2d 500))(setq e "Change Spacing"))
               );end cond
               );end if
(if (= c "16")
      (cond  ((<= d2d 144)(setq e "2x6"))
       ((and(>= d2d 144.01)(<= d2d 183))(setq e "2x8"))
              ((and(>= d2d 183.01)(<= d2d 217))(setq e "2x10"))
              ((and(>= d2d 217.01)(<= d2d 256))(setq e "2x12"))
       ((and(>= d2d 256.01)(<= d2d 500))(setq e "Change Spacing"))
               );end cond
               );end if
(if (= c "12")
      (cond  ((<= d2d 167)(setq e "2x6"))
       ((and(>= d2d 167.01)(<= d2d 211))(setq e "2x8"))
              ((and(>= d2d 211.01)(<= d2d 251))(setq e "2x10"))
              ((and(>= d2d 251.01)(<= d2d 296))(setq e "2x12"))
       ((and(>= d2d 296.01)(<= d2d 500))(setq e "Change Spacing"))
               );end cond
               );end if

 (defun radians->degrees (r)(cvunit r "radian" "degree"));end rad defun
      
;-------TEXT JUSTIFICATION----------------------------------------     
(setq lan (angle p10 p11))
      (setq ad (radians->degrees lan))
      (if (and (> ad 90.1) (<= ad 270.1)) 
        (progn
          (setq ptemp p10
                p10 p11
                p11 ptemp
                lan (angle p10 p11)  
                ad (radians->degrees lan))
   );end progn
   );end if
                 
      (setq dir (if (< (* pi 0.5) lan (* pi 1.5)) - +))
 (setq r3(entmake (list (cons 0 "TEXT")
                          (cons 8 (getvar "CLAYER"))
                          (cons 7 (getvar "TEXTSTYLE"))
                          (cons 40 (getvar "TEXTSIZE"))
                          (cons 41 0.80)
     (cons 72 4)
            (setq fg(cons 10 ' (0.0 0.0)));(setq r1(polar mpt (dir lan (+ 1))
                                   ;(getvar "TEXTSIZE")))))
                          (setq hg(cons 11 (setq r2(polar mpt (dir lan (* 0.5 pi));(+ 1))
                                  (+ (* 0.5 (atof width)) (* 0.8 (getvar "TEXTSIZE")))))))
                          (setq gg(cons 50 lan))
                         (setq rg(cons 1 (strcat e)))
   );end list
          );end entmake
                 );end setq r3
      
       
                  (ssdel en ss)));end and
    (prin1)
);end defun

Link to comment
Share on other sites

I figured it out now for some reason it is giving me an error.

; error: bad argument type: stringp nil

But when I run one of my other lisps then run this one it works.

Any ideas on why?

 

;Version 1.00
(defun c:cs (/)
(setq c (getstring "\nWhat is the spacing? (24,16,12): ")) 
(and (setq ss (ssget "_:L" '((0 . "LINE"))))
           (while (setq en (ssname ss 0))
           (setq ed (entget en))
           (setq p10 (cdr (assoc 10 ed)))
           (setq p11 (cdr (assoc 11 ed)))
           (setq mpt (mapcar '(lambda (a b) (* (+ a b) 0.5)) p10 p11))
           (setq d2d (distance (cdr (reverse p10)) (cdr (reverse p11))))
           ;(setq d1d (/ d2d 12.))
           ;(setq d1c (fix (+ d1d 0.501)))
 
 
  (if (= c "24")
      (cond  ((<= d2d 118)(setq e "2x6"))
       ((and(>= d2d 118.01)(<= d2d 150))(setq e "2x8"))
              ((and(>= d2d 150.01)(<= d2d 177))(setq e "2x10"))
              ((and(>= d2d 177.01)(<= d2d 209))(setq e "2x12"))
       ((and(>= d2d 209.01)(<= d2d 500))(setq e "Change Spacing"))
               );end cond
               );end if
  (if (= c "16")
      (cond  ((<= d2d 144)(setq e "2x6"))
       ((and(>= d2d 144.01)(<= d2d 183))(setq e "2x8"))
              ((and(>= d2d 183.01)(<= d2d 217))(setq e "2x10"))
              ((and(>= d2d 217.01)(<= d2d 256))(setq e "2x12"))
       ((and(>= d2d 256.01)(<= d2d 500))(setq e "Change Spacing"))
               );end cond
               );end if
  (if (= c "12")
      (cond  ((<= d2d 167)(setq e "2x6"))
       ((and(>= d2d 167.01)(<= d2d 211))(setq e "2x8"))
              ((and(>= d2d 211.01)(<= d2d 251))(setq e "2x10"))
              ((and(>= d2d 251.01)(<= d2d 296))(setq e "2x12"))
       ((and(>= d2d 296.01)(<= d2d 500))(setq e "Change Spacing"))
               );end cond
               );end if

 (defun radians->degrees (r)(cvunit r "radian" "degree"));end rad defun
      
;-------TEXT JUSTIFICATION----------------------------------------     
(setq lan (angle p10 p11))
      (setq ad (radians->degrees lan))
      (if (and (> ad 90.1) (<= ad 270.1)) 
        (progn
          (setq ptemp p10
                p10 p11
                p11 ptemp
                lan (angle p10 p11)  
                ad (radians->degrees lan))
   );end progn
   );end if
                 
      (setq dir (if (< (* pi 0.5) lan (* pi 1.5)) - +))
 (setq r3(entmake (list (cons 0 "TEXT")
                          (cons 8 (getvar "CLAYER"))
                          (cons 7 (getvar "TEXTSTYLE"))
                          (cons 40 (getvar "TEXTSIZE"))
                          (cons 41 0.80)
     (cons 72 4)
            (setq fg(cons 10 ' (0.0 0.0)));(setq r1(polar mpt (dir lan (+ 1))
                                   ;(getvar "TEXTSIZE")))))
                          (setq hg(cons 11 (setq r2(polar mpt (dir lan (* 0.5 pi));(+ 1))
                                  (+ (* 0.5 (atof width)) (* 0.8 (getvar "TEXTSIZE")))))))
                          (setq gg(cons 50 lan))
                         (setq rg(cons 1 (strcat e)))
   );end list
          );end entmake
                 );end setq r3
      
       
                  (ssdel en ss)));end and
    (prin1)
);end defun

Link to comment
Share on other sites

The width variable has no value and it returns nil which would cause the code to return error at the command line .

 

(setq    hg (cons 11
                                (setq r2 (polar mpt
                                                (dir lan (* 0.5 pi))
                                                (+ (* 0.5 (atof [color=red][b]width[/b][/color]))
                                                   (* 0.8 (getvar "TEXTSIZE"))
                                                )
                                         )
                                )
                          )
                     )

 

And localize the variables like the following .

 

(defun c:cs (/ A AD B C D2D DIR E ED EN FG GG HG LAN MPT P10 P11 PTEMP R2 R3 RG SS WIDTH)

Link to comment
Share on other sites

As Tharwat already pointed, the WIDTH variable isn't allocated, so it will generate an error when you attempt to use it in an evaluation. You stated that after using a particular routine, the trouble-maker one just start to work - you didn't posted the code of that second routine, but the reason it helps is that you probably have a variable with the same name in it, so when call CS command the variable can now be evaluated.

Link to comment
Share on other sites

Try this draft at the moment after removing the width variable :)

 

(defun c:cs (/ radians->degrees a ad b c d2d dir e ed en lan mpt p10 p11
            ptemp ss
           )
 (defun radians->degrees (r) (cvunit r "radian" "degree"))
 (if
   (and (progn (initget 7 "12 16 24")
               (setq c (getkword "\nWhat is the spacing? (24,16,12): "))
        )
        (setq ss (ssget "_:L" '((0 . "LINE"))))
   )
    (progn
      (while (setq en (ssname ss 0))
        (setq ed (entget en))
        (setq mpt (mapcar '(lambda (a b) (* (+ a b) 0.5))
                          (setq p10 (cdr (assoc 10 ed)))
                          (setq p11 (cdr (assoc 11 ed)))
                  )
        )
        (setq d2d (distance (cdr (reverse p10)) (cdr (reverse p11))))
        (if (= c "24")
          (cond ((<= d2d 118) (setq e "2x6"))
                ((and (>= d2d 118.01) (<= d2d 150)) (setq e "2x8"))
                ((and (>= d2d 150.01) (<= d2d 177)) (setq e "2x10"))
                ((and (>= d2d 177.01) (<= d2d 209)) (setq e "2x12"))
                ((and (>= d2d 209.01) (<= d2d 500))
                 (setq e "Change Spacing")
                )
          )
        )
        (if (= c "16")
          (cond ((<= d2d 144) (setq e "2x6"))
                ((and (>= d2d 144.01) (<= d2d 183)) (setq e "2x8"))
                ((and (>= d2d 183.01) (<= d2d 217)) (setq e "2x10"))
                ((and (>= d2d 217.01) (<= d2d 256)) (setq e "2x12"))
                ((and (>= d2d 256.01) (<= d2d 500))
                 (setq e "Change Spacing")
                )
          )
        )
        (if (= c "12")
          (cond ((<= d2d 167) (setq e "2x6"))
                ((and (>= d2d 167.01) (<= d2d 211)) (setq e "2x8"))
                ((and (>= d2d 211.01) (<= d2d 251)) (setq e "2x10"))
                ((and (>= d2d 251.01) (<= d2d 296)) (setq e "2x12"))
                ((and (>= d2d 296.01) (<= d2d 500))
                 (setq e "Change Spacing")
                )
          )
        )
        (setq lan (angle p10 p11))
        (setq ad (radians->degrees lan))
        (if (and (> ad 90.1) (<= ad 270.1))
          (progn (setq ptemp p10
                       p10   p11
                       p11   ptemp
                       lan   (angle p10 p11)
                       ad    (radians->degrees lan)
                 )
          )
        )
        (setq dir (if (< (* pi 0.5) lan (* pi 1.5))
                    -
                    +
                  )
        )
        (entmake (list (cons 0 "TEXT")
                       (cons 8 (getvar "CLAYER"))
                       (cons 7 (getvar "TEXTSTYLE"))
                       (cons 40 (getvar "TEXTSIZE"))
                       (cons 41 0.80)
                       (cons 72 4)
                       (cons 10 '(0.0 0.0))
                       (cons 11
                             (polar mpt
                                    (dir lan (* 0.5 pi))
                                    (* 0.8 (getvar "TEXTSIZE"))
                             )
                       )
                       (cons 50 lan)
                       (cons 1 (strcat e))
                 )
        )
        (ssdel en ss)
      )
    )
 )
 (prin1)
)

Link to comment
Share on other sites

I used a piece of another lisp that is why that was in there. I changed and it works great.

Tharwat,

Well my goal is to use this and try and merge another lisp so I can swipe a lot of lines and have it label them with a dimension and say what they are. So any lines that equal the same result they will be labeld all with the dimension. It may make since looking at my example. I am not good at lisp yet so I am doing one step at a time.

example.dwg

Link to comment
Share on other sites

I used a piece of another lisp that is why that was in there. I changed and it works great.

Tharwat,

Well my goal is to use this and try and merge another lisp so I can swipe a lot of lines and have it label them with a dimension and say what they are. So any lines that equal the same result they will be labeld all with the dimension. It may make since looking at my example. I am not good at lisp yet so I am doing one step at a time.

 

I am talking about the current modified lisp and I have no idea about your second lisp , so I can not guess what the second lisp does .

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