Questions about some things associated with ssget.

Discussion in 'AutoCAD' started by Friptzap, Apr 15, 2004.

  1. Friptzap

    Friptzap Guest

    I cannot find anything on the apostrophe. What is it's purpose when used in a lisp routine? (ssget "x" '((6 . "name")))

    And I know that 6 is the "number" of the data requested but what is this actually called and where can I fin a list of all the numbers associated with things ?

    One more thing the period. Is this just a separator? What does it do.

    I spent allot of time looking in help and could not find what they do specifically.

    And yes I have a book but it does not say what all these little things do it just shows them.
     
    Friptzap, Apr 15, 2004
    #1
  2. The apstrophe is used to make a list.
    Example:
    (setq a(entget(car(nentsel)))) <- use this on a piece of text results in:

    ((-1 . <Entity name: 411b7e60>) (0 . "TEXT") (330 . <Entity name: 40062cf8>)
    (5 . "9A94") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "TXT50")
    (100 . "AcDbText") (10 100926.0 10901.0 0.0) (40 . 100.0) (1 ."dsn.106")
    (50 . 0.0) (41 . 1.0) (51 . 0.0) (7 . "VDLAAR") (71 . 0) (72 . 0)
    (11 0.0 0.0 0.0) (210 0.0 0.0 1.0) (100 . "AcDbText") (73 . 0))

    As you see there are many 'lists' here, like (8 . "TXT50"), where 8 is the
    Layer and TXT50 is the layername.
    1 is the contents of the textstring, 7 the textstyle used, 40 the
    scalefactor and 10 the insertion point.

    All of these codes are socalled DXF codes.
    If you chech out the help files for it than you will find these code
    strings.
    Try the autocad developer help, type dxf codes and look for an entry like
    Group codes in numerical order.
    There they are listed or find a decent book about autocad.

    So your example would be like: find (ssget) all (x) where Linetype (6) is
    ..... (name)
    It would return a selction with all linetypes with a specific name.

    I hope it clarify's some things for you.

    Jan

    in a lisp routine? (ssget "x" '((6 . "name")))
    actually called and where can I fin a list of all the numbers associated
    with things ?
    it just shows them.
     
    Jan van de Poel, Apr 15, 2004
    #2
  3. The quote (') is to ensure the following expression
    is returned without being evaluated; in other words,
    "return as is; unevaluated". See the quote function
    in the on-line help.

    numbers associated with things ?
     
    michael puckett, Apr 15, 2004
    #3
  4. Friptzap

    Tom Smith Guest

    The apostrophe is used to make a list.

    Not exactly. The apostrophe is simply shorthand for the quote function,
    which is effectively the opposite of the eval function. Eval explicitly
    forces an expression to be evaluated, while quote suppresses evaluation. By
    default every lisp expression is evaluated.

    '(a b c) is exactly the same as (quote (a b c)) which means "return this
    list literally, without evaluating it." Either will return (a b c).

    (list a b c) will return (nil nil nil) because the symbols a b c have not
    been assigned any meaning. The return value of the list function is a list,
    but by default the arguments passed to the list function are evaluated, and
    they each evaluate to nil.

    (list 'a 'b 'c) will return (a b c) because each individual symbol is quoted
    (not evaluated).

    (list 'a b c) will return (a nil nil) -- the quote supresses evaluation of
    a, so it's returned literally, but b and c are evaluated and return nil.

    You have to be careful in building association lists because sometimes you
    want evaluation, sometimes you don't.

    '(( 0 . "text") (8 . "txt50")) will return the list exactly as given. But if
    you need to make a new group using cons, you need to use list rather than
    quote, to avoid suppressing evaluation of the cons.

    (list (cons 0 "text") '(8 . "txt50")) will correctly return ((0 . "text") (8
    .. "txt50")). Note that the second group is quoted, but the association list
    as a whole isn't.

    '((cons 0 "text") '(8 . "txt50")) will attempt to return ((cons 0 "text")
    (quote (8 . "txt50"))) and it will trigger an error, because the interpreter
    attempts to evaluate the cons, in a context where it isn't legal.

    This can be confusing at first, but allowing vs suppression evaluation is a
    key concept in lisp.
     
    Tom Smith, Apr 15, 2004
    #4
  5. Friptzap

    Friptzap Guest

    oh ok that makes sense, although I don't see why it would need to evaluate it in one situation and not another if it where a simple routine I guess it would be to save memory? And is my assumption correct the period is just a separator between the data bit? of the object and the name of the object?
     
    Friptzap, Apr 15, 2004
    #5
  6. Friptzap

    Friptzap Guest

    oh great thanks dxf codes that will make things easier :) didn't know how to look it up cause I didn't know what it was called :) (so the ' makes a list or returns the list un-evaluated?)
     
    Friptzap, Apr 15, 2004
    #6
  7. Lets make it more complicated.
    It makes a list but lets them unevaluated. ;-))
    Really, this "list" is just used to let the ssget"x" function know what to
    search for.
    Therefore in this case the "list" is not evaluated.
    Think a little like the search function at Google, if you put some text
    between quotes ( "..") Google searches for entries that resemble this text.
    The ssget "x" works the same way.

    I hope it gets a little clearer now.

    Jan

    to look it up cause I didn't know what it was called :) (so the ' makes a
    list or returns the list un-evaluated?)
     
    Jan van de Poel, Apr 15, 2004
    #7
  8. Friptzap

    Tom Smith Guest

    oh ok that makes sense, although I don't see why it would need to evaluate
    it in one situation and not another if it where a simple routine I guess it
    would be to save memory?

    Read my reply to Jan and maybe it will be clearer. It's not memory, it's
    program execution. Sometimes you want to deal with things literally --
    unevaluated -- and sometimes you don't. This is particularly important in
    building association lists as per the entity data Jan posted. I gave several
    examples of the results of quoting or not quoting symbols and lists.

    It takes a little while to "get" this concept, but it's important, so be
    patient & ask questions when you have them.
     
    Tom Smith, Apr 15, 2004
    #8
  9. Friptzap

    Friptzap Guest

    Ok I get it now. That makes perfect sense.

    Some times you may want to use the a sometimes you may want to use the a's value. (in a simple form)

    And thanks for all those examples that will be a big help. Sometimes it is hard to see how many ways one single thing can be used and that sure clears this one up a bit. I also assume it can be used in many more locations as well, now that I have seen your list.
     
    Friptzap, Apr 15, 2004
    #9
  10. Friptzap

    Friptzap Guest

    Thanks, I was starting to get that impression. :)
     
    Friptzap, Apr 15, 2004
    #10
  11. Friptzap

    Tom Smith Guest

    And thanks for all those examples that will be a big help. Sometimes it is
    hard to see how many ways one single thing can be used and that sure clears
    this one up a bit. I also assume it can be used in many more locations as
    well, now that I have seen your list.

    There are other cases where you need to suppress evaluation via quote, or
    when you want to explicitly force it via eval, but they're a little more
    obscure. The most common cases are in dealing with association lists in
    creating or modifying entities.

    If you have all the entity data, as needed, you can simply quote the whole
    list. If you need to build groups within the list -- generally with cons --
    you have to use list to define the overall edata list, to allow the cons
    function to be evaluated, and quote there remaining groups per my example.

    Other situations include...

    (apply '+ '(1 2 3)) returns 6. You have to quote the + function in order to
    apply it to the quoted list -- similar with mapcar.

    Examples...

    (setq nums (list 1 2 3)) or (setq nums '(1 2 3)) both return (1 2 3) -- note
    alternative ways of defining the named list, with or without quoting.

    (apply '+ nums) would then also return 6 -- note the unquoted symbol nums is
    evaluated as the list (1 2 3).

    (apply '+ 'nums) causes an error -- apply expects a list, and the literal
    "nums" is undefined. If evaluation is suppressed, nums is meaningless.

    Hope this helps.
     
    Tom Smith, Apr 15, 2004
    #11
  12. Friptzap

    randy benson Guest

    the dot between the 1st and 2nd members of the list make it a special form
    of list called a "dotted pair", which autolisp treats in a special way;
    there's more in the online help...

    quote from Acad 2004 Help: Developer Documentation:

    Another way AutoCAD uses lists to organize data is with a special type of
    list called a dotted pair. This list must always contain two members. When
    representing a dotted pair, AutoLISP separates the members of the list with
    a period (.). Most listhandling functions will not accept a dotted pair as
    an argument, so you should be sure you are passing the right kind of list to
    a function.
    Dotted pairs are an example of an "improper list." An improper list is one
    in which the last cdr is not nil. In addition to adding an item to the
    beginning of a list, the cons function can create a dotted pair. If the
    second argument to the cons function is anything other than another list or
    nil, it creates a dotted pair.

    _$ (setq sublist (cons 'lyr "WALLS")) (LYR . "WALLS")
    it in one situation and not another if it where a simple routine I guess it
    would be to save memory? And is my assumption correct the period is just a
    separator between the data bit? of the object and the name of the object?
     
    randy benson, Apr 15, 2004
    #12
  13. Friptzap

    randy benson Guest

    Sorry. That last is confusing -- it should look like this, where 'command:'
    is the command prompt in the acad drawing editor, and the next line is the
    return value, a dotted pair:

    command: (setq sublist (cons 'lyr "WALLS"))
    (LYR . "WALLS")
    command:
     
    randy benson, Apr 15, 2004
    #13
  14. Friptzap

    Friptzap Guest

    thanks again. good info there for me to review :)
     
    Friptzap, Apr 15, 2004
    #14
  15. Friptzap

    Friptzap Guest

    I think I understand what you mean. I think I need to read up on it a bit more before I fully understand. So in the following this is a doted pair?

    (ssget "x" '((6 . "name")))
     
    Friptzap, Apr 19, 2004
    #15
  16. Yes, that is an example of a dotted pair.

    Also show in long format -
    (ssget "X" (list (cons 6 "name")))

    Another example -
    (ssget "X" '((0 . "text")(8 . "LayerName")))
    (ssget "X" '((cons 0 "text" )(cons 8 "LayerName")))

    You are not limited to only 1 dotted pair!

    Alan
     
    Alan Henderson, Apr 19, 2004
    #16
  17. Friptzap

    Tom Smith Guest

    (ssget "X" (list (cons 6 "name")))
    The first 2 examples are valid: using either and list and cons to build a
    list, or passing a quoted -- literal -- list complete with dots

    The last example is invalid, for the reasons I've described previously. The
    cons in (cons 0 "text") must be evaluated in order to return (0 . "text").
    If you quote the whole list this evaluation is suppressed, and you'll get a
    "bag SSGET list" error.
     
    Tom Smith, Apr 19, 2004
    #17
  18. Sorry about that, it was too early this morning and I didn't test.
     
    Alan Henderson, Apr 19, 2004
    #18
  19. Friptzap

    Friptzap Guest

    Yeah I got that error to. I tried it without the ' but I still got the error. I guess it must need to be written like the other line above it and will not work with the cons? (I am also getting a little ahead of myself here :) )
     
    Friptzap, Apr 19, 2004
    #19
  20. Friptzap

    Tom Smith Guest

    Yeah I got that error to. I tried it without the ' but I still got the
    error.

    Read my reply again.

    (ssget "X" (list (cons 0 "text" )(cons 8 "LayerName"))) is legal. But if you
    quote the filter list, instead of using the list function, you prevent the
    cons from being evaluated and cause an error.

    (cons 0 "text" ) returns (0 . "text")

    '(0 . "text") is identical to (quote (0 . "text")) which also returns (0 .
    "text")

    There is nothing wrong with using cons to construct a dotted pair. But if
    you already know exactly what the dotted pair is, as in (0 . "text"), you
    might as well just quote it.

    Cons is necessary when your filter list includes a variable. Suppose you
    wanted to select everything on a user-supplied layer name.

    (setq layername "TEXT") or whatever

    (cons 8 layername) will then return (8 . "TEXT"), and you can't quote this
    list or you will prevent the cons from working.

    Your filter list can contain both literally quoted groups, and variables,
    for instance

    (ssget "X" (list '(0 . "text" ) (cons 8 layername))) will select all text on
    whatever the layer name is.

    Note the first groups is quoted. The second group is built from a variable,
    using cons. Because the cons has to be evaluated, you can't quote the
    overall list.
     
    Tom Smith, Apr 20, 2004
    #20
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.