Author Topic: Newbie to world of (Lost in Stupid Parentheses) errr..(List)  (Read 101373 times)

0 Members and 1 Guest are viewing this topic.

amgirard2003

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #315 on: November 24, 2003, 09:56:09 AM »
(cond((= ans "Three")
   (setvar "clayer" "612")
   (not (tblsearch "Layer" "612"))
   (command "layer" "make" "612" "")
   (setvar "celtype" "Three")
)

Does that make any sense?
i was confused with how to apply it to the "COND" function.
If it's not right, How do i apply it to the "COND" function?

daron

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #316 on: November 24, 2003, 10:04:41 AM »
If you are using "make", you don't need to search for it. It will be set whether it exists or not. You might want to consider doing this "_.layer" after command. Look here for the reasons why.

SMadsen

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #317 on: November 24, 2003, 10:11:13 AM »
Andre, as Daron pointed out, you don't really need to check if a layer exists because of how the "Make" option of the LAYER command works.
Thanks Daron ... for clearing up the smoke after my brain fart.

amgirard2003

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #318 on: November 24, 2003, 10:30:24 AM »
How do i properly code it all with "COND"?
I'm confused on this part

JohnK

  • Administrator
  • Seagull
  • Posts: 10646
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #319 on: November 24, 2003, 10:30:54 AM »
I disagree. It may not be needed, but its good pratice in further applications (When he starts coding harder applications) to develp good programing habits. Why "make" a layer when its not needed.  (I undersand, that it could make the code harder to maintain, but its more of a "theory" thing then a "not necessary" thing. ) It will make his error trapping understanding a whole lot easier if he understands the concept of "do what is needed and not what is necessary."

Test the end users enviroment all you can, it will make your code that much more versatile later down the road.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

SMadsen

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #320 on: November 24, 2003, 10:50:04 AM »
Andre, you already coded it using COND here.

If you need more tests within each condition, you simply add it to the chunk of code that follows the condition.

amgirard2003

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #321 on: November 24, 2003, 10:58:25 AM »
O.k i must not have made myself clear in my previous post, but what i'm confused with is this..

(cond ((= ans "Three")
    (setvar "clayer" "612")
    (not (tblsearch "layer" "612"))
    (command ".layer" "make" "612")
    (setvar "celtype" "Three"))
)

This does not work why?
What am i doing wrong in the code? I'm confused on how to write it out so if the layer doesn't not exist then create the layer.

JohnK

  • Administrator
  • Seagull
  • Posts: 10646
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #322 on: November 24, 2003, 11:00:26 AM »
Where is it crashing? (Did you run each line to see what autocad returns?)
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

amgirard2003

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #323 on: November 24, 2003, 11:04:11 AM »
it's crashing because layer "612" doesn't exist.
I want it to create the layer if it doesn't exist

JohnK

  • Administrator
  • Seagull
  • Posts: 10646
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #324 on: November 24, 2003, 11:06:48 AM »
Ok, good. Comment each line of that code you posted and tell us what each line does. (In english)
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

SMadsen

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #325 on: November 24, 2003, 11:09:19 AM »
Always remember to exit the COMMAND function as you would in AutoCAD - usually with an empty response.

(command ".layer" "make" "612") should be
(command ".layer" "make" "612" "")

amgirard2003

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #326 on: November 24, 2003, 11:18:38 AM »
(cond ((= ans "Three") Line 1
(setvar "clayer" "612")  Line 2
(not (tblsearch "layer" "612")) Line 3
(command ".layer" "make" "612") Line 4
(setvar "celtype" "Three")) Line 5
)

Line 1:- If ans equals "three" then do the following
Line 2:- Set layer to "612"
Line 3:- Check and see if layer "612" exist
line 4:- If it doesn't exist then create it
line 5:- Set lintype to "Three"


I think i might have answered my own question but i'll post it for your comments.

I should have line 3 & 4 before line 2 ??

SMadsen

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #327 on: November 24, 2003, 11:40:18 AM »
Quote from: amgirard2003
Line 3:- Check and see if layer "612" exist

It certainly does - but that's all it does. It stands alone as a test condition and is therefore not used for anything. To do something with it, use it as a condition for an IF expression:

Code: [Select]
(cond ((= ans "Three")
      (if (not (tblsearch "layer" "612"))
        (command ".layer" "make" "612" "")
        (setvar "clayer" "612")
      )
      (setvar "celtype" "Three"))
)


This code says:
- if ans is equal to "Three" then do this:
- - if layer 612 does not exist then
- - - make layer 612 (create and set active)
- - otherwise
- - - set layer 612 active
- - set current ltype to "Three"

As Daron pointed out, there's no need to test if the layer exists before using "Make", but this is what you'd do if following Se7en's advice. I think in this case where the end result is setting the layer active, that I would follow Daron's advice. Se7en does have a point about the readability and logic of the code, though.

The real effort should be to see if the linetype exists. Because linetypes are dependent on external files and there are no easy way to simply create it (like a layer), there is a very real chance that it will crash if it doesn't exist.

amgirard2003

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #328 on: November 24, 2003, 11:45:01 AM »
Quote from: SMadsen
To do something with it, use it as a condition for an IF expression:


Code: [Select]
(cond ((= ans "Three")
      (if (not (tblsearch "layer" "612"))
        (command ".layer" "make" "612" "")
        (setvar "clayer" "612")
      )
      (setvar "celtype" "Three"))
)


I've been testing it without the "IF"?
Is it alright to do that as well or should i use it like you showed above?

And another note.. I have the linetype loading but after it's loaded, it's crashing and asking me if i want to reload the layer.

I fixed this problem as well

SMadsen

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #329 on: November 24, 2003, 11:56:16 AM »
No, it's not alright to use the condition as you did. What would be the purpose of it? Try to see the code in a a sequential manner. This is what you wrote:

Quote from: amgirard2003
Line 1:- If ans equals "three" then do the following
Line 2:- Set layer to "612"
Line 3:- Check and see if layer "612" exist
line 4:- If it doesn't exist then create it
line 5:- Set lintype to "Three"


Line 1 is alright, of course. But look at the next line: Set layer to "612". What would be the purpose first to set the layer active and then see if the layer exists?

The interpreter evaluates the code exactly as you write it. It will try to set a layer active when it sees (setvar "CLAYER" "612"), but if the layer doesn't exists it will crash right there.
So the proper sequence is to test if the layer exists and first then set it active if it was found.

Of course, line 4 is wrong all together. There is no IF in it, so the description would be:
line 4:- Create it