Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 12/15/2018 in all areas

  1. Thanks all - I'm pleased to see that this thread has evolved into an interesting discussion You're most welcome saim - I'm always happy to help those keen to learn. The branching logic that I've implemented in my example is known as 'short-circuit evaluation' or 'McCarthy evaluation' (after John McCarthy, the inventor of LISP); it's a very useful exploit for writing concise code, but just be aware that other languages (for example VBA) don't offer this form of evaluation. Because you have enclosed the three expressions inside outer parentheses, meaning the value returned is then evaluated as a function. Try instead: (defun c:test ( / tstvar ) (initget 128) (setq tstvar (getpoint "\nClick an object ")) ;I will just type a value, like 50 (if (= 'str (type tstvar)) (setq tstvar (distof tstvar)) ) ) Indeed entsel does not support arbitrary input - you would need to roll your own... [color=GREEN];; Selection or Text - Lee Mac[/color] [color=GREEN];; Prompts the user to select an object or enter an arbitrary string.[/color] [color=GREEN];; msg - [str] [Optional] Prompt string[/color] [color=GREEN];; ftr - [lst] [Optional] ssget filter list[/color] [color=GREEN];; Returns: [ent/str] Entity name of selected entity or entered string; "" if enter is pressed.[/color] ([color=BLUE]defun[/color] LM:select-or-text ( msg ftr [color=BLUE]/[/color] gr1 gr2 rtn sel ) ([color=BLUE]setq[/color] msg ([color=BLUE]princ[/color] ([color=BLUE]cond[/color] (msg) ([color=MAROON]"\nSelect object: "[/color]))) rtn [color=MAROON]""[/color] ) ([color=BLUE]while[/color] ([color=BLUE]progn[/color] ([color=BLUE]setq[/color] gr1 ([color=BLUE]grread[/color] [color=BLUE]nil[/color] 14 2) gr2 ([color=BLUE]cadr[/color] gr1) gr1 ([color=BLUE]car[/color] gr1) ) ([color=BLUE]cond[/color] ( ([color=BLUE]=[/color] 3 gr1) ([color=BLUE]if[/color] ([color=BLUE]ssget[/color] gr2) [color=GREEN];; nentselp is slow for xrefs[/color] ([color=BLUE]if[/color] ([color=BLUE]setq[/color] sel ([color=BLUE]ssget[/color] gr2 ftr)) ([color=BLUE]progn[/color] ([color=BLUE]setq[/color] rtn ([color=BLUE]ssname[/color] sel 0)) [color=BLUE]nil[/color]) ([color=BLUE]princ[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\nInvalid object selected."[/color] msg)) ) ([color=BLUE]princ[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\nMissed, try again."[/color] msg)) ) ) ( ([color=BLUE]=[/color] 2 gr1) ([color=BLUE]cond[/color] ( ([color=BLUE]<[/color] 31 gr2 127) ([color=BLUE]setq[/color] rtn ([color=BLUE]strcat[/color] rtn ([color=BLUE]princ[/color] ([color=BLUE]chr[/color] gr2)))) ) ( ([color=BLUE]=[/color] 13 gr2) [color=BLUE]nil[/color] ) ( ([color=BLUE]and[/color] ([color=BLUE]=[/color] 8 gr2) ([color=BLUE]<[/color] 0 ([color=BLUE]strlen[/color] rtn))) ([color=BLUE]setq[/color] rtn ([color=BLUE]substr[/color] rtn 1 ([color=BLUE]1-[/color] ([color=BLUE]strlen[/color] rtn)))) ([color=BLUE]princ[/color] [color=MAROON]"\010 \010"[/color]) ) ( [color=BLUE]t[/color] ) ) ) ( ([color=BLUE]=[/color] 25 gr1) [color=BLUE]nil[/color] ) ( [color=BLUE]t[/color] ) ) ) ) rtn )
    1 point
×
×
  • Create New...