Author Topic: Weekend challenge  (Read 9576 times)

0 Members and 1 Guest are viewing this topic.

Jimmy D

  • Guest
Weekend challenge
« Reply #15 on: April 11, 2005, 02:47:47 AM »
Not so fancy as Jeff_M ... but it works.

Code: [Select]
(defun c:LayToDwg (/ LayName)
(setq DwgPath (getvar "DWGPREFIX")
      PO (list 0 0 0))
(defun NewDwg (LayName / DwgPathName)
   (setvar "CLAYER" LayName)
   (command "_layer" "freeze" "*" "")
   (setq DwgPathName (strcat DwgPath LayName))
   (command "_WBlock" DwgPathName "" P0 "all" "")
   (command "OOPS")
   (command "_layer" "thaw" "*" "")
)
(setq LayName (cdr (assoc 2 (tblnext "layer" T))))
(NewDwg LayName)
(while (/= (setq LayName (cdr (assoc 2 (tblnext "LAYER")))) nil)
       (NewDwg LayName))
(command "regen")
)


And this was all done on a Monday morning!

Jimmy

daron

  • Guest
Weekend challenge
« Reply #16 on: April 11, 2005, 08:36:30 AM »
Jimmy, how many drawings were created? How many entities were present? How long did it take? I'm curious to see how big of a file it would take to render that code useless? I'll llink as to my questioning why momentarily. Stay tuned...

This
and
this
and
this

Jimmy D

  • Guest
Weekend challenge
« Reply #17 on: April 11, 2005, 10:09:24 AM »
Daron,

You're right about the time it takes.
I've tried it on a +7Mb drawing with +30500 objects in it, and it took about 35 secs (didn't really time it), but it did what it was suppose to do. All dwg's were created (25 layers - 25 dwg's).
I know there is a right and a wrong way to do things, but if I knew the right way, I wouldn't be reading this forum would I?
I'm new at this and I'm figuring it out as I go along!

Jimmy

nivuahc

  • Guest
Weekend challenge
« Reply #18 on: April 11, 2005, 12:26:25 PM »
Quote from: Jimmy D
I know there is a right and a wrong way to do things, but if I knew the right way, I wouldn't be reading this forum would I?


Yes, that's true...

It works = right way
It doesn't work = wrong way

What you wrote works. Don't think, for one second, that it is in any way wrong. Is there a better way? There almost always is... no matter what you're talking about. What you did works, so it's right. Period. I don't care who you are or what code you write... code can always be improved. That doesn't make it wrong.

Quote from: Jimmy D
I'm new at this and I'm figuring it out as I go along!


Based on the code you posted above, I would think that it is your duty to drop the "I'm new at this" bit... I know people who have been writing code for a long, long time who wouldn't have been able to come up with that on a Monday morning. If you truly are *new* at this, you are far more advanced than a lot of people I know. You're being too hard on yourself Jimmy.  8)

Jimmy D

  • Guest
Weekend challenge
« Reply #19 on: April 12, 2005, 01:26:48 AM »
Thanks Nivuahc. When I say I'm *new* I mean I've only been programming lisp for about a year now, so *new* is relative.

I'm jealous how you guys can program so clearly and simple though.
My biggest problem I think is that I write too impulsive and make everything up as I go along. All my programs look very messy and after a while I can't even find my way in it. But sooner or later I'll get there...

nivuahc

  • Guest
Weekend challenge
« Reply #20 on: April 12, 2005, 07:20:42 AM »
Quote from: Jimmy D
All my programs look very messy and after a while I can't even find my way in it. But sooner or later I'll get there...


Sounds like you have my programming style down to a T.

And I've been doing it for about 15 years. :)

SMadsen

  • Guest
Weekend challenge
« Reply #21 on: April 12, 2005, 07:27:27 AM »
Is there any other style??

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Weekend challenge
« Reply #22 on: April 12, 2005, 07:41:59 AM »
:)  :)  :)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

TR

  • Guest
Weekend challenge
« Reply #23 on: April 12, 2005, 07:48:14 AM »
Pfft..every program I've ever written looks as if it came straight from the hands of Zeus.


But seriously if you're not a professional programmer and/or you're not programming every day then chances are you're code isn't going to be the best looking stuff around. I have to agree with Chuck on this that as long as it works as intended you should be happy. Then in five years when you're a better programmer you can go back and tweak that while loop to save you 3 milliseconds in execution time.

ronjonp

  • Needs a day job
  • Posts: 7526
Weekend challenge
« Reply #24 on: April 12, 2005, 08:25:20 AM »
Hey Jeff,

I get this when I tried your routine:

Code: [Select]
Command: layers2dwgs
; error: Automation Error. Description was not provided.


What am I doing wrong?

Thanks,

Ron

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

daron

  • Guest
Weekend challenge
« Reply #25 on: April 12, 2005, 10:10:43 AM »
Quote from: Jimmy D
Daron,
...I know there is a right and a wrong way to do things, but if I knew the right way, I wouldn't be reading this forum would I?
I'm new at this and I'm figuring it out as I go along!

Jimmy

Jimmy, the reason I would bring this out isn't to point out that you've done anything wrong. Did I say it was wrong? I don't think so. If I did, I apologize. Why I would bring up what I did, would be to help you learn. This place is about learning and I, as well as many others here are here to both learn from each other and to help others learn. To be perfectly honest, my first year stuff has a lot of bad programming examples. I didn't get beyond it until about five years later when I started visiting sites like this. Your lucky you found them in your first year. You'll learn a lot from this place. I hope when you do, you won't go away, but will contribute to the atmosphere of this place. We can never have too many good people here.

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Weekend challenge
« Reply #26 on: April 12, 2005, 12:42:25 PM »
Jimmy, that is a quick and simple approach which met the requirements. Well done. I will say this, though.....using wblock will allow any and all named layer filters in the original drawing to be copied to all of the new drawings, at least in R2002 and below.

Ron, good question. That error will occur when calling for an item in a collection (usually) that doesn't exist. If you could open the code in the VLIDE, set a break point near the beginning, step through the code while it's running and note at what line it errors I may be able to figure it out

Has anyone else with 2005 tried this?

Water Bear

  • Guest
automation error
« Reply #27 on: April 12, 2005, 12:48:22 PM »
yep..i got the same thing  :shock:

the LayToDwg routine sets the layer current, then attempts to freeze it..which generates an error on that, and subsequently every command in the loop....

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Weekend challenge
« Reply #28 on: April 12, 2005, 12:58:27 PM »
OK, I guess I'll go back and add a ton of error checking with different messages for each one so I can see where it's breaking. I suspect, though, that it is the ObjectDBX reference......and since I only have 2002 to test on, I'm not sure what the newer version nimbers are.

Jimmy D

  • Guest
Weekend challenge
« Reply #29 on: April 13, 2005, 01:19:38 AM »
Quote
Did I say it was wrong? I don't think so. If I did, I apologize.


Absolutely no need to apologize and no offence was taken.
Maybe I sounded at little angry but I'm not.
I'm glad that guys like you try to show me the correct way.