Author Topic: Error in code - Can someone help?  (Read 6679 times)

0 Members and 1 Guest are viewing this topic.

stusic

  • Guest
Re: Error in code - Can someone help?
« Reply #15 on: July 20, 2012, 04:10:42 PM »
Please correct me if I'm wrong, but shouldn't the following COND statement have an "else" statement?

Code: [Select]
             (cond
               ((= "DRAWNBY" tag) (_entmod fld1 attData))
               ((= "DRAWNDATE" tag) (_entmod fld2 attData))
               ((= "DRAWING_NO" tag) (_entmod fld3 attData))
               ((= "ITEM_NO" tag) (_entmod fld4 attData))
               ((= "DESCRIPTION" tag) (_entmod fld5 attData))
               ((= "SALES_ORDER" tag) (_entmod fld6 attData))
             )

Nevermind, I see that it's an optional statement.
« Last Edit: July 20, 2012, 04:13:59 PM by stusic »

stusic

  • Guest
Re: Error in code - Can someone help?
« Reply #16 on: July 23, 2012, 04:30:59 PM »
Okay, I've done a ton of reading and, while I understand the theory and the ultra-novice basics of the WHILE function, I am apparently not experienced enough to debug it.

Working with Lee Mac's guide (http://www.lee-mac.com/debugvlide.html), I was able to isolate the section that's giving the error, but I'm not sure how to fix it. From the watch window, I see that it hangs on the PAGE_NO tag. I'm guessing there's nothing to tell it to skip over tags that aren't specified.

Here's the little bit that's giving me the trouble:
Code: [Select]
(progn
         (setq i -1)
         (while (setq ent (ssname ss (setq i (1+ i))))
           (setq att (entnext ent))
           (setq attData (entget att))
           (while (not (= "SEQEND" (cdadr attData)))
             (setq tag (cdr (assoc 2 attData)))
             (cond
               ((= "DRAWNBY" tag) (_entmod fld1 attData))
               ((= "DRAWNDATE" tag) (_entmod fld2 attData))
               ((= "DRAWING_NO" tag) (_entmod fld3 attData))
               ((= "ITEM_NO" tag) (_entmod fld4 attData))
               ((= "DESCRIPTION" tag) (_entmod fld5 attData))
               ((= "SALES_ORDER" tag) (_entmod fld6 attData))
             )
             (setq att (entnext att))
           )
         )

         (command "._regenall")
         (*error* nil)
       )

Specifically, the program seems to stop on:
Code: [Select]
(setq att (entnext att)) ;the second instance of this code
I am certainly not knocking Renderman's code, it's awesome, I just didn't provide a ton of info and he's already spent a few weeks helping me on this ridonkerous problem.
« Last Edit: July 23, 2012, 04:34:18 PM by stusic »

BlackBox

  • King Gator
  • Posts: 3770
Re: Error in code - Can someone help?
« Reply #17 on: July 23, 2012, 05:10:48 PM »
Given that I was unable to test the code properly on the title block you provided, I am not surprised that the code is error prone. Also adding to this, is that I do not use ENT* functions often for digging into nested entities, rather I use Visual LISP to query Property Objects instead.

... Perhaps someone more adept at ENT* functions can see where I've made a mistake?

In any event, the first thing that jumps out from your post is that you say that the tag variable hangs on 'PAGE_NO', but there is no string with that value in the COND statement. Perhaps I fat-finger typed something in my earlier code, or maybe another instance of the information trickling out over the past couple weeks?  :lol: LoL
"How we think determines what we do, and what we do determines what we get."

stusic

  • Guest
Re: Error in code - Can someone help?
« Reply #18 on: July 23, 2012, 07:54:59 PM »
Ah, yeah, I'm sorry man. No mistake on your part. I meant to go back and get your original code, but pasted the code I had been using to figure out how it worked.  I edited the post when I realized that. Again, apologies.  :|

