Our Friends: Leaflet Printing , Presented by: Talia Cad Software

Sign In

Subscribe

Subscribe to Daily Autocad.


Jan 29
Thursday
AutoLISP, Download, Programming
2 Really Useful AutoLISP Utilities: COPYROT and PICKDEL

Today we added two new AutoLISP application examples to our download section. One of them is COPYROT.LSP. It simply copies the entities that you select and applies the rotate command at the location where they are copied.

;************************************************************
;* COPYROT.LSP										   		*
;************************************************************
;* Copies selected objects and rotates them in their new   	*
;* position. This utility is prepared for instructive		*
;* purposes. It's free for use.								*
;************************************************************
;* (c) Copyright 2007 Taliasoft.com							*
;* www.dailyautocad.com --- www.taliasoft.com				*
;************************************************************

; Let's define our main function 'cr' and local vars

(defun c:cr (/ sel pt)
	(setq ent 1) ; set ent var to 1 for loop

	; Ask user for selection
	(while (= sel nil)				; wait for selection
		(princ "\nSelect objects to copyrot:")
		(setq sel (ssget))
		)

	; Copy selected objects on their own position
	(command "_.COPY" sel "" "0,0" "@")

	; Let's move selected opjects
	(princ "\Please select base point:")
	(setq pt (getpoint))
	(princ "\Select second point:")
	; pause waits user for pick second point
	(command "_.MOVE" "_P" "" pt pause)

	; let's rotate copied objects on their new position
	; first get LASTPOINT value as rotation base point
	(setq pt (getvar "LASTPOINT"))
	(princ "\nPlease enter rotation angle:")
	(command "_.ROTATE" "_P" "" pt pause)

	(princ)
	)

Code.1 Source code of COPYROT.LSP

The other one is PICKDEL.LSP, which deletes the entities that are clicked on.

;************************************************************
;* PICKDEL.LSP										   		*
;************************************************************
;* Deletes picked object till user cancel the command   	*
;* This application is preapered for instructive 			*
;* purposes. It's free for use.								*
;************************************************************
;* (c) Copyright 2007 Taliasoft.com							*
;* www.dailyautocad.com --- www.taliasoft.com				*
;************************************************************

; Let's define our main function 'pd' and local vars

(defun c:pd (/ ent ename sel)
	(setq ent 1) ; set ent var to 1 for loop

	; Start pick loop till ent is nil
	(while (/= ent nil)
		(setq 	ent (entsel)		  ; wait user for pick
				ename (car ent)		  ; get entity name
				sel (ssadd)			  ; create an empty ss
				sel (ssadd ename sel) ; pu picked ent into
				)
		(command "._ERASE" sel "")	  ; Erase selected ent
		)

	(princ)
	)

Code.2 Source code of PICKDEL.LSP

We are increasing the number of examples as a result of many requests from readers. And sooner you will be able to download them from here free. We are also looking forward to see some applications from our readers. Those who are willing to send us some example applications can send us the application files and their short resume together with a 90×120 portrait.

  cr_pd.zip (1.2 KiB, 198 hits)
You need to be a registered user to download this file.

Viewed 3,967 times so far... This week: 65 Today: 10 Latest: 4 July 2009, 20:50

Post Tags: ,

One Response to “ 2 Really Useful AutoLISP Utilities: COPYROT and PICKDEL ”
  1. Bart.Erlings
    Bart.Erlings

    Feb 2, 2009
    Reply

    Hello Orhan,

    I have written a function just like your Pickdel function but white the difference that my function use ssget to select the objects to delete. For my opinion this works better because you can select more objects in one time. This is my version:

    ; Main function ‘pd’

    (defun c:pd (/ oldError -cmdecho- $selectedobjects $impliedselection)
    (setq -cmdecho- (getvar “CMDECHO”))        ; Save current value for cmdecho
    (setvar “CMDECHO” 0)                    ; Set cmdecho to 0

    (setq oldError *Error*)                    ; Define error handler
    (defun *Error* (Melding)
    (Prompt Melding)
    (setvar “CMDECHO” -cmdecho-)
    (setq *Error* oldError)
    (princ)
    )

    (if (setq $impliedselection (ssget “_i”))    ; check if there is a current selection
    (progn                                    ; if true delecte selection
    (setvar “PICKFIRST” 1)
    (command “erase” $impliedselection “”)
    )

    (progn                                    ; If false start a while function
    (while (setq $selectedobjects (ssget “_:s”))    ; While select objects (”_:s” fore single selection)
    (command “erase” $selectedobjects “”)        ; Erase selected objects
    )
    )
    )

    (redraw)
    (setvar “CMDECHO” -cmdecho-)    ; Reset cmdecho value
    (setq *Error* oldError)            ; Reset error handler
    (princ)
    )


Post a Comment



All content and source © 2008 Daily Autocad | News Plus wordpress theme brought to you by Zidalgo.