CivilTechSource Posted yesterday at 01:37 PM Posted yesterday at 01:37 PM 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 21 hours ago Posted 21 hours 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) ) 2 Quote
CivilTechSource Posted 12 hours ago Author Posted 12 hours ago Hi @BIGAL! I did not explore the option of going straight away to the PDFing. The reason is most likely that sometimes we need to tweak the settings (turn transparency on, or object lineweight). So my idea was to have the lisp extract the Drawing name components (Dwg.Number-Status-Revision-Dwg.Name) and save it in the clipboard so the user can paste it in the dialogbox when saving the drawing. The shell solution seemed pretty good and it does work on the full cad but did not work on LT. @Lee Mac maybe you have some thoughts on this? @BIGAL thanks you so much for being so helpful! Quote
Tharwat Posted 10 hours ago Posted 10 hours ago I think saving the string to a temporary text file and importing it when needed for insertion should accomplish the task. Quote
Saxlle Posted 10 hours ago Posted 10 hours ago (edited) 2 hours ago, CivilTechSource said: So my idea was to have the lisp extract the Drawing name components (Dwg.Number-Status-Revision-Dwg.Name) and save it in the clipboard so the user can paste it in the dialogbox when saving the drawing Why not just use princ to write the text in command line, then select it, ctrl+c and ctrl+v? For e.g. (setq a "213" b "abs" c "ddd") (princ (strcat a " " b " " c)) (princ) ------------------------------- result: 213 abs ddd (select then in command line and paste it) Edited 10 hours ago by Saxlle Quote
Steven P Posted 1 hour ago Posted 1 hour ago (edited) 11 hours ago, CivilTechSource said: Hi @BIGAL! I did not explore the option of going straight away to the PDFing. The reason is most likely that sometimes we need to tweak the settings (turn transparency on, or object lineweight). So my idea was to have the lisp extract the Drawing name components (Dwg.Number-Status-Revision-Dwg.Name) and save it in the clipboard so the user can paste it in the dialogbox when saving the drawing. The shell solution seemed pretty good and it does work on the full cad but did not work on LT. @Lee Mac maybe you have some thoughts on this? @BIGAL thanks you so much for being so helpful! Generally if I am plotting it is much quicker to get a LISP to do all the 'hard' work going through the dialogue box - more so with PDFs where it wants you to select folders to plot to. If these are all standard 90% of the time like BigAl says, go straight to plot. Might be that the most efficient way would be 4 functions to plot to PDF: 'PlotPdf' 'PlotPdfTr' - Transparency 'PlotPdfLW' - Lineweight 'PlotPdfTrLw' - Transparency and lineweight, (or 5th one PlotPDFLwTr to cover it going the options entered in reverse) All call the same basic function passing the required data for example: (defun c:plotpdf ( / )(plotPDF (list 0 0))) ;; List: TR, LW (defun c:plotpdfTr ( / )(plotPDF (list 1 0))) ;; List: TR, LW (defun c:plotpdfLw ( / )(plotPDF (list 0 1))) ;; List: TR, LW (defun c:plotpdfTrLW ( / )(plotPDF (list 1 1))) ;; List: TR, LW (defun c:plotpdfLWTr ( / )(plotPDF (list 1 1))) ;; List: TR, LW (defun PlotPDF ( MyControls / .....) .... ... (if (= (nth 0 MyControls) 1) (setq DoTransparency "Yes")) ... (if (= (nth 1 MyControls) 1) (setq DoLineWeight "Yes")) .... ) I use a similar thing: PlotA0, PlotA1.... for different papersizes, plotpdfmsc (plot PDF Mono Save Close) as examples, easy to remember (can do the 'code' part of the functions backwards too, eg, PLotPDFCS - Close Shave) I tend to pass the controls as a list so that if you want to add more functions later you only need to change the main function and anything new afterwards, for example c:plotpdfPr where Pr might be 'show preview' and that list might be (plotPDF (list 0 0 1)) noting that shorter lists will just return a 'nil' in the if statements / conds so have no effect Edited 1 hour ago by Steven P 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.