mark_kostic Posted March 29, 2021 Posted March 29, 2021 Hello, I need to create a custom command that will be used for inserting file path and file name of the current drawing (I should just click to define the place where I want to put it). Quote
X11start Posted March 29, 2021 Posted March 29, 2021 (edited) (getvar "dwgprefix") ex. "D:\MYDWG\SMITH\" (getvar "dwgname") ex. "HOUSE_OF_MR_SMITH.DWG" Edited March 29, 2021 by X11start Quote
Tharwat Posted March 29, 2021 Posted March 29, 2021 (defun c:Test (/ ins str) ;; Tharwat - Date: 29.Mar.2021 ;; (and (or (> (getvar 'DWGTITLED) 0) (alert "Save the drawing then try again!") ) (setq ins (getpoint "\nSpecify the insertion point : ")) (setq str (entmakex (list '(0 . "MTEXT") '(100 . "AcDbEntity") '(100 . "AcDbMText") (cons 10 (trans ins 1 0)) '(1 . "") ) ) ) (vla-put-textstring (vlax-ename->vla-object str) "%<\\AcVar Filename \\f \"%tc4%fn7\">%" ) ) (princ) ) 1 Quote
rkmcswain Posted March 29, 2021 Posted March 29, 2021 @mark_kostic - you might also create a block that contains a FIELD that contains the drawing path and filename, then you can just insert this block each time, or include it in your templates. 2 Quote
tombu Posted March 29, 2021 Posted March 29, 2021 Field examples you can add to template title block since they reference the current document not drawing objects. Drawing path and filename with file extension: %<\AcVar Filename \f "%fn7">% Drawing path and filename without file extension: <\AcVar Filename \f "%fn3">% This way they will automatically update if you move or rename the drawing. 2 Quote
mark_kostic Posted April 28, 2021 Author Posted April 28, 2021 Thanks for your responses. I ended up with this code: (defun c:pdm (/ ins str) (and (or (> (getvar 'DWGTITLED) 0) (alert "Save the drawing then try again!") ) (setq ins (getpoint "\nChoose where you want to insert the file name : ")) (setq str (entmakex (list '(0 . "MTEXT") '(100 . "AcDbEntity") '(100 . "AcDbMText") (cons 10 (trans ins 1 0)) '(1 . "") ) ) ) (vla-put-textstring (vlax-ename->vla-object str) "{\\fArial|b1|i0|c0|p34;\\C2;%<\\AcVar Filename \\f \"%tc4%fn6\">%}" ) ) (princ) ) Is there a way to define the text size (height) in this code? 1 Quote
Lee Mac Posted April 28, 2021 Posted April 28, 2021 (edited) I would strongly suggest controlling the typeface through an appropriate Text Style, and the colour using either the layer colour (with object colour set to ByLayer) or using object colour, in place of using MText formatting overrides embedded within the text content. I would personally opt to write the code in the following way: (defun c:pdm ( / ins obj ) (cond ( (zerop (getvar 'dwgtitled)) (princ "\nThe current drawing is unsaved.") ) ( (setq ins (getpoint "\nSpecify insertion point: ")) (setq obj (vla-addmtext (vlax-get-property (vla-get-activedocument (vlax-get-acad-object)) (if (= 1 (getvar 'cvport)) 'paperspace 'modelspace) ) (vlax-3D-point (trans ins 1 0)) 0.0 "%<\\AcVar Filename \\f \"%tc4%fn6\">%}" ) ) ) ) (princ) ) (vl-load-com) (princ) Currently, the text height is controlled by the TEXTSIZE system variable, however, you can add an expression such as the following to override the height to something other than that defined by the Text Style: (vla-put-height obj 2.5) Edited April 28, 2021 by Lee Mac Quote
Tharwat Posted April 28, 2021 Posted April 28, 2021 31 minutes ago, mark_kostic said: Thanks for your responses. I ended up with this code: (defun c:pdm (/ ins str) (and (or (> (getvar 'DWGTITLED) 0) (alert "Save the drawing then try again!") ) (setq ins (getpoint "\nChoose where you want to insert the file name : ")) (setq str (entmakex (list '(0 . "MTEXT") '(100 . "AcDbEntity") '(100 . "AcDbMText") (cons 10 (trans ins 1 0)) '(1 . "") ) ) ) (vla-put-textstring (vlax-ename->vla-object str) "{\\fArial|b1|i0|c0|p34;\\C2;%<\\AcVar Filename \\f \"%tc4%fn6\">%}" ) ) (princ) ) Is there a way to define the text size (height) in this code? Its a bad idea to end up with removing authors' names from their original codes. 1 Quote
tombu Posted April 28, 2021 Posted April 28, 2021 4 hours ago, Lee Mac said: I would strongly suggest controlling the typeface through an appropriate Text Style, and the colour using either the layer colour (with object colour set to ByLayer) or using object colour, in place of using MText formatting overrides embedded within the text content. You may want to change the Text Style to Arial Narrow to squeeze a long file path in later. Why complicate this? I rarely use Mtext formatting overrides other than in blocks using Standard Text Style so they display the same for everyone no matter what Text Styles they have in their drawings. It's actually the only time I use the Standard Text Style. Never any confusion what an Arial Text Style will look like. Quote
Lee Mac Posted April 28, 2021 Posted April 28, 2021 7 hours ago, tombu said: You may want to change the Text Style to Arial Narrow to squeeze a long file path in later. Why complicate this? I rarely use Mtext formatting overrides other than in blocks using Standard Text Style so they display the same for everyone no matter what Text Styles they have in their drawings. It's actually the only time I use the Standard Text Style. Never any confusion what an Arial Text Style will look like. I couldn't quite work out whether you agreed or disagreed with me here Quote
tombu Posted April 29, 2021 Posted April 29, 2021 12 hours ago, Lee Mac said: I couldn't quite work out whether you agreed or disagreed with me here Sorry should have made that clearer. I agreed! There are no absolutes though. For a fancy N for a North Arrow block without adding another Text Style to any drawing it's inserted in is one. Thanks again for all the code like Steal from Drawings I use every day. Being able to quickly add whatever size layout I need with title block and Plot Styles for both plotting and sending to PDF. ^C^C^P(Steal (strcat (vl-filename-directory (getenv "QnewTemplate")) (chr 92) "AutoCAD Template" (chr 92) "TemplateBlks.dwt") (list (list "Page Setups" (list "11×17" "11×17 PDF"))(list "Layouts" (list "11×17"))))(load "Glblattchg.lsp")(Glblattchg "11×17" "#P" "Layouts") .regen With code from you and others whenever I add or move layouts around page numbers and number of pages automatically update. With a few clicks I select whoever's signature is required and fill in most of the attributes. Like to think I've contributed online as well but am forever grateful for all the help and code I've gotten from forums like this. 1 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.