Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

AutoLisp Examples - Requested Programs PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11
At a glance
Powered by AI
The document describes several AutoLisp programs that were requested by users to perform various tasks in AutoCAD drawings.

The CopyC.lsp, GetArea.lsp, GetAcre.lsp, DLD.lsp, LTR.lsp, TXTCNT.lsp, TEXTIN.lsp, and TEXTOUT.lsp programs are described.

The CopyC.lsp program allows the user to continuously copy selected entities with preset distance and angle defaults.

8/14/13

AutoLisp Examples - Requested Programs

AutoLisp Home Home

AutoLisp Example Programs Most From Users Request

Download Temple Run Game


MoboGeni 1000s of Android Games & Apps. Save Mobile Data Cost. Try Mobogenie Now

CopyC.lsp - Wendy Diffendall, the Senior CAD Drafter at Facilities Planners + Architects in Harrisb
PA. wanted a program to do multiple Copies with preset defaults.

GetArea.lsp - Jamey Westmoreland, a Civil Engineer E.I.T. for Toothman-Orton Engineering Co. in
ID wanted a program to label the accumulated area of selected polyline entities.

GetAcre.lsp - Bruce Stanton wanted a program to label each polyline entity with the area in square fe
and acreage.

DLD.lsp - An anonymous visitor wanted a program to draw a vertical line next to multiple lines of tex
during a Dim Leader command. Sounds easy right? Yeesh!

LTR.lsp - Jamey Westmoreland, a Civil Engineer E.I.T. for Toothman-Orton Engineering Co. in Boi

wanted a program to select a Line entity, a Text entity, then rotate the text entity based on the angle o line.

TXTCNT.lsp - An anonymous visitor wanted a program to count how many times each text entity
appeared in a drawing and display the results sorted in a dialog box.

TEXTIN.lsp - A program to read from a text file and write to an AutoCAD drawing. TEXTOUT.lsp - A program to read from an AutoCAD drawing and write to a text file. Support this Site!

A U T O L I S P

