CivilTechSource Posted 1 hour ago Posted 1 hour ago Hi again! I had this crazy idea to automate the drawing name process by making a lisp that will generate the drawing name (using titleblock attributes Name, Dwg.no, revision, status and so on). I have the below lisp that works great on AutoCAD, but I need it to work on LT. My question: Is there a way where AutoCad LT to copy something into the clipboard? (defun C:PrintMe (/ ss en ent data dwgno dwgstatus dwgrevision dwgtitle Dwg_No Dwg_Status Dwg_Rev Dwg_Name final fPath fPtr curTag curVal titleblockname _TitleCase) ;; Helper Function: Convert string to Title Case (e.g. "GROUND FLOOR" -> "Ground Floor") (defun _TitleCase (str / res cap next) (setq str (strcase str t) ; lowercase whole string res "" cap t) ; flag for first letter (repeat (strlen str) (setq next (substr str 1 1) str (substr str 2)) (if (= next " ") (setq res (strcat res next) cap t) (if cap (setq res (strcat res (strcase next)) cap nil) (setq res (strcat res next)) ) ) ) res ) ;; 1. Configuration (setq titleblockname "LE Titleblock Information `@A1") (setq dwgno "DRAWING_NO.") (setq dwgstatus "VIS_TEXT") (setq dwgrevision "REV") (setq dwgtitle "DRAWING_TITLE") ;; 2. Selection Logic (setq ss (ssget "_I" (list '(0 . "INSERT") (cons 2 titleblockname)))) (if ss (setq en (ssname ss 0)) (setq en (car (entsel "\nSelect the Title Block: "))) ) (if en (progn (princ "\nProcessing Plot Name...") (command "_.UPDATEFIELD" en "") (setq ent (entnext en)) ;; 3. Loop through attributes (while (and ent (/= (cdr (assoc 0 (entget ent))) "SEQEND")) (setq data (entget ent)) (setq curTag (strcase (cdr (assoc 2 data)))) (setq curVal (cdr (assoc 1 data))) (cond ((= curTag (strcase dwgno)) (setq Dwg_No curVal)) ((= curTag (strcase dwgstatus)) (setq Dwg_Status curVal)) ((= curTag (strcase dwgrevision)) (setq Dwg_Rev curVal)) ((= curTag (strcase dwgtitle)) (setq Dwg_Name curVal)) ) (setq ent (entnext ent)) ) ;; 4. Construct Final String (if (and Dwg_No (/= Dwg_No "")) (progn ;; Extract first 2 chars of Visibility (if (and Dwg_Status (/= Dwg_Status "")) (setq Dwg_Status (substr Dwg_Status 1 2)) (setq Dwg_Status "XX") ) ;; Handle Revision default (if (or (not Dwg_Rev) (= Dwg_Rev "")) (setq Dwg_Rev "00")) ;; Apply Title Case to Dwg_Name (if (or (not Dwg_Name) (= Dwg_Name "")) (setq Dwg_Name "Untitled") (setq Dwg_Name (_TitleCase Dwg_Name)) ) ;; Combine string (using your "_" separator for the title) (setq final (strcat Dwg_No "-" Dwg_Status "-" Dwg_Rev "_" Dwg_Name)) ;; 5. Send to Clipboard (setq fPath (strcat (getvar "TEMPPREFIX") "clip_tmp.txt")) (setq fPtr (open fPath "w")) (princ final fPtr) (close fPtr) (command "_.SHELL" (strcat "clip < \"" fPath "\"")) (princ (strcat "\nSuccess! '" final "' copied to clipboard.")) (princ "\n") ;; 6. Launch Plot Command (initdia) (command "_.PLOT") ) (princ "\nError: Drawing Number (DRAWING_NO.) is empty.") ) ) (princ "\nError: No valid Title Block selected.") ) (princ) ) ;; Activation command: PRINTME Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.