Jump to content

Recommended Posts

Posted

OK.. here is the story. This is a modified version of a LISP that I wrote that works perfectly. I added a few more variables to it (there are a ton), and now all the sudden, I'm getting a 'stringp nil' error when it runs, and I cant seem to figure out why! I dont have a ton of experience writing LISPs, so my code is probably very redundant and sloppy, so please excuse the mess :D Thanks in advance if anyone is able to help out!

 

(defun c:gmE1 ()

 (setq osnapsettings (getvar "osmode"))
 (setq lyr (getvar "clayer"))
 (setvar "osmode" 0)
 (setvar "fieldeval" 13)
(command "-layer" "s" "F-ANNO-REV" "")
 (setq zp1 "37.3,29.6")
 (setq zp2 "41.6,13.9")

 (setq rp1 "37.4661,14.3748")
 (setq rp2 "37.4661,14.5992")
 (setq rp3 "37.4661,14.8236")
 (setq rp4 "37.4661,15.048")
 (setq rp5 "37.4661,15.2724")
 (setq rp6 "37.4661,15.4968")
 (setq rp7 "37.4661,15.7212")
 (setq rp8 "37.4661,15.9456")
 (setq rp9 "37.4661,16.17")
 (setq rp10 "37.4661,16.3944")
 (setq rp11 "37.4661,16.6188")
 (setq rp12 "37.4661,16.8432")
 (setq rp13 "37.4661,17.0676")
 (setq rp14 "37.4661,17.292")
 (setq rp15 "37.4661,17.5164")
 (setq rp16 "37.4661,17.7408")
 (setq rp17 "37.4661,17.9652")
 (setq rp18 "37.4661,18.1896")
 (setq rp19 "37.4661,18.414")
 (setq rp20 "37.4661,18.6384")

 (setq rpt1 "37.4661,29.215")
 (setq rpt2 "37.4661,28.9906")
 (setq rpt3 "37.4661,28.7662")
 (setq rpt4 "37.4661,28.5418")
 (setq rpt5 "37.4661,28.3174")
 (setq rpt6 "37.4661,28.093")
 (setq rpt7 "37.4661,27.8686")
 (setq rpt8 "37.4661,27.6442")
 (setq rpt9 "37.4661,27.4198")
 (setq rpt10 "37.4661,27.1954")
 (setq rpt11 "37.4661,26.971")
 (setq rpt12 "37.4661,26.7466")  
 
 (setq zw1 "38,25")
 (setq zw2 "42,17.2")
 (setq zw3 "38,23")
 (setq zw4 "41.16,16.56")

(command "zoom" "e")
(command "rectangle" zp1 zp2)
(command "zoom" "w" zp1 zp2)
 
 (setq r1 (getint "\nEnter First Rev Line Number use ZERO for NONE: "))
 (setq r2 (getint "\nEnter Second Rev Line Number use ZERO for NONE: "))
 (if (= r2 0)(setq r3 0)(setq r3 (getint "\nEnter Third Rev Line Number use ZERO for NONE: ")))
 (if (= r3 0)(setq r4 0)(setq r4 (getint "\nEnter Fourth Rev Line Number use ZERO for NONE: ")))
 (if (= r4 0)(setq r5 0)(setq r5 (getint "\nEnter Fifth Rev Line Number use ZERO for NONE: ")))
 (if (= r5 0)(setq r6 0)(setq r6 (getint "\nEnter 6th Rev Line Number use ZERO for NONE: ")))
 (if (= r6 0)(setq r7 0)(setq r7 (getint "\nEnter 7th Rev Line Number use ZERO for NONE: ")))
 (if (= r7 0)(setq r8 0)(setq r8 (getint "\nEnter 8th Rev Line Number use ZERO for NONE: ")))
 (if (= r8 0)(setq r9 0)(setq r9 (getint "\nEnter 9th Rev Line Number use ZERO for NONE: ")))
 (if (= r9 0)(setq r10 0)(setq r10 (getint "\nEnter 10th Rev Line Number use ZERO for NONE: ")))
 (if (= r10 0)(setq r11 0)(setq r11 (getint "\nEnter 11th Rev Line Number use ZERO for NONE: ")))
 (if (= r11 0)(setq r12 0)(setq r12 (getint "\nEnter 12th Rev Line Number use ZERO for NONE: ")))
 (if (= r12 0)(setq r13 0)(setq r13 (getint "\nEnter 13th Rev Line Number use ZERO for NONE: ")))
 (if (= r13 0)(setq r14 0)(setq r14 (getint "\nEnter 14th Rev Line Number use ZERO for NONE: ")))
 (if (= r14 0)(setq r15 0)(setq r15 (getint "\nEnter 15th Rev Line Number use ZERO for NONE: ")))
 (if (= r15 0)(setq r16 0)(setq r16 (getint "\nEnter 16th Rev Line Number use ZERO for NONE: ")))
 (if (= r16 0)(setq r17 0)(setq r17 (getint "\nEnter 17th Rev Line Number use ZERO for NONE: ")))
 (if (= r17 0)(setq r18 0)(setq r18 (getint "\nEnter 18th Rev Line Number use ZERO for NONE: ")))
 (if (= r18 0)(setq r19 0)(setq r19 (getint "\nEnter 19th Rev Line Number use ZERO for NONE: ")))
 (if (= r19 0)(setq r20 0)(setq r20 (getint "\nEnter 20th Rev Line Number use ZERO for NONE: ")))

 (setq rt1 r1
   rt2 r2
   rt3 r3
   rt4 r4
   rt5 r5
   rt6 r6
   rt7 r7
   rt8 r8
   rt9 r9
   rt10 r10
   rt11 r11
   rt12 r12)

(if (> r13 0)(setq rt1 r13))
(if (> r14 0)(setq rt2 r14))
(if (> r15 0)(setq rt3 r15))
(if (> r16 0)(setq rt4 r16))
(if (> r17 0)(setq rt5 r17))
(if (> r18 0)(setq rt6 r18))     
(if (> r19 0)(setq rt7 r19))
(if (> r20 0)(setq rt8 r20))
     
(COMMAND "-PURGE" "B" "" "N")
(command "zoom" "e")
(Command "erase" "w" zp2 zp1 "")
(command "zoom" zp1 zp2)

(setq z (itoa 0))
(setq rr1  (itoa r1)
     rr2  (itoa r2)
     rr3  (itoa r3)
     rr4  (itoa r4)
     rr5  (itoa r5)
     rr6  (itoa r6)
     rr7  (itoa r7)
     rr8  (itoa r8)
     rr9  (itoa r9)
     rr10 (itoa r10)
     rr11 (itoa r11)
     rr12 (itoa r12)
     rr13 (itoa r13)
     rr14 (itoa r14)
     rr15 (itoa r15)
     rr16 (itoa r16)
     rr17 (itoa r17)
     rr18 (itoa r18)
     rr19 (itoa r19)
     rr20 (itoa r20)
)  
    
(setq a (strcat "%<\\AcSm SheetSet.REV "))
(setq d (strcat " DATE \\f \"%tc1\">%"))
(setq e (strcat " DESCRIPTION \\f \"%tc1\">%"))
(setq i (strcat " APPR \\f \"%tc1\">%"))
(setq j (strcat " ENG \\f \"%tc1\">%"))
(setq k (strcat " PROJ \\f \"%tc1\">%"))
 
(if (< r1 10 )(setq ru1 (strcat z rr1))(setq ru1 (strcat rr1)))
(if (< r2 10 )(setq ru2 (strcat z rr2))(setq ru2 (strcat rr2)))
(if (< r3 10 )(setq ru3 (strcat z rr3))(setq ru3 (strcat rr3)))
(if (< r4 10 )(setq ru4 (strcat z rr4))(setq ru4 (strcat rr4)))
(if (< r5 10 )(setq ru5 (strcat z rr5))(setq ru5 (strcat rr5)))
(if (< r6 10 )(setq ru6 (strcat z rr6))(setq ru6 (strcat rr6)))
(if (< r7 10 )(setq ru7 (strcat z rr7))(setq ru7 (strcat rr7)))
(if (< r8 10 )(setq ru8 (strcat z rr8))(setq ru8 (strcat rr8)))
(if (< r9 10 )(setq ru9 (strcat z rr9))(setq ru9 (strcat rr9)))
(if (< r10 10 )(setq ru10 (strcat z rr10))(setq ru10 (strcat rr10)))
(if (< r11 10 )(setq ru11 (strcat z rr11))(setq ru11 (strcat rr11)))
(if (< r12 10 )(setq rv12 (strcat z rr12))(setq ru12 (strcat rr12)))
(if (< r13 10 )(setq ru13 (strcat z rr13))(setq ru13 (strcat rr13)))
(if (< r14 10 )(setq ru14 (strcat z rr14))(setq ru14 (strcat rr14)))
(if (< r15 10 )(setq ru15 (strcat z rr15))(setq ru15 (strcat rr15)))
(if (< r16 10 )(setq ru16 (strcat z rr16))(setq ru16 (strcat rr16)))
(if (< r17 10 )(setq ru17 (strcat z rr17))(setq ru17 (strcat rr17)))
(if (< r18 10 )(setq ru18 (strcat z rr18))(setq ru18 (strcat rr18)))
(if (< r19 10 )(setq ru19 (strcat z rr19))(setq ru19 (strcat rr19)))
(if (< r20 10 )(setq ru20 (strcat z rr20))(setq ru20 (strcat rr20)))       
     
(setq date1  (strcat a ru1 d)
     desc1  (strcat a ru1 e)
     appr1  (strcat a ru1 i)
     eng1   (strcat a ru1 j)
     proj1  (strcat a ru1 k)
     date2  (strcat a ru2 d)
     desc2  (strcat a ru2 e)
     appr2  (strcat a ru2 i)
     eng2   (strcat a ru2 j)
     proj2  (strcat a ru2 k)
     date3  (strcat a ru3 d)
     desc3  (strcat a ru3 e)
     appr3  (strcat a ru3 i)
     eng3   (strcat a ru3 j)
     proj3  (strcat a ru3 k)
     date4  (strcat a ru4 d)
     desc4  (strcat a ru4 e)
     appr4  (strcat a ru4 i)
     eng4   (strcat a ru4 j)
     proj4  (strcat a ru4 k)
     date5  (strcat a ru5 d)
     desc5  (strcat a ru5 e)
     appr5  (strcat a ru5 i)
     eng5   (strcat a ru5 j)
     proj5  (strcat a ru5 k)
     date6  (strcat a ru6 d)
     desc6  (strcat a ru6 e)
     appr6  (strcat a ru6 i)
     eng6   (strcat a ru6 j)
     proj6  (strcat a ru6 k)
     date7  (strcat a ru7 d)
     desc7  (strcat a ru7 e)
     appr7  (strcat a ru7 i)
     eng7   (strcat a ru7 j)
     proj7  (strcat a ru7 k)
     date8  (strcat a ru8 d)
     desc8  (strcat a ru8 e)
     appr8  (strcat a ru8 i)
     eng8   (strcat a ru8 j)
     proj8  (strcat a ru8 k)
     date9  (strcat a ru9 d)
     desc9  (strcat a ru9 e)
     appr9  (strcat a ru9 i)
     eng9   (strcat a ru9 j)
     proj9  (strcat a ru9 k)
     date10 (strcat a ru10 d)
     desc10 (strcat a ru10 e)
     appr10 (strcat a ru10 i)
     eng10  (strcat a ru10 j)
     proj10 (strcat a ru10 k)
     date11 (strcat a ru11 d)
     desc11 (strcat a ru11 e)
     appr11 (strcat a ru11 i)
     eng11  (strcat a ru11 j)
     proj11 (strcat a ru11 k)
     date12 (strcat a ru12 d)
     desc12 (strcat a ru12 e)
     appr12 (strcat a ru12 i)
     eng12  (strcat a ru12 j)
     proj12 (strcat a ru12 k)
     date13 (strcat a ru13 d)
     desc13 (strcat a ru13 e)
     appr13 (strcat a ru13 i)
     eng13  (strcat a ru13 j)
     proj13 (strcat a ru13 k)
     date14 (strcat a ru14 d)
     desc14 (strcat a ru14 e)
     appr14 (strcat a ru14 i)
     eng14  (strcat a ru14 j)
     proj14 (strcat a ru14 k)
     date15 (strcat a ru15 d)
     desc15 (strcat a ru15 e)
     appr15 (strcat a ru15 i)
     eng15  (strcat a ru15 j)
     proj15 (strcat a ru15 k)
     date16 (strcat a ru16 d)
     desc16 (strcat a ru16 e)
     appr16 (strcat a ru16 i)
     eng16  (strcat a ru16 j)
     proj16 (strcat a ru16 k)
     date17 (strcat a ru17 d)
     desc17 (strcat a ru17 e)
     appr17 (strcat a ru17 i)
     eng17  (strcat a ru17 j)
     proj17 (strcat a ru17 k)
     date18 (strcat a ru18 d)
     desc18 (strcat a ru18 e)
     appr18 (strcat a ru18 i)
     eng18  (strcat a ru18 j)
     proj18 (strcat a ru18 k)
     date19 (strcat a ru19 d)
     desc19 (strcat a ru19 e)
     appr19 (strcat a ru19 i)
     eng19  (strcat a ru19 j)
     proj19 (strcat a ru19 k)
     date20 (strcat a ru20 d)
     desc20 (strcat a ru20 e)
     appr20 (strcat a ru20 i)
     eng20  (strcat a ru20 j)
     proj20 (strcat a ru20 k)
)

   
(if (> r1 0)(COMMAND "-insert" "REV1T40GME1-BOT" rp1 "" "" "" r1 date1 eng1 appr1))()
(if (> r2 0)(COMMAND "-insert" "REV1T40GME1-BOT" rp2 "" "" "" r2 date2 eng2 appr2))()
(if (> r3 0)(COMMAND "-insert" "REV1T40GME1-BOT" rp3 "" "" "" r3 date3 eng3 appr3))()
(if (> r4 0)(COMMAND "-insert" "REV1T40GME1-BOT" rp4 "" "" "" r4 date4 eng4 appr4))()
(if (> r5 0)(COMMAND "-insert" "REV1T40GME1-BOT" rp5 "" "" "" r5 date5 eng5 appr5))()
(if (> r6 0)(COMMAND "-insert" "REV1T40GME1-BOT" rp6 "" "" "" r6 date6 eng6 appr6))()
(if (> r7 0)(COMMAND "-insert" "REV1T40GME1-BOT" rp7 "" "" "" r7 date7 eng7 appr7))()
(if (> r8 0)(COMMAND "-insert" "REV1T40GME1-BOT" rp8 "" "" "" r8 date8 eng8 appr8))()
(if (> r9 0)(COMMAND "-insert" "REV1T40GME1-BOT" rp9 "" "" "" r9 date9 eng9 appr9))()
(if (> r10 0)(COMMAND "-insert" "REV1T40GME1-BOT" rp10 "" "" "" r10 date10 eng10 appr10))()
(if (> r11 0)(COMMAND "-insert" "REV1T40GME1-BOT" rp11 "" "" "" r11 date11 eng11 appr11))()
(if (> r12 0)(COMMAND "-insert" "REV1T40GME1-BOT" rp12 "" "" "" r12 date12 eng12 appr12))()
(if (> r13 0)(COMMAND "-insert" "REV1T40GME1-BOT" rp13 "" "" "" r13 date13 eng13 appr13))()
(if (> r14 0)(COMMAND "-insert" "REV1T40GME1-BOT" rp14 "" "" "" r14 date14 eng14 appr14))()
(if (> r15 0)(COMMAND "-insert" "REV1T40GME1-BOT" rp15 "" "" "" r15 date15 eng15 appr15))()
(if (> r16 0)(COMMAND "-insert" "REV1T40GME1-BOT" rp16 "" "" "" r16 date16 eng16 appr16))()
(if (> r17 0)(COMMAND "-insert" "REV1T40GME1-BOT" rp17 "" "" "" r17 date17 eng17 appr17))()
(if (> r18 0)(COMMAND "-insert" "REV1T40GME1-BOT" rp18 "" "" "" r18 date18 eng18 appr18))()
(if (> r19 0)(COMMAND "-insert" "REV1T40GME1-BOT" rp19 "" "" "" r19 date19 eng19 appr19))()
(if (> r20 0)(COMMAND "-insert" "REV1T40GME1-BOT" rp20 "" "" "" r20 date20 eng20 appr20))()

(if (> r1 0)(COMMAND "-insert" "REV1T40GME1-TOP" rpt1 "" "" "" rt1 date1 eng1 appr1 desc1))()
(if (> r2 0)(COMMAND "-insert" "REV1T40GME1-TOP" rpt2 "" "" "" rt2 date2 eng2 appr2 desc2))()
(if (> r3 0)(COMMAND "-insert" "REV1T40GME1-TOP" rpt3 "" "" "" rt3 date3 eng3 appr3 desc3))()
(if (> r4 0)(COMMAND "-insert" "REV1T40GME1-TOP" rpt4 "" "" "" rt4 date4 eng4 appr4 desc4))()
(if (> r5 0)(COMMAND "-insert" "REV1T40GME1-TOP" rpt5 "" "" "" rt5 date5 eng5 appr5 desc5))()
(if (> r6 0)(COMMAND "-insert" "REV1T40GME1-TOP" rpt6 "" "" "" rt6 date6 eng6 appr6 desc6))()
(if (> r7 0)(COMMAND "-insert" "REV1T40GME1-TOP" rpt7 "" "" "" rt7 date7 eng7 appr7 desc7))()
(if (> r8 0)(COMMAND "-insert" "REV1T40GME1-TOP" rpt8 "" "" "" rt8 date8 eng8 appr8 desc8))()
(if (> r9 0)(COMMAND "-insert" "REV1T40GME1-TOP" rpt9 "" "" "" rt9 date9 eng9 appr9 desc9))()
(if (> r10 0)(COMMAND "-insert" "REV1T40GME1-TOP" rpt10 "" "" "" rt10 date10 eng10 appr10 desc10))()
(if (> r11 0)(COMMAND "-insert" "REV1T40GME1-TOP" rpt11 "" "" "" rt11 date11 eng11 appr11 desc11))()
(if (> r12 0)(COMMAND "-insert" "REV1T40GME1-TOP" rpt12 "" "" "" rt12 date12 eng12 appr12 desc12))()

 (setvar "osmode" osnapsettings)
 (setvar "clayer" lyr)
 (COMMAND "ZOOM" "E")

 (PRINC)
 )

