Author Topic: CAD Setup Routine  (Read 62785 times)

0 Members and 2 Guests are viewing this topic.

deegeecees

  • Guest
CAD Setup Routine
« Reply #45 on: January 26, 2004, 01:37:13 PM »
I'll save you the trouble of "LOOKING IT UP". <----hint

An "IF" statement checks for a condition, in this case, Daron combined additional conditions all in the same line to, basically, save space/time, and it's a bit more professional (if there is such a thing).

The "IF" statement now has to do 2 things, if the statement is true, do THIS, if the statement is not true, do THAT.

Are you with me?

daron

  • Guest
CAD Setup Routine
« Reply #46 on: January 26, 2004, 01:52:34 PM »
To the above, IF I (drogers) am invoking the command, do the first statement. If somebody other than drogers is invoking the command, do the other. If you test the test, you'll see that (= (strcase (getvar 'loginname) t) "drogers") in your case will equal nil. If you change "drogers" to whatever your username is, it will return t. If true the first statement will be run. If nil, the second statement will be run. Cond is a little different in that whatever condition is true, all the code inside that block will be run.

Quote from: Andre
I know you'll all be asking why start with a big project like this..

My first undertaking is two pages long. It'd be more if it didn't have reusable code in it. So, I'm not asking why you're starting with a big project like this. What you need to do is create small functions to do each job then call each function in your startup code. You'll understand as you go. Don't eat the whole elephant. Chew on one set of standards at a time, like layers, then whatever else. Create a new function for each piece. We'll show you how to put it together later.

daron

  • Guest
CAD Setup Routine
« Reply #47 on: January 26, 2004, 01:54:05 PM »
to find out what your loginname is, if you're unsure, test this (getvar 'loginname).

amgirard2003

  • Guest
CAD Setup Routine
« Reply #48 on: January 26, 2004, 02:12:19 PM »
Yupe i'm with ya on the IF statement

I can understand about making small functions for each part and then put it all together in the end..

I have made one quick function for the layers

Code: [Select]


