Halaman Utama

Senin, 24 November 2014

autolisp programer

Ini hampir sama dgn vis.basic..hanya kode.kode berbeda dan penggunaan berbeda....prinsip sama saja
-----------------------------------------
Sumber:link ke web sumber

Variables are used as the principle means to store values. Files may also be used to
store values, but variables are what store values for short-term use.AutoLISP variables may be any of (4) four "types"; integers, reals, points, or strings. Variables in AutoLISP are automatically "typed" depending on the value they contain, so no "typing" of variables is required.The function SETQ will be used to create a variable. A variable will contain a nil value until some value is bound to it. If you reference a variable before you have assigned a value to it, you will receive nil as the result of the reference.(setq a 3) ;Integer variable (setq a 3.00) ;Real variable (setq a (list 1.50 2.375 1.00) ;Point variable (setq a "This is a string.") ;String variable
-----------------------------------
Variable Naming

When we discussed comments in lesson 3, we neglected to touch on the easiest method of commenting of all; variable names. If you use proper variable names, much of your code can be self-documenting. You need only add comments to code, which is not clear simply by reading it.Variables can be named anything you want providing the first character is alphabetic, and you don't use the reserved characters from lesson 2.Many AutoLISP programmers try to keep variable names to (6) six characters or less. This is due to the way variables are stored in AutoLISP. If a variable name is less than 6 characters AutoLISP only requires (2) two nodes to store the value. If you make the variable name longer than (6) six characters, AutoLISP stores the value in one node and stores a pointer to the name in the other node. The name itself is stored in memory taken from the heap for string storage. Heap space is limited and that is why some programmers try to keep variable names short.Two things have happened that makes this rule not so carved in stone as it used to be. The advent of virtual memory and learning how to program cleanly has done much to solve the problem of running out of memory. I can't do much about the amount of memory in your computer or the amount of memory AutoCAD needs, but I can show you how not to run out of memory by programming in a clean manner.Naming a variable is not like naming the family pet, you can't choose a name cause it's cute or it's what the variable looks like. You need to choose names based on what it is the variable holds. You must look at the variable and its name as being the same thing. If you can't tell what the variable is, maybe you don't need the variable anyway.If a variable holds the point for a line, state that in the variable name. First tell which line, and then tell which point. Variables can be named well or they can be named badly, it's all up to you.Good:CenterLineStartCtrLnStrtCtrLnEndBad:C1 ;Start of centerlineC2 ;End of centerlineThe bad variable names have been made slightly more palatable by the use of comments to say what they are, but the good variable names are much more descriptive and require no comments. Anyone who has programmed for awhile knows comments rarely come easy, sometimes not at all. It is better to give your variables names, which do not need to be explained, so a missing comment later will not lead to confusion about what the variable is holding.Also note that end-line comments no matter how well done, clutter up code and make it harder to read. If you can avoid using end-line comments, you will be much better off.Some times you have many variables that seem to hold the same type values. They may seem the same but there is always something different about them that the name can tell you.Good:TapDrillCenterLineStartTapDrCtrLnStrtTapDrCtrLnEndTapCenterLineStartTapCtrLnStrtTapCtrLnEndBad:TDCSTDCETDSTDEI have seen programmers go as far as giving many pages of comments to explain what each of their variables was supposed to hold. Having a decoder ring is no substitute for proper variable naming. If you give full variable names you will have less commenting and a easier time when hunting problems.
--------------------------------------------
Index variables

Indexes through a loop are one of the areas where it is sometimes difficult to come up with a name. Many programmers have a name they give to all indexes, such as Index, Idx, Ndx, or some such thing that they are comfortable looking at. They know when they read their code what these things are, but others may not. If you are going to use short names for indexes be sure to tell what it is that you are indexing through.Good:PointNdxListNdxFileNdxBad:xIdxNdxAn index variable is like any other variable and needs a proper name to be truly understood.

Status variables

Status variables should be given names better than "flag". Everyone seems to use flag for status variables. The first thing we have to do to give truly meaningful names to variables, is get away from thinking about our problems from the viewpoint of the computer. A flag tells if something is right or wrong, it should be given a name that reflects the item we are checking.Good:FileDonePrintDoneSortDoneStatus variables are not used extensively in AutoLISP programming, but if you use them, give them real names.

Naming guidelines

Variables should be named in a manner that also identifies their scope and / or type.
--------------------------------------------
GLOBAL variables

should be identifiable as such by reading their name. Some people use prefix or suffix notations to accomplish this. An example would be to add a g or g_to the beginning of the variable name:gScrewListThis identifies the variable as a list that is available to all the functions in your program. I am not a fan of putting the "_" character in variable names as a separator. I prefer the naming convention where you capitalize the first letter of each word or abbreviation in the variable name.

CONSTANTS

Are normally capitalized as a way of identifying them. They stand out from the rest of your code so you know they are a constant.

INPUT variables

Are parameters to a function, should not be modified inside the function. It is recommended that you identify input variables so if you see one getting modified you can do something else. It will be easier to read your code and tell which variables are parameters if you identify them in the name. An "i" or "ip" may be prefixed to the name to identify them.

Constants

A CONSTANT in AutoLISP is really nothing more than a variable you have set to a certain value, and know that you shouldn't change to any other value. It's a conceptual, idea rather than a "type" as in...link http://www.draftsperson.net/index.php?title=AutoLISP_Lesson_5_-_VARIABLES