Posted

Each of these lines will return an error, however the first line to throw the error ends your routine:

 

...
       date12 (strcat a ru12 d)                                        ; <-- First Error
       desc12 (strcat a ru12 e)
       appr12 (strcat a ru12 i)
       eng12  (strcat a ru12 j)
       proj12 (strcat a ru12 k)
...

 

The reason for this error can be found here:

 

...
(if (< r12 10)
   (setq rv12 (strcat z rr12))
   (setq ru12 (strcat rr12)))
...

 

... Can you identify what's wrong?

 

When the IF statement's test experssion is true, the then expression sets the "rv12" variable, instead of the "ru12" variable (as it should).

 

Separately, you really should look into the COND function to minimize the duplication of code. Additionally, consider adding an *error* handler so that the sysvars you change can be reset upon an *error* (like the one you're experiencing now), or if the user were to hit Esc.

 

If it were only a quick re-write, I'd go ahead and do so... but I simply do not have the time to re-write the 497 lines of code this morning.

 

Hope this helps!

Posted

Can you upload a dwg that holds all these mentioned blocks within your routine ?

Posted (edited)

Wow.. so the problem the WHOLE time was... I cant type! haha

 

I do agree that there is a LOT of redundant code here, unfortunately, I dont know enough about it to use the COND function. I'm basically to the point where I kind of know what the COND does (i think its like an if>then statement, but for multiple IFs), but I wouldnt know how to write the code to use it to set the variable values.

 

Thanks for finding my error for me! I knew it would be something really simple and dumb like a mistyped character.

 

Do you have any good resources for learning the COND, and other things that would maybe help consolidate the code some?

 

Oh.. by the way, it works perfectly now!

Edited by rwsice9
forgot something
Posted

You're welcome, I'm glad I could help.

 

As for learning more about the COND function, the best place to start is the Developer Help (In VLIDE, hit F1).

Posted

It's always a "good" idea to localize your variables, but you've got just way too many of those. I'd advise you try looking at rather storing the values into lists. E.g. instead of using variable r1 through r20 to store the revision number entered by the user you could have done something like this:

  (setq rList nil
       index 1
 )
 (while (and (setq tmpAnswer (getint (strcat "Enter " (int->word index) " Rev Line Number use ZERO for NONE: ")))
             (> tmpAnswer 0)
        )
   (setq rList (cons tmpAnswer rList) index (1+ index))
 )
 (setq rList (reverse rList))

The function I use to covert the index to First, Second, Third ... 20th ...

(defun int->word (i /)
 (cond
   ((= i 1) "First")
   ((= i 2) "Second")
   ((= i 3) "Third")
   ((= i 4) "Fourth")
   ((= i 5) "Fifth")
   ((= (rem i 10) 1) (strcat (itoa i) "st"))
   ((= (rem i 10) 2) (strcat (itoa i) "nd"))
   ((= (rem i 10) 3) (strcat (itoa i) "rd"))
   (t (strcat (itoa i) "th"))
 )
)

To get the 2nd value you then use (nth 1 rList) - the list is zero based, so the 1st has an index of 0.

 

Though this means a lot of your other code will also need changing, mostly for the better though. E.g. the portion where you extract only the last 8 revisions entered by the user could be rewritten thus:

  (setq rtList rList)
 (while (> (length rtList)  (setq rtList (cdr rtList)))

That would leave the list containing only the last 8 numbers entered.

 

Edit: then there's another "trick" to use if you want to perform one function on all items in the list. E.g. converting all the integers to strings:

(setq rrList (mapcar 'itoa rList))

Posted

Wow. See, I've been using AutoCAD for about 12 years now, but never got into any of the LISP programming until now (shouldve started a LONG time ago), so a lot of this stuff is still pretty much Greek to me. I'm at the point where I can read the code, and get a pretty good idea of what its doing, but as far as knowing the code well enough to come up with stuff like this, I think I'm still a ways off from that.

 

I do know, however that having 450,000 (or so) variables in one function isnt necessarily a good thing, but its the best I can come up with at this point.

 

I do want to learn more, and I will be looking into what you posted here and try to get a good grasp of how to write this stuff for myself. I do appreciate the time you took to write all that out! (although, you seem pretty experienced in it, so it probably didnt really take nearly as long for you as it would have for me)

 

Thanks for your help!

Posted

Don't worry! You're ahead of a large portion of people by simply trying to "lisp" :wink:.

 

I've done programming for some 20 years now (not just in AutoLisp - actually have a "programming" degree), but I definitely don't deem myself an "expert", have just "learned" some nifty ways over the years. Best way for you to learn is actually doing it, books only do so much - I'd even say my varsity time wasn't worth the cost. There's quite a few guys over here and other forums where I've seen them getting to my level and even surpassing in one or two years of "fiddling" with lisp. So it seems to be not too difficult to learn.

Posted

Yeah I agree with that. Its definitely not as difficult as it first looks. Just a matter of learning the functions, what they do.... and how not to put in a V that should have been a U! haha8)

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