free autolisp samples

23
Free AutoLisp Samples I have found that updating help sheets that nobody uses is a pain and a waste of time. Many of these are old and do not work with newer versions of AutoCAD. I am still writing and updating my lisps, and I’m better now than I was when most of these were done. My newer stuff is much better. My personal AutoCAD setup looks nothing like this web page. Each problem and each profession requires its own touch. Therefore, each lisp that is uploaded to the site is generic. I can modify them to your needs! These are mostly in order of complexity, not usefulness. Be sure to request a lisp before you leave the site. I may already have it what you need. I’ve literally written thousands. Check here and here for more lisps. These are listed in order of complexity. The most difficult lisps I’ve written are field specific and would not likely be useful to the general public. You can download all lisps at once or browse the html. Download all lisps: better formatting, less bugs, more functions not included on this page, including: xi – isolate an xref layer and make it into a new xref trunclayers – shorten layer names and remove spaces ptbindall – bind all xrefs, removing unused layers byall – change all the colors in all blocks to bylayer ln – select all lines of a selected length nl – list all the nested layer names for an xref object oo – open an xref you select Like or share to unlock download link for all lisps Tweet

Upload: pepe-brindis

Post on 24-Sep-2015

373 views

Category:

Documents


41 download

TRANSCRIPT

Free AutoLisp Samples I have found that updating help sheets that nobody uses is a pain and a waste of time. Many of these are old and do not work with newer versions of AutoCAD. I am still writing and updating my lisps, and Im better now than I was when most of these were done. My newer stuff is much better.My personal AutoCAD setup looks nothing like this web page. Each problem and each profession requires its own touch. Therefore, each lisp that is uploaded to the site is generic. I can modify them to your needs! These are mostly in order of complexity, not usefulness. Be sure to request a lisp before you leave the site. I may already have it what you need. Ive literally written thousands. Check here and here for more lisps.These are listed in order of complexity. The most difficult lisps Ive written are field specific and would not likely be useful to the general public.You can download all lisps at once or browse the html.Download all lisps:better formatting, less bugs, more functions not included on this page, including:xi isolate an xref layer and make it into a new xreftrunclayers shorten layer names and remove spacesptbindall bind all xrefs, removing unused layersbyall change all the colors in all blocks to bylayerln select all lines of a selected lengthnl list all the nested layer names for an xref objectoo open an xref you selectLike or share to unlock download link for all lisps Tweet[Generic Script] [Load Explorer window in Current Directory] [Previous Objects to New Layer] [Change X-ref color] [Copy and paste text] [Add text to the end of a string] [Addpoints & Midpoint] [Open next drawing] [Resize a line] [Close wall] [Ddedit & Ddatte] [Setlast & Setprevious] [Move all of a selected attribute] [Make into a 2d dwg] [List all lisps within files in a directory][Undefined Shape xx fix][Batch Bind][Match blocks][Toggle between text] Generic Script(DEFUN C:gs () ; A generic script in AutoLISP. for training purposes It does nothing! ByBrian Forbes http://www.autolisp.org/(PRINC "You can make this say whatever you want!")(COMMAND"move") (COMMAND) (COMMAND "select" "p" pause)) Load Explorer Window in Current Directory(DEFUN C:DIRR() ; By Brian Forbes http://www.autolisp.org/

(STARTAPP "EXPLORER.EXE" (GETVAR"DWGPREFIX")) (princ))Previous Objects to New Layer(DEFUN C:p2n () ; Previous to New Layer By Brian Forbes http://www.autolisp.org/(PROMPT "\nName of layer for entities to reside:")(SETQ newlay (GETSTRING))(COMMAND "LAYER" "N" newlay """CHANGE" "p" "" "P" "LA" newlay"" "CHANGE" "p" "" "P" "C""BYLAYER" ""))Change Color(DEFUN C:cxc (/ osm ln) ; Change the color of a layer by selecting an object By Brian Forbes http://www.autolisp.org/(SETQ osm (getvar "osmode")) (SETVAR "osmode"0)(SETQ ln (cdr (assoc 8 (entget (car (nentselp (getpoint"Select object: ")))))))(PROMPT "Select Color: ")(COMMAND "LAYER" "C" pause ln "")(SETVAR "osmode" osm) (PRINC))Text(DEFUN C:cf () ; Copy text [normally with snap modes enabled, this one is simplified] By Brian Forbes http://www.autolisp.org/(PRINC (SETQ CT (CDR (ASSOC 1 (setq ed (entget (car(nentselp (getpoint "Select text to copy: ")))))))))(while T (c:yt))(PRINC))(DEFUN C:YT () ; Paste text By Brian Forbes http://www.autolisp.org/(setq ed (entget (car (nentselp (getpoint "\nSelecttext to replace: ")))))(entmod (subst (cons 1 CT) (assoc 1 ed) ed ) )(ENTUPD (CDR (CAR ED))))Add Text to the End of a String(defun c:ate() ;; Add text to the end of a string By Brian Forbes http://www.autolisp.org/

(command undo _be)

; (setq ui (getstring)) ; Use this to prompt for string and comment out the following line

(setq ui Your string here!)

(setq ed (entget (car (nentselp (cadr (entsel))))))

(entmod

(subst

(cons 1 (strcat (cdr (assoc 1 ed))

(if (= (setq str ui) ) str)

))

(assoc 1 ed)

ed

)

)

(ENTUPD (CDR (CAR ed)))

(command undo _end)

(PRINC))Add Points & Midpoint(defun addpoints (p1 p2 / p3) ; adds 2 points together By Brian Forbes http://www.autolisp.org/(setq p3 (list (+ (car p1) (car p2)) (+ (cadr p1) (cadrp2)) (+ (caddr p1) (caddr p2)) )))(defun mp ( p1 p2 / p1x p1y p2x p2y ) ; Returns the point between two points By Brian Forbes http://www.autolisp.org/(SETQ P1X (CAR p1))(SETQ P1Y (CADR p1))(SETQ P2X (CAR p2))(SETQ P2Y (CADR p2))(LIST (/ (+ P1X P2X) 2) (/ (+ P1Y P2Y) 2)))Open Next Drawing(DEFUN C:nd () ; next drawing no save by Brian Forbes http://www.autolisp.org/(SETVAR "clayer" (GETVAR "clayer")); This line makes the open command give a save prompt(COMMAND "dir" (STRCAT (GETVAR"dwgprefix")"*.dwg /b /on > c:\\temp.txt"))(SETQ fn (open "c:\\temp.txt" "r"))(SETQ eof "Im not nil!!")(SETQ dn (getvar "dwgname"))(WHILE eof (SETQ eof (READ-LINE fn))(IF (= eof dn) (PROGN (SETQeof nil) (SETQ dwn (READ-LINE fn)))))(CLOSE fn) (COMMAND "del" "c:\\temp.txt")(SETQ FN (STRCAT (GETVAR "DWGPREFIX") DWN));(COMMAND "qsave") ; delete the ; at the frontof the line to save the dwg by default(COMMAND "open" "YES" fn) (PRINC dwn)(PRINC))Resize a line(defun c:res () ; Resize a line by Brian Forbes http://www.autolisp.org/(command "undo" "be")(setq osm (getvar"osmode"))(setvar "osmode" 0)(setq op (getpoint "Select object to resize: "))(while (not (setq obj (ssname (ssget op) 0)))(setq op (getpoint "Selectobject to resize: ")))(setq P1 (cdr (assoc 10 (entget obj))))(setq P2 (cdr (assoc 11 (entget obj))))(setq newdist (getstring "New size in inches: "))(if (< (distance p1 op) (distance p2 op))(progn (command"line" p1 "" "line" (strcat "@" newdist"