CivilTechSource Posted 11 hours ago Posted 11 hours 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
BIGAL Posted 1 hour ago Posted 1 hour ago I think code can be made easier, yes LT does support VL just not a full set but should support "getattributes" an easier way of getting attribute values or you may be able to use the getpropertyvalue method even easier. Have a look at Lee-mac ssget functions. you should use "E" to select block. https://www.lee-mac.com/ssget.html If the desired result is to plot ";; 6. Launch Plot Command" say a PDF with a known filename please say so, no need for a clipboard. There are plenty of plot lisps out there. You need to provide more details, is the title block true size or scaled, what device for output, PDF, A3, A1, plotter names and so on. Is it in model or a layout ? A couple of test code just try them. Property would be easiest, please let me know if it works in LT. (DEFUN C:test ( / ) (setq ent (car (entsel "\npick block "))) (setq dwgno (strcase (getpropertyvalue ent "DRAWING_NO.") T))) (princ) ) ; Wrapper the entsel in a while is it a BLOCK with attributes so if wrong pick do again. A enter check would be exit. ; in this test looks for one attribute but can redo as look for multiple atts and save value in varaibles. (defun c:test ( / ) (setq obj (vlax-ename->vla-object (car (entsel "\nPick block with attributes ")))) (setq atts (vlax-invoke obj 'Getattributes)) (vlax-for att atts (if (= (vlax-get att 'textstring) "DRAWING_NO.") (setq dwgno (strcase (getpropertyvalue ent "DRAWING_NO.") T))) ) ) (princ) ) 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.