Tutorial: Page (1) of 1 - 11/20/01 Email this story to a friend. email article Print this page (Article printing at MyDmn.com).print page facebook

AutoLISP - Selecting and Scaling Blocks

Select by certain names, scale by insertion points By Robert Rosner
This is an alternate LISP to the previous one at

http://www.digitalcad.com/2001/10_oct/tutorials/autolisp.htm.


This routine will allow the user to select a group of blocks or all of the blocks by a certain name and scale them by their insertion point. It does it's scaling as a reference rather than a scale factor. It will list the current scale factor and then ask you what the new scale factor will be. It does the math for you.

The routine at the end called Default is subroutine that allows the routine to remember your last entry for a particular variable. This SCABLK routine requires it.

Click here to download a txt file of the AutoLISP.

(defun C:SCABLK (/ ss ln cnt tstname e)
(setq expertsetting (getvar "expert"))
(setvar "EXPERT" 5);
(if (= tst nil)
(setq tst "Y")
);end if
(setq tst (strcase (default 'string tst " Do you wish to scale all of
these blocks? ")))
(command ".undo" "m")
(prompt " Setting UCS to WCS for duration of this command. Your UCS will
be restored when completed.")
(command ".ucs" "s" "save01");save ucs settings
(command ".ucs" "world")
(cond
((= tst "N")
(prompt " Select objects to be scaled ")
(setq ss (ssget))
(setq ln (sslength ss))
(setq cnt 0)
(setq tstname (ssname ss cnt))
(setq old (cdr (assoc 41 (entget tstname))))
(setq old (default 'real old " Current Scale Factor: "))
(setq new (default 'real new " New Scale Factor: "))
(while (< cnt ln)
(setq tstname (ssname ss cnt))
(setq pt (cdr (assoc 10 (entget tstname))))
(command "SCALE" tstname "" PT "REF" old new)
(setq cnt (+ 1 cnt))
);end while
(setq cnttxt (rtos cnt 2 0))
(prompt cnttxt)(prompt " Blocks scaled.")
)
((= tst "Y")
(setq e (entsel " Select block to scaled: "))
(setq e (car e))
(setq cnt 0)
(setq ename (cdr (assoc 2 (entget e))))
(setq old (cdr (assoc 41 (entget e))))
(setq old (default 'real old " Current Scale Factor: "))
(setq new (default 'real new " New Scale Factor: "))
(setq sse (ssget "X" (list (cons 2 ename))))
(setq e (ssname sse 0))
(while (/= e nil)
(setq pt (cdr (assoc 10 (entget e))))
(command "SCALE" e "" PT "REF" old new)
(setq sse (ssdel e sse))
(setq e (ssname sse 0))
(setq cnt (+ 1 cnt))
);end while
(setq cnttxt (rtos cnt 2 0))
(prompt cnttxt)(prompt " Blocks scaled.")
)
)
(command ".ucs" "restore" "save01")
(command ".ucs" "delete" "save01")
(setvar "expert" expertsetting)
(princ)
) ;end defun


(DEFUN DEFAULT (vt val promstr / valcomp val)
(terpri)
(setvar "cmdecho" 0)
(prompt promstr) (prompt "") (princ val)
(cond ((eq vt 'real)
(if (setq valcomp (getreal ""))
(setq out valcomp)
(setq out val)
);end if
)
((eq vt 'int)
(if (setq valcomp (getint ""))
(setq out valcomp)
(setq out val)
);end if
)
((eq vt 'string)
(if (= 0 (ascii (setq valcomp (getstring t ""))))
(setq out val)
(setq out valcomp)
);end if
)
((eq vt 'point)
(if (setq valcomp (getpoint ""))
(setq out valcomp)
(setq out val)
);end if
)
);end of cond
);end of defun DEFAULT



Robert J. Rosner, ASLA is aLandscape Architect/Urban Designer. He can be reached at Mailto:RRosner@RATIOArchitects.com.


Page: 1


Related Keywords:AutoCAD, AutoLISP

HOT THREADS on DMN Forums
Content-type: text/html  Rss  Add to Google Reader or
Homepage    Add to My AOL  Add to Excite MIX  Subscribe in
NewsGator Online 
Real-Time - what users are saying - Right Now!

Our Privacy Policy --- @ Copyright, 2015 Digital Media Online, All Rights Reserved