(defun newlayers (/ cmd clay)
 (setq cmd (getvar "cmdecho")
 (setq clay (getvar "clayer" "0")
 (setvar "cmdecho" 0)
(command ".layer" "m" "1" "c" "1" "" ""
                ".layer" "m" "2" "c" "2" "" ""
                ".layer" "m" "3" "c" "3" "" ""
)
(setvar "clayer" "1")
(setvar "clayer" clay)
(setvar "cmdecho" cmd)
(princ)


i haven't come up with a full list for the layers... but this gets my point out..
what are your thoughts?

daron

  • Guest
CAD Setup Routine
« Reply #49 on: January 26, 2004, 02:32:18 PM »
Here's  a good place to start. A lot of reading, but about midway through the second page, you'll find Smadsen getting really involved. I'd scan/read through the entire 5 pages. It may be very close to what you're looking to do. Do a search for other threads using layer as a keyword in vlisp hackers and see what else you come up with.

amgirard2003

  • Guest
CAD Setup Routine
« Reply #50 on: January 26, 2004, 02:40:19 PM »
Thanks Daron,

I'll Print it out and add it to my homework pile..

deegeecees

  • Guest
CAD Setup Routine
« Reply #51 on: January 26, 2004, 02:46:59 PM »
Very nicely commented. Stig is more than just... well... Stig. Where was this forum when I was starting out, sheesh. I'd spend days poking around and testing this and that, and now people can get full functions, commented even.

SMadsen

  • Guest
CAD Setup Routine
« Reply #52 on: January 27, 2004, 04:31:43 AM »
Quote from: deegeecees
Where was this forum when I was starting out, sheesh.

I don't think Mark would have enough bandwidth for that   :lol:  :lol:  :lol:


Andre, you're doing a good job trying to figure it out but somehow I don't think you have the patience to do an even better job. Whether or not that assumption is right, it's not uncommon to lack patience - especially when trying to squeeze a little coding in between daily choirs.

But - and I think most here can testify to this - if you don't try to figure out exactly what it is you are asking the machine to do then you'll spend twice, triple or quadruple the amount of time writing, editing and debugging code.

The rather simple code that Daron posted is an excellent example of how more understanding could be gained by testing .. and testing and testing.

When you look up the IF function in the help reference ('cos you did that, right?), it will tell you that the first expression is a test expression, that the second expression will be evaluated if the test expression is not nil and that the third expression will be evaluated if the test expression is nil.
That's ALL you need to know about IF. Understanding that very basic concept allows you to decipher any IF statement - at first by testing and later by merely looking at it.

So, how to test Daron's IF statement? You made the first step, which is to  identify each of the components that the IF statement is made up of:

Code: [Select]

function name  :  (if
test expression:    (= (strcase (getvar "loginname") t) "drogers")
2nd expression :    (command ".zoom" "")    ; line 1
3rd expression :    (command ".zoom" ".9X") ; line 2
end of function:  )


Now use the command line in AutoCAD and test each component. The expression that makes the decision is the test expression, which is always the first expression (as pointed out in the help file). Break it down, identify each component and test it, always starting with the innermost expressions:

Command: (getvar "loginname")
"andre"

Command: (strcase (getvar "loginname") t)
"andre"

Hmmm, you might say, this gives the same answer so why use STRCASE? Let's test that function. Looking it up in the help reference will tell you that it converts a string to either uppercase or lowercase. The third argument, if present, specifies which operation to perform. Test it to understand it:

Command: (strcase (getvar "loginname"))
"ANDRE"

Command: (strcase "AnDrE")
"ANDRE"

Command: (strcase "AnDrE" t)
"andre"

Ahh, so Daron may have experienced that login names comes in all forms and shapes and wants to make sure that he is only comparing lowercase strings. That's why he added the second argument, T.

Now that you have deciphered all arguments to the equality function, test it:

Command: (= "andre" "drogers")
nil

Command: (= "drogers" "drogers")
T

Command: (= "DRogers" "drogers")
nil

Now you know what IF has to work with in order to decide which expression to choose, the second or the third. If the test is not nil then it chooses to evaluate the second expression. If the test is nil then the third. The outcome of the test expression is the "pointer" to the selected statement.

To sum it up, if you are not quite sure why a statement does as it does then TEST it. Break it down into components and test each of the components. Think of the command line as being your own personal code testing tool!
Have the help file ready in the background, already opened at the "AutoLISP reference" so you can quickly identify the arguments to a function. Note which data types that the function accepts and compare them to your test results.

amgirard2003

  • Guest
CAD Setup Routine
« Reply #53 on: January 27, 2004, 08:17:02 AM »
Smadsen:-

Thanks for clearing a big fog that was in front of my eyes...
You're the first person that has posted a message like this for me, to help me figure out what i'm doing..
Like you said i some times run out of patience in trying to figure what i'm doing but like the sayings goes

Quote

If I'm reading Chinese and I don't know Chinese... I'm not gonna get too far.


And that's when i get frustrated...
And i know it frustrates other people trying to teach me how to write code and so on...
I look for any kinds of tips that will help me think my way through a project, conceptually and coding wise as i've never had any programming experience ever.....


I know in my head that it will take a lot of time and a lot of practice before i will get a hold on what i'm doing and then be able to do things on my own and i'm willing and wanting to get to that point...

daron

  • Guest
CAD Setup Routine
« Reply #54 on: January 27, 2004, 09:31:56 AM »
Good! Stig, that was an awesome example. Thanks for the complement. You hit the nail right on the head about the strcase username thing.

Andre', you've used cond statement in previous code, yet lacked understanding of IF. Now that you have a new found knowledge of IF and a little understanding of cond, I have a challenge for you. Study, test and describe, the elements of each function; what makes them similar, what makes them different, and what in both cases, will make or allow them to perform actions on multiple items for one true statement. Example
Code: [Select]

(cond (t
          (do this)
          (do this)
          (do this)
         )
         (t
          (do this)
          (do this)
          (do this)
         )
)
(if (t)
    (what goes here
     (do this)
     (do this)
    )
    (and here, to make this work?
     (do this)
     (do this)
    )
)

I don't want a quick answer. I want you to have a better understanding of both. Remember, test, test, test. Find code on this forum. Pick it apart, test it and understand.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
CAD Setup Routine
« Reply #55 on: January 27, 2004, 09:33:09 AM »
am2003,

Your first project is a bit ambitious in my opinion
but it looks like you are making progress.

The folks helping you are VERY knowledgable and sometimes
they assume you understand the first time you are told.
I myself have to redo several times before I fully understand
and then there are some aspects that I don't learn until later.

What I am trying to say is hang in there and they will get you there.

Stepping through each bit of code in the VLIDE and watching the flow
and the LAST VALUE will tell you volumes.
You know how to watch the LAST VALUE, right?
Just making sure, as it's very important.

Hang in there.

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

amgirard2003

  • Guest
CAD Setup Routine
« Reply #56 on: January 27, 2004, 10:03:40 AM »
Quote from: CAB
am2003,

Stepping through each bit of code in the VLIDE and watching the flow
and the LAST VALUE will tell you volumes.
You know how to watch the LAST VALUE, right?
Just making sure, as it's very important.

CAB


Can you elaborate more on this point.. don't quite know what you mean?

daron

  • Guest
CAD Setup Routine
« Reply #57 on: January 27, 2004, 10:12:07 AM »
Here is a tutorial I wrote on the vlide. It isn't complete, but it should help you learn how to use the inspect button to test code. I personally like testing with the inspect button rather than testing on the command line. It gives a little more detail about the results of a test. I think Stig's site also has a tutorial on the vlide. I'm not sure though.

As far as CAB's post, "watch" is really the key word there. There is a watch window that reads the value of each variable you tell it to watch.

SMadsen

  • Guest
CAD Setup Routine
« Reply #58 on: January 27, 2004, 10:49:52 AM »
Quote from: Daron
I think Stig's site also has a tutorial on the vlide.

Nope, sorry (but sign up for the course and you'll get a mini tutorial .. umm, when translation is done :) )
I might put it there later this year, though.

daron

  • Guest
CAD Setup Routine
« Reply #59 on: January 27, 2004, 11:08:30 AM »
Must've been on Afralisp then.