Daily AutoLISP Dose |
|
|
This is not meant to be a tutorial for AutoLISP. Because AutoCAD is not wedded to a single customization tool, randomly code for any topic from AutoLISP, VBA, hatch patterns, linetypes, menus, shape, AutoCAD script, is taken up daily. A detailed explaination follows the code along with some useful hints and tips. For tutorials, go to the Tutorials 4U page. Tons of other code are also available from the AutoLISP Projects and Source C:ode pages on this site. Saturday late nights - is DCL time. On Sundays, I shall take up VBA. 6 December 2000 : Thursday Todays topic : AutoLISP (Q.LSP) Single key shortcut to 12 AutoCAD commmands ;;; Written by : Tushar Suradkar (CadGuruCool) ;;; Enter Q at the command: prompt and select ;;; an entity in the drawing area. (defun c:q (/ COM ENT1) <1> (setq ENT1 (entget (car (entsel)))) <2> (setq COM (cdr (assoc 0 ENT1))) <3> (command COM) <4> ) <5> A very small piece of code today; but lots of punch and power. This one lets you issue 12 AutoCAD commands in a jiffy. These are line, circle, point, insert, ellipse, arc, ray, construction line, multiline, spline and text. All that with a single key press. Wow thats incredible ! sounds impossible. But its true. By the way, if you weren't busy nourishing your lazy bone and didn't count em, those are only 11 commands. True again. The single and most important - the pline - left out, deserves special treatment and I will hopefully take it up tommorow. Chalo! Back to our topic. By now, you must have guessed it correctly, the Q key is the only one you have to press against , which sets ENT1 to the entity association list of the object you select, of course after prompting you to select objects. Its actually car which strips off the rhs part for you. assoc takes over next and extracts the meaty part - the 0 dotted pair - followed by cdr, which grabs the actual command that we are going to use. For example, if you selected a construction line, XLINE is what is stored inside the COM variable as a string. Finally, the string is passed to the command function of AutoLISP, which issues it to AutoCAD.Thats all to it. So now every time you hit Q, Q.LSP prompts you to select objects and starts the same command as the entity you picked.Try this one for all those entity promised early on. Q.LSP : AutoLISP function Synopsis 1) defun xxx() and defun c:xxx(), car, cdr and command - enough of these now. I will revise them again atleast two weeks later. New functions : 2) entsel - Pauses processing and prompts for the selection of an entity. Syntax: (entsel prompt) Return value: A list containing the selected entity name and the point used to select it. The prompt argument is optional. If supplied, this argument is a character string displayed while AutoLISP pauses and waits for the user to pick an entity. If the argument is not supplied, AutoCAD uses the default "select object:" prompt. More examples: (entsel) results in select object: ( The rhs part (7.43842 4.57087 0.0) is stripped off by car discussed next. This list gives the coordiantes of the point where you picked the entity. while, (entsel "Pick object:) results in Pick objects: ( Remember:
Syntax: (entget ent list) Return value: The entget function requires an entity name, either stored in a memory variable or returned by a nested function. The latter is done in Q.LSP The list argument is optional. If supplied, it must be a list containing the name(s) of the registered application(s) that use the extended entity data. These name(s) are formatted as strings. If extended entity data exists for the entity specified by ent, the extended data for each application named in the list is also returned, as part of the entity's association list . More examples: (entget ent) results in ((-1 . < Entity name: 1494d58 >) (0 . "RAY") (330 . < Entity name: 1494cf8 >) (5 . "2B") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (100 . "AcDbRay") (10 4.78945 3.15354 0.0) (11 0.881663 0.47188 0.0)) Remember:
Tomorrow : I will show you how to include polyline as a selectable entity to this routine. Till then happy Qing. Bye... |