CopyC.lsp
program to make the Copy command continuous. Ask for a distance, ask for an angle, set them as defaults, then Copy Continuously. [ The Copy, Array and Offset commands were not cutting it!] ; C o p y C . l s p-C o p yC o n t i n u o u s ( d e f u nC : C C ( ) ; t u r no f ft h es y s t e me c h o ( s e t v a r" c m d e c h o "0 ) ; s e tt h ee x i tn o t et ob es u c c e s s f u l ( s e t qe r n o t e" \ n. . . C C . l s pC o m p l e t e ! " ) ; g e tas e l e c t i o ns e t ( i f ( s e t qe s e t ( s s g e t ) ) ( p r o g n

Wendy Diffendall, the Senior CAD Drafter at Facilities Planners + Architects in Harrisburg, PA. wan

A U T O
www.jefferypsanders.com/autolisp_examp.html#GetArea.lsp

; s e tt h eb a s ep o i n t[ b p t ]t ob et h ec e n t e ro ft h es c r e e n ; a n ds e ts o m ev a r i a b l e st on o t h i n g ( s e t qb p t( g e t v a r" v i e w c t r " )d i sn i la n gn i la n s" "a c u D i sn i l )

; i ft h eg e td i s t a n c ef u n c t i o nr e t u r n ss o m e t h i n gi n v a l i d . . .k e e p t r y i n g ( w h i l e ( n o t ( s e t qd i s ( g e t d i s t( g e t v a r" v i e w c t r " )" \ nD i s t a n c e :" )

; i ft h eg e ta n g l ef u n c t i o nr e t u r n ss o m e t h i n gi n v a l i d . . .k e e p t r y i n g ( w h i l e ( n o t ( s e t qa n g ( g e t a n g l e( g e t v a r" v i e w c t r " )" \ nA n g l e :" ) ) ) ; s e tt h ea c c u m u l a t e dd i s t a n c ev a r i a b l et oe q u a lt h ed i s t a n c e v a r i a b l e 1/11

8/14/13

O L I S P

AutoLisp Examples - Requested Programs v a r i a b l e ( s e t qa c u D i sd i s )

; w h i l et h eu s e rd o e sn o tw a n tt oe x i t ( w h i l e ( / =a n s" X " )

d i s ) ) )

; p r i n tt h ec u r r e n ta n g l ea n dd i s t a n c et ot h ec o m m a n dl i n e ( p r i n c( s t r c a t" \ nA n g l e="( a n g t o sa n g )"D i s t a n c e="( r t o

; f i n do u tw h a tt h eu s e rw a n t st od o . . . . r e t u r na l la n s w e r si n u p p e r c a s e ( s e t qa n s ( s t r c a s e ( g e t s t r i n g" \ ne X i t / A n g l e / D i s t a n c e / E n t e rt oC o p y : X / A / D < e n t e r > :" ) )

A U T O L I S P
a w a y

) ; i ft h eu s e rp r e s s e se n t e rt h e n ( i f ( =a n s" " ) ( p r o g n

; c o p yt h ee n t i t i e sf r o mt h e[ b p t ]t ot h ea c c u m l a t e dd i s t a ( c o m m a n d" c o p y "e s e t" "b p t( p o l a rb p ta n ga c u D i s ) )

2 4 "f r o m o r i g i n a l a d d e dt o

; s e tt h ea c c u m u l a t e dd i s t a n c et ob ef a r t h e rf r o mb a s ep o i ; i no t h e rw o r d s . . . i fd i s=2 4 "t h e nt h e1 s tc o p ys h o u l db ; t h eo r i g i n a l . . . . t h es e c o n dc o p ys h o u l db e4 8 "f r o mt h e

; t h e[ a c u D i s ]v a r i a b l eh o l d st h i sd i s t a n c e .I tg e t s[ d i s ] ; i te a c hl o o p . ( s e t qa c u D i s ( +a c u D i sd i s ) ) )

A U T O L I S P

t h e

; i ft h eu s e rp r e s s e sXt oe x i to rt y p e st h ew o r dE X I Tt h e ns e ; [ a n s ]v a r i a b l et oe q u a l" X " .T h ep r o g r a mw i l le x i t . ( i f ( =a n s" E X I T " ) ( s e t qa n s" X " ) ) ; i ft h eu s e rw a n t st oc h a n g et h ea n g l e .[ a n g ] ( i f ( o r ( =a n s" A N G L E " ) ( =a n s" A " ) ) ( w h i l e ( n o t ( s e t qa n g ( g e t a n g l e( g e t v a r" v i e w c t r " )" \ nA n g l e : )

" ) ) ) )

" ) ) ) )

; i ft h eu s e rw a n t st oc h a n g et h ed i s t a n c e[ d i s ] ; d o n ' tf o r g e tt or e s e tt h ea c c u m u l a t e dd i s t a n c e[ a c u D i s ] ( i f ( o r ( =a n s" D I S T A N C E " ) ( =a n s" D " ) ) ( p r o g n ( w h i l e ( n o t ( s e t qd i s ( g e t d i s t( g e t v a r" v i e w c t r " )" \ nD i s t a n ) ( s e t qa c u D i sd i s )

; s e tt h ee x i tm e s s a g et ob eu n s u c c e s s f u li fn o t h i n gw a ss e l e c t e d ( s e t qe r n o t e" \ nE r r o r-N o t h i n gS e l e c t e d ." )

A U T O L
www.jefferypsanders.com/autolisp_examp.html#GetArea.lsp

; r e s e tt h es y s t e me c h o ( s e t v a r" c m d e c h o "1 ) ; p r i n tt h ee x i tm e s s a g et ot h ec o m m a n dl i n e ( p r i n ce r n o t e ) ; s u p p r e s st h ef i n a le c h o ( p r i n c ) ) ; e n do fp r o g r a m Download this file: Click Here!


2/11

8/14/13

L I S P

AutoLisp Examples - Requested Programs

GetArea.lsp

Jamey Westmoreland, a Civil Engineer E.I.T. for Toothman-Orton Engineering Co. in Boise ID wante program to label the accumulated area of selected polyline entities. ; G e t A r e a . l s p-T o t a lt h ea r e a so fs e l e c t e dp o l y l i n ee n t i t i e s . ; W a r n i n g . . . . T h i sw i l la l s or e t u r na na r e af o ra ne n t i t yt h a ti sn o t e n c l o s e d . ( d e f u nC : G e t A r e a ( ) ; t u r no f ft h es y s t e me c h o ( s e t v a r" c m d e c h o "0 ) ; s e tu pav a r i a b l et oh o l dt h ea c c u m u l a t e da r e a s ( s e t qm y A r e a0 )

A U T O L I S P

; w h i l et h eu s e rk e e p sm a k i n gas e l e c t i o n ( w h i l e ( s e t qe n t ( e n t s e l ) ) ; i fa ne n t i t yw a ss e l e c t e da n dn o tap o i n ti ns p a c e ( i f ( c a re n t ) ( p r o g n

; l e tA u t o C A Dg e tt h ea r e ao ft h eo b j e c t . . . c h e a py e te f f e c t i v w a yo u t . ; N o t e :A u t o C A Ds t o r e st h ea r e ai nt h es y s t e mv a r i a b l e" A r e a " ( c o m m a n d" a r e a "" O b j e c t "( c a re n t ) ) ; p r i n tt h ea r e at ot h ec o m m a n dl i n e ( p r i n c " A r e a " ) ) ) ) ; a c c u m u l a t et h ea r e ai fi te x i s t ( i f( g e t v a r" A r e a " ) ( s e t qm y A r e a ( +m y A r e a( g e t v a r" A r e a " ) ) ) ) ( s t r c a t" \ nT o t a lA r e af o rt h i sO b j e c t="( r t o s( g e t v a r

; a s kf o rat e x ti n s e r t i o np o i n t ( s e t qp t 1 ( g e t p o i n t" \ nI n s e r t i o nP o i n t :" ) ) ; p r i n tt h ea r e ai nt h ed r a w i n g ( c o m m a n d" t e x t "p t 1" "" "( s t r c a t" T o t a lA r e a :"( r t o sm y A r e a ) ) ) ; p r i n tt h ee x i tm e s s a g et ot h ec o m m a n dl i n e ( p r i n c" \ n. . . G e t A r e a . l s pC o m p l e t e .\ n" ) ; s u p p r e s st h el a s te c h o ( p r i n c ) ) ; e n do fp r o g r a m Download this file: Click Here!

A U T O L I S P

GetAcre.lsp

Bruce Stanton wanted a program similar to the one above. Except, he wanted to label each polyline e with the area in square feet and acreage. ; G e t A c r e . l s p-G e tt h ea r e ao fas e l e c t e dp o l y l i n ee n t i t y . ; W a r n i n g . . . . T h i sw i l la l s or e t u r na na r e af o ra ne n t i t yt h a ti sn o t e n c l o s e d . ( d e f u nC : G A ( ) ; t u r nt h es y s t e me c h oo f f ( s e t v a r" c m d e c h o "0 )

A U
www.jefferypsanders.com/autolisp_examp.html#GetArea.lsp

; s e tu pt h ee x i tm e s s a g e ( s e t qe r n o t e" \ n. . . G A . l s pC o m p l e t e ." ) ; s e tu pav a r i a b l et oh o l dt h ea r e a ( s e t qm y A r e a0 ) ; s e l e c to n eo b j e c t ( s e t qe n t ( e n t s e l ) )


3/11

8/14/13

T O L I S P

AutoLisp Examples - Requested Programs

; i fa no b j e c tw a ss e l e c t e da n dn o ts o m ep o i n ti ns p a c e ( i f( c a re n t ) ( p r o g n

; g e tA u t o C A Dt of i n dt h ea r e ao ft h ep o l y l i n e ,c h e a py e te f f e c t w a yo u t ; N o t e :A u t o C A Ds t o r e st h ei n f o r m a t i o ni nt h es y s t e mv a r i a b l e " A r e a " ( c o m m a n d" a r e a "" O b j e c t "( c a re n t ) ) ; g e tt h ea r e af r o mt h es y s t e mv a r i a b l e" A r e a "a n dc o n v e r tf r o m ; s q u a r ei n c h e st os q u a r ef e e t ( s e t qm y a r e a( / ( g e t v a r" A r e a " ) 1 4 4 . 0 ) ) ; p r i n tt h es qf e e tt ot h ec o m m a n dl i n e ( p r i n c" \ nT o t a lS q u a r eF e e t:" ) ( p r i n c( r t o sm y A r e a ) ) ; p r i n tt h ea c r e a g et ot h ec o m m a n dl i n ea f t e rc o n v e r t i n g ( p r i n c" \ nT o t a lA c r e a g e:" ) ( p r i n c( r t o s( /m y A r e a4 3 5 6 0 . 0 ) ) )

A U T O L I S P

; a s kt h eu s e rf o ra ni n s e r t i o np o i n tf o rt h et e x t ; i ft h eu s e rp r e s s e se n t e rt h e nb yp a s st h ei n s e r t i o np r o c e d u r e ( i f ( s e t qp t 1 ( g e t p o i n t" \ nI n s e r t i o nP o i n t :" ) ) ( p r o g n ; p r i n tt h es qf e e to nt h ed r a w i n g ( c o m m a n d" t e x t "p t 1" "" " ( s t r c a t" T o t a lS q u a r eF e e t:"( r t o sm y A r e a ) ) ) d r a w i n g ; m o v et h et e x ts t a r t i n gp o i n ta n dp r i n tt h ea c r e a g eo nt h e

( c o m m a n d" t e x t " ( p o l a rp t 1( *p i1 . 5 )( *1 . 5( g e t v a r" t e x t s i z e " ) ) ) " "" "( s t r c a t" T o t a lA c r e a g e:"( r t o s( /m y A r e a4 3 5 6 0 . 0 ) )

) ; c l o s et h ei fp r o g nf o rp o i n ts e l e c t i o n ) ) ; c l o s et h ei f ; c l o s et h ei fp r o g nf o ro b j e c ts e l e c t i o n

; i fn o t h i n gw a ss e l e c t e dt h e nc h a n g et h ee x i tn o t et ob e u n s u c c e s s f u l ( s e t qe r n o t e" \ nE r r o r-N o t h i n gS e l e c t e d . " )

A
Related Searches: POP Accounts Gmail Filters Txt File Text Encryption Software Native POP3 Connector

; c l o s et h ei fs t a t e m e n t

U T O L I S P
)

; p r i n tt h ee x i tn o t et ot h ec o m m a n dl i n e ( p r i n ce r n o t e ) ; r e s e tt h es y s t e me c h ov a r i a b l e ( s e t v a r" c m d e c h o "1 ) ; s u p p r e s st h el a s te c h o ( p r i n c )

;E n do fp r o g r a m Download this file: Click Here!

DLD.lsp

Visitor wanted a program that would draw a vertical line next to multiple lines of text during a Dim Le command. Sounds simple right? Yeesh! ; D L D . l s p-D r a wav e r t i c a ll i n en e x tt om u l t i p l el i n e so f ; t e x td u r i n gad i ml e a d e rc o m m a n d . ( d e f u nC : D L D ( ) ; t u r ns y s t e me c h oo f f ( s e t v a r" c m d e c h o "0 ) ; g e tt h es t a r tp o i n to ft h el e a d e rl i n e ( s e t qp t 1 ( g e t p o i n t" \ nS t a r tP o i n t :" ) )

A U
www.jefferypsanders.com/autolisp_examp.html#GetArea.lsp

; s e t u ps o m ev a r i a b l e st ob eu s e dl a t e r ; [ t p 1 ]i sat e m p o r a r yp o i n t ; [ c n t r ]i sac o u n t e r ; [ t h t ]h o l d st h ec u r r e n tt e x ts i z e
4/11

8/14/13

U T O L I

AutoLisp Examples - Requested Programs ; [ t h t ]h o l d st h ec u r r e n tt e x ts i z e ( s e t qt p tp t 1c n t r0t h t( g e t v a r" t e x t s i z e " ) )

; u n r e m a r kt h en e x tl i n ea n dr e p l a c eY O U R _ L A Y E R _ N A M Ew i t hy o u rl a y e r n a m e , ; t h i sw o u l db et h el a y e rn a m ef o ry o u rl e a d e rl i n e sa n da r r o wh e a d . ; I fy o ua r eu s i n gav e r s i o no fa u t o c a da b o v e1 4y o um i g h th a v et o r e p l a c e ; " l a y e r "w i t h" l a y e r "o rp e r h a p s" _ l a y e r " .Y o uc o u l dw r i t eaf u n c t i ; t oc h e c kt h ev e r s i o no fa u t o c a da n dd e c i d ew h i c ht ou s ea tt h a tp o i ; ( c o m m a n d" l a y e r "" s e t "" Y O U R _ L A Y E R _ N A M E "" " ) ; l o o pu n t i lt h eu s e rq u i t ss e l e c t i n gp o i n t s ( w h i l e( / =n i l ( s e t qt p t ( g e t p o i n t t p t " \ nN e x tP o i n t :" ) ) ) Trust Rating ; i fi ti st h ef i r s tp o i n tt h eu s e rh a ss e l e c t e d jefferypsanders.com ( i f ( =c n t r0 )
Not Yet Rated

WebCake Ads

S P A U T O L I S P

; s t a r tt h el e a d e rc o m m a n dt og e ta na r r o wh e a da n dt h ef i r s tl i ; t h e nu s et h e( c o m m a n d )f u n c t i o nt oe x i tt h el e a d e rc o m m a n d ( c o m m a n d" d i m 1 "" l e a "p t 1t p t( c o m m a n d ) ) ; e l s ej u s td r a wl i n e s ( c o m m a n d" l i n e "o l d p tt p t" " )

; i n c r e m e n tt h ec o u n t e r ( s e t qc n t r ( +c n t r1 ) ) ; g e tt h ea n g l eo ft h el a s tl i n ed r a w n ( s e t qa n g l ( a n g l eo l d p tt p t ) ) ; s a v et h el a s tp o i n td r a w n ( s e t qo l d p tt p t ) ) ; f i n dt h el o c a t i o nf o rt h et e x tu s i n gt h e ; t e x ts i z et i m e s0 . 2 5 ( s e t qt x p t ( p o l a ro l d p ta n g l( *t h t0 . 2 5 ) ) ) ; l o o pw h i l et h eu s e rt y p e si ns o m e t h i n gb e s i d e s< e n t e r > ; t h eTa l l o w ss p a c e si nt h et e x ts t r i n g ( w h i l e ( / =" "( s e t qs t r ( g e t s t r i n gT" \ nT e x t :" ) ) )

A U T O L I S P

; u n r e m a r kt h en e x tl i n ea n dr e p l a c eY O U R _ L A Y E R _ N A M Ew i t hy o u rl a y n a m e . ; t h i sw o u l db et h el a y e rn a m ef o ry o u rt e x t .I fy o ua r eu s i n ga v e r s i o n ; o fa u t o c a da b o v e1 4y o um i g h th a v et or e p l a c e" l a y e r "w i t h o r ; p e r h a p s" _ l a y e r " .Y o uc o u l dw r i t eaf u n c t i o nt oc h e c kt h ev e r s i o o f ; a u t o c a da n dd e c i d ew h i c ht ou s ea tt h a tp o i n t . ; ( c o m m a n d" l a y e r "" s e t "" Y O U R _ L A Y E R _ N A M E "" " ) ; c h e c kt h el a s tl i n ea n g l et od e c i d ew h e t h e rt h et e x t ; s h o u l db eL e f to rR i g h tJ u s t i f i e d . ( i f ( o r ( <a n g l( /p i0 . 5 ) ) ( >a n g l( *p i1 . 5 ) ) ) ; l e f tj u s t i f i e d ( c o m m a n d" t e x t "" j "" M L "t x p t" "0s t r ) ; r i g h tj u s t i f i e d ( c o m m a n d" t e x t "" j "" M R "t x p t" "0s t r )

; u n r e m a r kt h en e x tl i n ea n dr e p l a c eY O U R _ L A Y E R _ N A M Ew i t hy o u rl a y n a m e . ; t h i sw o u l db et h el a y e rn a m ef o rt h ev e r t i c a ll i n en e x tt ot h e t e x t . ; I fy o ua r eu s i n gav e r s i o no fa u t o c a da b o v e1 4y o um i g h th a v et o r e p l a c e ; " l a y e r "w i t h" l a y e r "o rp e r h a p s" _ l a y e r " .Y o uc o u l dw r i t ea f u n c t i o n ; t oc h e c kt h ev e r s i o no fa u t o c a da n dd e c i d ew h i c ht ou s ea tt h a t p o i n t . ; ( c o m m a n d" l a y e r "" s e t "" Y O U R _ L A Y E R _ N A M E "" " ) ; d r a wt h ev e r t i c a ll i n e ( c o m m a n d" l i n e " ( p o l a ro l d p t( *p i0 . 5 )( /t h t2 . 0 ) ) ( p o l a ro l d p t( *p i1 . 5 )( +( /t h t2 . 0 ) ( *t h t0 . 2 5 ) ) ) " "
5/11

A U T
www.jefferypsanders.com/autolisp_examp.html#GetArea.lsp

8/14/13

AutoLisp Examples - Requested Programs

O L I S P
)

) ; r e s e tt h et e x ts t a r t i n gl o c a t i o nd o w nal i n e ( s e t qt x p t( p o l a rt x p t( *p i1 . 5 )( +t h t ( *t h t0 . 2 5 ) ) ) ) ; r e s e tt h el o c a t i o no ft h en e x tv e r t i c a ll i n e ( s e t qo l d p t ( p o l a ro l d p t( *p i1 . 5 )( +t h t ( *t h t0 . 2 5 ) ) ) )

; r e s e tt h es y s t e me c h o ( s e t v a r" c m d e c h o "1 ) ; s u p p r e s st h el a s te c h o ( p r i n c ) ) ; E n do fP r o g r a m Download this file: Click Here!

A U T O L I S P

LTR.lsp

Jamey Westmoreland, a Civil Engineer E.I.T. for Toothman-Orton Engineering Co. in Boise ID want program to select a Line entity, a Text entity, then rotate the text entity based on the angle of the line. ; L T R . l s p-s e l e c taL i n ee n t i t ya n daT e x te n t i t yt h e nr o t a t et h e e n t i t yb a s e do nl i n ea n g l e . ( d e f u nC : L T R ( ) ; t u r no f ft h es y s t e me c h o ( s e t v a r" c m d e c h o "0 ) ; d i s p l a yam e s s a g eo nt h ec o m m a n dl i n e ( p r i n c" \ nS e l e c tL I N Ew i t hC o r r e c tA n g l e . " ) ; l e tt h eu s e rs e l e c to n ee n t i t y ( i f( s e t qe s e t ( e n t s e l ) ) ( p r o g n ; g e tt h ee n t i t yn a m ef r o mt h ee n t s e lc o m m a n d ( s e t qe n ( c a re s e t ) ) ; g e tt h eD X Fg r o u pc o d e so ft h es e l e c t e de n t i t y ( s e t qe n l i s t ( e n t g e te n ) )

A U T O L I S P

; c h e c kt os e ei faL I N Ew a ss e l e c t e d ( i f ( =" L I N E "( c d r ( a s s o c0e n l i s t ) ) ) ( p r o g n ; d i s p l a yam e s s a g eo nt h ec o m m a n dl i n e ( p r i n c" \ nS e l e c tT E X Tt oM a t c hL i n eA n g l e . " ) ; l e tt h eu s e rs e l e c to n ee n t i t y ( i f ( s e t qe s e t 2 ( e n t s e l ) ) ( p r o g n ; g e tt h es t a r t i n gp o i n to ft h el i n e ( s e t qe p t 1 ( c d r ( a s s o c1 0e n l i s t ) ) ) ; g e tt h ee n dp o i n to ft h el i n e ( s e t qe p t 2 ( c d r ( a s s o c1 1e n l i s t ) ) ) ; g e tt h ea n g l ef r o mt h ee n dp o i n t so ft h el i n e ( s e t qa n g 1 ( a n g l ee p t 1e p t 2 ) ) ; g e tt h ee n t i t yn a m ef r o mt h ee n t s e lf u n c t i o n ( s e t qe n 2 ( c a re s e t 2 ) ) ; g e tt h eD X FG r o u pC o d e so ft h ee n t i t y ( s e t qe n l i s t 2 ( e n t g e te n 2 ) ) ; c h a n g et h ea n g l ei nt h et e x te n t i t i e sD X Fg r o u pc o d e s ( s e t qe n l i s t 2 ( s u b s t( c o n s5 0a n g 1 ) ( a s s o c5 0 e n l i s t 2 ) e n l i s t 2 ) )

A U
www.jefferypsanders.com/autolisp_examp.html#GetArea.lsp

; u p d a t et h et e x te n t i t y ( e n t m o de n l i s t 2 )

; i ft h es e c o n de n t i t yw a s n ' ts e l e c t e d . . . ( p r i n c" \ nS e l e c tT e x tE n t i t yP l e a s e .P r o g r a mA b o r t e d . " )


6/11

8/14/13

T O L I S P A U T O L I S P

AutoLisp Examples - Requested Programs ) )

; i ft h ef i r s te n t i t yw a s n ' tal i n e ( p r i n c" \ nE n i t i t ys e l e c t e dw a sn o taL I N E .P r o g r a mA b o r t e d . " ) )

; i ft h ef i r s te n t i t yw a s n ' ts e l e c t e d ( p r i n c" \ nN o t h i n gs e l e c t e d .P r o g r a mA b o r t e d . " ) ) ; r e s e tt h es y s t e me c h o ( s e t v a r" c m d e c h o "1 ) ; s u p p r e s st h el a s te c h o ( p r i n c ) ) ; E n do fP r o g r a m

Download this file: Click Here!

TXTCNT.lsp

Visitor wanted a program to count how many times each text entity appeared in a drawing and display results sorted in a dialog box. ; T X T C N T . l s p-C o u n th o wm a n yt i m e se a c ht e x te n t i t ya p p e a r s . ;D i s p l a yt h er e s u l t ss o r t e di nad i a l o gb o x .
( d e f u nC : T X T C N T ( )

; d e f i n eas o r tr o u t i n e-U s a g e :( s r tl i s t )-L e t ' sn o tg oi n t ot h i sy e t !I tw o r k s . ( d e f u ns r t ( a l i s t/n ) ( s e t ql c u pn i lr c u pn i l ) ( d e f u nc t s ( ab ) ( c o n d ( ( >ab ) t ) ( ( =ab) t ) ( tn i l ) ) ) ( f o r e a c hna l i s t ( w h i l e( a n dr c u p ( c t sn ( c a rr c u p ) ) ) ( s e t ql c u p ( c o n s ( c a rr c u p ) l c u p ) r c u p ( c d rr c u p ) ) ) ( w h i l e( a n dl c u p ( c t s ( c a rl c u p ) n ) ) ( s e t qr c u p ( c o n s ( c a rl c u p ) r c u p ) l c u p ( c d rl c u p ) ) ) ( s e t qr c u p ( c o n snr c u p ) ) ) ( a p p e n d ( r e v e r s el c u p ) r c u p ) ) ; t u r nt h ec o m m a n de c h oo f f ( s e t v a r" c m d e c h o "0 ) ; s e t u pav a r i a b l et oh o l dt h ed a t a ( s e t qd a t a l i s t ( l i s t ) ) ; s e l e c to b j e c t s ( i f( s e t qe s e t ( s s g e t ) ) ( p r o g n ; s e tac o u n t e rt ot h ef i r s ti t e mi nt h es e l e c t i o ns e t ( s e t qc n t r0 ) ; l o o pt h r o u g he a c hs e l e c t e de n t i t y ( w h i l e( <c n t r( s s l e n g t he s e t ) ) ; g r a bt h ee n t i t y ' sn a m e ( s e t qe n ( s s n a m ee s e tc n t r ) ) ; g r a bt h eD X Fg r o u pc o d e so ft h ee n t i t y ( s e t qe n l i s t ( e n t g e te n ) )

; i g n o r et h ee n t i t yi fi ti sn o taT E X Te n t i t y ( i f ( =" T E X T "( c d r ( a s s o c0e n l i s t ) ) ) ( p r o g n

; g e tt h et e x tv a l u ef r o mt h eD X FG r o u pC o d e ( s e t qs t r ( c d r ( a s s o c1e n l i s t ) ) ) ; s e t u pav a r i a b l et oc h e c ki ft h ee n t i t ye x i s ti nt h ed a t a l i s tl i s t ( s e t qe x i s t i n g0 )

; l o o pt h r o u g ht h ed a t a l i s tt of i n do u ti fi ti san e we n t i t yt h a tn e e d s ; t ob ea d d e dt ot h el i s to ri fi ta l r e a d ye x i s ta n di t ' sc o u n t e rn e e d s ; t ob ei n c r e m e n t e d ( f o r e a c had a t a l i s t ( i f( =( c a ra )s t r ) ( s e t qe x i s t i n g1 ) ) )

www.jefferypsanders.com/autolisp_examp.html#GetArea.lsp

7/11

8/14/13

AutoLisp Examples - Requested Programs


; i ft h ee n t i t yi sn e wt h e n ( i f( =e x i s t i n g0 )

; d ot h i s-A d dt h ei t e mt ot h ed a t a l i s ta l o n gw i t hac o u n t e rt h a ts t a r t sa t ( s e t qd a t a l i s t ( a p p e n dd a t a l i s t( l i s t( c o n ss t r1 ) ) ) ) ; e l s ei t ' sc n t rn e e d st ob ei n c r e m e n t e d ( s e t qd a t a l i s t ( s u b s t ( c o n ss t r( +1( c d r ( a s s o cs t rd a t a l i s t ) ) ) ) ( a s s o cs t rd a t a l i s t ) d a t a l i s t ) ) ) ) ) ; i n c r e m e n tt h ee n t i t yc o u n t e r ( s e t qc n t r ( +c n t r1 ) ) ) ) ) ; s e t u pav a r i a b l et oh o l dt h ed a t aa g a i n ,t h i st i m ei nad i f f e r e n tf a s h i o n ( s e t qn e w L i s t ( l i s t ) )

; r e a r r a n g et h el i s t ( f o r e a c had a t a l i s t ( s e t qn e w L i s t ( a p p e n dn e w L i s t ( l i s t ( s t r c a t ( s u b s t r ( s t r c a t( c a ra )".........................." ) 15 0 ) "-"( i t o a ( c d ra ) ) ) ) ) ) ) ; s o r tt h el i s t ( s e t qn e w L i s t ( s r tn e w L i s t ) ) ; p u tu pt h ed i a l o gb o x ( s e t qd c l _ i d( l o a d _ d i a l o g" T X T C N T . d c l " ) ) ; s e ei fi ti sa l r e a d yl o a d e d ( i f( n o t( n e w _ d i a l o g" T X T C N T "d c l _ i d ))( e x i t ) ) ; a d dt h ed a t at ot h el i s ti nt h ed i a l o gb o x ( s t a r t _ l i s t" d a t a l i s t " ) ( m a p c a r'a d d _ l i s tn e w L i s t ) ( e n d _ l i s t ) ; i fa na c t i o ne v e n to c c u r s ,d ot h i sf u n c t i o n ( a c t i o n _ t i l e" c a n c e l "" ( s e t qd d i a g1 ) ( d o n e _ d i a l o g ) " ) ; d i s p l a yt h ed i a l o gb o x ( s t a r t _ d i a l o g ) ; i ft h ec a n c e lb u t t o nw a sp r e s s e d-d i s p l a ym e s s a g e ( i f( =d d i a g1 ) ( p r i n c" \ n\ n. . . T X T C N TC a n c e l l e d .\ n" ) ) ; u n l o a dt h ed i a l o gb o x ( u n l o a d _ d i a l o gd c l _ i d ) ; t u r nt h ec o m m a n de c h ob a c ko n ( s e t v a r" c m d e c h o "1 ) ; s u p r e s st h el a s te c h o ( p r i n c ) ) ; E n do fA u t o L i s pP r o g r a m

D C LF i l e : T X T C N T:d i a l o g{ l a b e l=" T X T C N T-T e x tC o u n t e rB y :J e f f e r y P S a n d e r s . c o m " ; :r o w{ :l i s t _ b o x{ k e y=" d a t a l i s t " ; m u l t i p l e _ s e l e c t=" F A L S E " ; w i d t h=6 0 ; } } :b o x e d _ r o w{


www.jefferypsanders.com/autolisp_examp.html#GetArea.lsp 8/11

8/14/13

AutoLisp Examples - Requested Programs :b o x e d _ r o w{ :b u t t o n{ k e y=" c a n c e l " ; l a b e l="C a n c e l" ; i s _ d e f a u l t=f a l s e ; i s _ c a n c e l=t r u e ; } } }

E n do fD C LF i l e

Download this AutoLisp file: Click Here! Download this DCL file: Click Here!

TextIn.lsp
Read Text From a File, Write Text in the AutoCAD Drawing
; T E X T I N . L S PB y :J e f f e r yP .S a n d e r s ; T h i sp r o g r a mt a k e sa n yt e x tf i l ea n dp r i n t si ti nA u t o C A D . ; d e f i n ep r o g r a m-l i s t i n gy o u rv a r i a b l en a m e sh e r e ;r e s e t st h e mt on i la f t e rt h ep r o g r a mf i n i s h e s ( d e f u nC : T E X T I N ( /l t se r n o t ei n s p tf i l e nf i ll i n e o n e ) ; t u r ne c h oo f f ( s e t v a r" c m d e c h o "0 ) ; g e tl t s c a l e( N o t e :l t s c a l es h o u l da l w a y se q u a ld i m s c a l e ) ( s e t ql t s ( g e t v a r" l t s c a l e " ) ) ; s e tt h ee x i tn o t et od i s p l a ys u c c e s s f u l ( s e t qe r n o t e" \ n . . . . T e x t I nC o m p l e t e . " ) ; g e tt h et e x ti n s e r t i o np o i n t ( s e t qi n s p t ( g e t p o i n t" \ n I n s e r t i o nP o i n t :" ) ) ; u s ed i a l o gb o xt og e tf i l en a m e/t h e4a l l o w s ; t h eu s e rt ot y p ei nan e wf i l ee x t e n s i o n ; t h e" t x t "s e t st h ed e f a u l tt ob e" * . t x t " ( s e t qf i l e n ( g e t f i l e d" S e l e c tT e x tF i l e "" "" t x t "4 ) ) ; i ff i l ee x i s t ,o p e nf i l et or e a d ( i f( s e t qf i l ( o p e nf i l e n" r " ) ) ; p r o g nn e c e s s a r yf o rm u l t i p l es t a t e m e n t si n s i d ei fs t a t e m e n t ( p r o g n ; w h i l et h el i n ef r o mt e x tf i l ed o e sn o te q u a ln i l ( w h i l e( s e t ql i n e o n e ( r e a d l i n ef i l ) ) ; p r i n tt h et e x ti nA u t o C A Dd r a w i n g ( c o m m a n d" t e x t "i n s p t ( *l t s ( g e t v a r" t e x t s i z e " ) ) 0 . 0l i n e o n e ) ; m o v ed o w no n el i n ee a c hl o o pb yr e s e t t i n gt h ei n s e r t i o np o i n t ( s e t qi n s p t ; s t a r tt h ep o l a rf u n c t i o ni . e .[ p o l a rp ta n g l ed i s t a n c e ] ( p o l a r ; f r o mt h ei n s e r t i o np o i n t i n s p t ; s e tt h ea n g l et og od o w ni . e .( 2 7 0d e gO Rp i+p i / 2r a d i a n s ) ( *p i1 . 5 ) ; d i s t a n c ed o w nt ot h en e x tl i n ei s( t e x t s i z ex1 . 5 )xl t s c a l e ( *l t s( *1 . 5 ( g e t v a r" t e x t s i z e " ) ) ) );c l o s et h ep o l a rf u n c t i o n );c l o s et h es e t q );c l o s et h ew h i l el o o p ; c l o s et h et e x tf i l e ( c l o s ef i l ) );c l o s et h ei fp r o g ns t a t e m e n t ; e l s es e tt h ee x i t i n gr e m a r ka sa ne r r o r ( s e t qe r n o t e( s t r c a t" \ n C a n n o tF i n dF i l e :"f i l e n ) ) );c l o s et h ei fs t a t e m e n t

www.jefferypsanders.com/autolisp_examp.html#GetArea.lsp

9/11

8/14/13

AutoLisp Examples - Requested Programs


);c l o s et h ei fs t a t e m e n t ; t u r ne c h oo n ( s e t v a r" c m d e c h o "1 ) ; p r i n tt h ee x i t i n gr e m a r k ( p r i n ce r n o t e ) ( p r i n c" \ n" ) ;c l e a rc o m m a n dl i n e ( p r i n c ) ;n oe c h o ) ;c l o s et h ep r o g r a m

TextOut.lsp
Read Text From an AutoCAD Drawing, Write the Text To a File
; T E X T O U T . L S PB y :J e f f e r yP .S a n d e r s ; T h i sp r o g r a mg e t st e x tf r o ma nA u t o C A Dd r a w i n ga n dw r i t e si tt oat e x tf i l e . ; d e f i n ep r o g r a m-l i s t i n gy o u rv a r i a b l en a m e sh e r e ;r e s e t st h e mt on i la f t e rt h ep r o g r a mf i n i s h e s ( d e f u nC : T E X T O U T ( /l t se r n o t ef i l e nf i le s e te ne n l i s tc n t r ) ; t u r ne c h oo f f ( s e t v a r" c m d e c h o "0 ) ; g e tl t s c a l e( N o t e :l t s c a l es h o u l da l w a y se q u a ld i m s c a l e ) ( s e t ql t s ( g e t v a r" l t s c a l e " ) ) ; s e tt h ee x i tn o t et os u c c e s s f u l ( s e t qe r n o t e" \ n . . . . T e x t O u tC o m p l e t e . " ) ; u s ed i a l o gb o xt os e tf i l en a m e/t h e1a l l o w s ; t h eu s e rt ot y p ei nan e wf i l en a m e ; t h e" t x t "s e t st h ed e f a u l tt ob e" * . t x t " ( s e t qf i l e n ( g e t f i l e d" T y p eo rS e l e c tT e x tF i l eN a m e "" "" t x t "1 ) ) ; o p e nf i l et ow r i t e ( i f( s e t qf i l ( o p e nf i l e n" w " ) ) ; p r o g nn e c e s s a r yf o rm u l t i p l es t a t e m e n t si n s i d ea ni fs t a t e m e n t ( p r o g n ; i fs s g e tr e t u r n sav a l i ds e l e c t i o ns e t ( i f( s e t qe s e t ( s s g e t ) ) ; p r o g nn e c e s s a r yf o rm u l t i p l es t a t e m e n t si n s i d ea ni fs t a t e m e n t ( p r o g n ; s e tt h ee n t i t yc o u n t e rt oz e r o[ t h ef i r s te n t i t yi nas e ti sz e r o ] ( s e t qc n t r0 ) ; s t e pt h r o u g he a c he n t i t yi nt h es e l e c t i o ns e t ( w h i l e( <c n t r( s s l e n g t he s e t ) ) ; g e tt h ee n t i t yn a m ei n d e x e db yc n t r ( s e t qe n ( s s n a m ee s e tc n t r ) ) ; g e tt h eD X Fg r o u pc o d e sf o rt h ee n t i t y ( s e t qe n l i s t ( e n t g e te n ) ) ; c h e c kt h eg r o u pc o d e0t os e ei fe n t i t yt y p e=T E X T ( i f ( =" T E X T "( c d r ( a s s o c0e n l i s t ) ) ) ; p r o g nn e c e s s a r yf o rm u l t i p l es t a t e m e n t si n s i d ea ni fs t a t e m e n t ( p r o g n ; g e tt h et e x ts t r i n gf r o mt h ee n t i t y ' sD X FG r o u pC o d e1 ( s e t qs t r ( c d r ( a s s o c1e n l i s t ) ) ) ; p r i n tt h es t r i n gt ot h ec o m m a n dl i n e ( p r i n c( s t r c a t" \ n O u t p u tT oF i l e :"s t r ) ) ; p r i n tt h es t r i n gt ot h ef i l e ( p r i n c( s t r c a t" \ n "s t r )f i l ) ); c l o s et h ei fp r o g n ); c l o s et h ei fs t a t e m e n t ; i n c r e m e n tt h ec o u n t e rt og e tt h en e x te n t i t y ( s e t qc n t r ( +c n t r1 ) ) ); c l o s et h ew h i l el o o p ; c l o s et h et e x tf i l e ( c l o s ef i l ) ); c l o s et h ei fp r o g n ; s e tt h ee x i tn o t ea sa ne r r o r

www.jefferypsanders.com/autolisp_examp.html#GetArea.lsp

10/11

8/14/13

AutoLisp Examples - Requested Programs

; s e tt h ee x i tn o t ea sa ne r r o r ( s e t qe r n o t e" \ n E r r o r-N oE n t i t i e sS e l e c t e d . " )

);c l o s et h ei fs t a t e m e n t ); c l o s et h ei fp r o g n ; s e tt h ee x i tn o t et ob ea ne r r o r ( s e t qe r n o t e( s t r c a t" \ n E r r o r-C o u l dn o tc r e a t eF i l e :"f i l e n ) ) ); c l o s et h ei fs t a t e m e n t ; t u r nt h ec o m m a n de c h ob a c ko n ( s e t v a r" c m d e c h o "1 ) ; p r i n tt h ee x i tn o t et ot h ec o m m a n dl i n e ( p r i n ce r n o t e ) ; c l e a rt h ec o m m a n dl i n e ( p r i n c" \ n" ) ; s u p r e s sl a s te c h o ( p r i n c ) ); c l o s et h ep r o g r a m

New! Having trouble with one of the programs not working for your version of AutoCAD? Click this-----> Please fix this!

Support this Site!

AutoLisp Home Home All questions/complaints/suggestions should be sent to JefferyPSanders.com Last Updated April 1st, 2013 Copyright 2002-2013 JefferyPSanders.com. All rights reserved.

www.jefferypsanders.com/autolisp_examp.html#GetArea.lsp

11/11

You might also like