And I hope everyone realizes it's not an error in your code but, given that it deals with a particular file structure, I imagine it would make it difficult to test locally.

But I just learned a whole lot about the "while" function while I was digging around...  :-)

BlackBox

  • King Gator
  • Posts: 3770
Re: Error in code - Can someone help?
« Reply #19 on: July 23, 2012, 08:47:15 PM »
No worries; giving the code you posted another glance, nothing within the WHILE statement ever changes the 'attData' variable, which IMO is what is causing this line:

Code - Auto/Visual Lisp: [Select]
  1. (setq att (entnext att))

... To *error*, as the COND statement never has a test expression return non-Nil, so it (the COND statement) effectively just passes through to the next line (above), which _does_ throw an *error*.

This is simply an oversight on my part. Sorry for that, and the fact that I'm working from home this evening, otherwise I'd dig into this more. Just no time.  :|
"How we think determines what we do, and what we do determines what we get."

BlackBox

  • King Gator
  • Posts: 3770
Re: Error in code - Can someone help?
« Reply #20 on: July 23, 2012, 08:49:32 PM »
... Almost forgot the point of posting this!?! :lol: LoL Try commenting that line out (the second one at the end of your post), as I believe it to be a mistaken duplicate.
"How we think determines what we do, and what we do determines what we get."

stusic

  • Guest
Re: Error in code - Can someone help?
« Reply #21 on: July 23, 2012, 09:55:55 PM »
Ah, that makes so much sense! All the examples I was seeing were because the WHILE (or in this case, COND) statement was returning nil - it didn't occur to me that I was actually looking for the opposite (how does it know it reached the end?).

Thanks for the lesson! Go eat your din-din and enjoy the rest o fthe night!  ^-^

BlackBox

  • King Gator
  • Posts: 3770
Re: Error in code - Can someone help?
« Reply #22 on: July 24, 2012, 12:23:40 AM »
In this particular case, to the best of my knowledge, we're wanting to iterate the nested entities (the attributes) until we reach "SEQEND" (or Sequence End). The (what I now believe to be) duplicate line attempts to step into the next attribute before fully iterating the attribute's nested entity(s).

Personally, I find Visual LISP so much easier to 'read', that I feel I've made several (less noticeable?) mistakes... I just might change out for VL code at my next convenience. Hopefully someone will fill in the gaps here, or point you in a better direction before then.

Mmmm dinner; fried green tomatoes and homemade summer (vegetable) soup!

Cheers!
"How we think determines what we do, and what we do determines what we get."

stusic

  • Guest
Re: Error in code - Can someone help?
« Reply #23 on: July 24, 2012, 07:16:24 AM »
I think part of the problem was that I didn't mention that there are a bunch of attributes in the block, but I only want to change some of them (for now). The PAGE_NO attribute is one of these that I want to skip.

I tried commenting out:
Code - Auto/Visual Lisp: [Select]
  1. (setq att (entnext att))
but it still hangs; no error.

I think I get what's happening from your description, but I think it's the theory I understand, not the application of it. If all attributes were listed in the COND statement, would the above code be necessary? By commenting it out, how does it know when it reaches the end (without hitting the SEQEND)?

I agree, I think VL is much easier to read (and I don't even know it).

Thanks for your help and all of your hand-holding. Btw, fried green tomatoes are one of my favorites - I grew up just down the road from where they filmed the movie of the same name :)

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Error in code - Can someone help?
« Reply #24 on: July 24, 2012, 09:00:17 AM »
...

I agree, I think VL is much easier to read (and I don't even know it).

...

So why don't you use it ?  :-P

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

stusic

  • Guest
Re: Error in code - Can someone help?
« Reply #25 on: July 24, 2012, 09:14:26 AM »
So why don't you use it ?  :-P

'Cause I tried to learn LISP and VL at the same time and just ended up confusing myself and getting nowhere  :|