tiffanysml Posted March 26, 2010 Posted March 26, 2010 Is there a way to make autocad type in the drawing name on the model? For example: (command "-text" "J" "C" "50,50" "5" "0" "dwgname") and the real drawing name is magically typed automatically? (i'm sure the code isn't as simple as I written it) I've tried to figure it out but no luck. Thank you for any advice Quote
Fire_col Posted March 26, 2010 Posted March 26, 2010 Yeah. (defun c:name () ; name of command (setq dn (getstring T "\nEnter Drawing Name : ")) ; allows you to enter drawing title with spaces in text (setq ip (getpoint "\nEnter Insertion Point : ")); type your insertion point (setq th (getreal "\nEnter Text Height : ")) ; type your text height (setq ro (getreal "\nEnter Text Rotation : ")) ; type text rotation (setq js (getstring "\nEnter Justification : ")) ; type justification of text (command "text" "j" js ip th ro dn) ; AutoCAD draws text (princ) ) copy that text into notepad and save it a a .lsp or run vlide command and type it in to the lisp editor, save it in your support pasth file and then you'll always have that command available to you when you open CAD. Hope it helps. Quote
jammie Posted March 26, 2010 Posted March 26, 2010 (i'm sure the code isn't as simple as I written it) Actually you are not far off it (command "-text" "J" "C" "50,50" "5" "0" (getvar 'dwgname)) Quote
Lee Mac Posted March 26, 2010 Posted March 26, 2010 I would never recommend using a command call to generate text as it can be highly unpredictable, instead I would use entmake, (or an equivalent VL method): (defun c:insdwg (/ M-Text p) (defun M-Text (pt str) (entmakex (list (cons 0 "MTEXT") (cons 100 "AcDbEntity") (cons 100 "AcDbMText") (cons 10 pt) (cons 1 str)))) (if (setq p (getpoint "\nSelect Point for DWG Name: ")) (M-Text p (getvar 'DWGNAME))) (princ)) Or as per your example: (defun c:insdwg (/ Text) (defun Text (pt hgt str) (entmakex (list (cons 0 "TEXT") (cons 10 pt) (cons 40 hgt) (cons 1 str) (cons 72 1) (cons 73 0) (cons 11 pt)))) (Text '(50. 50. 0.) 5. (getvar 'DWGNAME)) (princ)) Or, using a FIELD: (defun c:insdwg (/ doc) (vl-load-com) (vla-addText (if (or (eq AcModelSpace (vla-get-ActiveSpace (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))))) (eq :vlax-true (vla-get-MSpace doc))) (vla-get-ModelSpace doc) (vla-get-PaperSpace doc)) "%<\\AcVar Filename \\f \"%tc4%fn6\">%" (vlax-3D-point '(50. 50. 0.)) 5.) (princ)) Quote
stevesfr Posted March 26, 2010 Posted March 26, 2010 I would never recommend using a command call to generate text as it can be highly unpredictable, instead I would use entmake, (or an equivalent VL method): (defun c:insdwg (/ M-Text p) (defun M-Text (pt str) (entmakex (list (cons 0 "MTEXT") (cons 100 "AcDbEntity") (cons 100 "AcDbMText") (cons 10 pt) (cons 1 str)))) (if (setq p (getpoint "\nSelect Point for DWG Name: ")) (M-Text p (getvar 'DWGNAME))) (princ)) Or as per your example: (defun c:insdwg (/ Text) (defun Text (pt hgt str) (entmakex (list (cons 0 "TEXT") (cons 10 pt) (cons 40 hgt) (cons 1 str) (cons 72 1) (cons 73 0) (cons 11 pt)))) (Text '(50. 50. 0.) 5. (getvar 'DWGNAME)) (princ)) Or, using a FIELD: (defun c:insdwg (/ doc) (vl-load-com) (vla-addText (if (or (eq AcModelSpace (vla-get-ActiveSpace (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))))) (eq :vlax-true (vla-get-MSpace doc))) (vla-get-ModelSpace doc) (vla-get-PaperSpace doc)) "%<\\AcVar Filename \\f \"%tc4%fn6\">%" (vlax-3D-point '(50. 50. 0.)) 5.) (princ)) How is the text height set in the first program? I understand the latter two settings. S Quote
Lee Mac Posted March 26, 2010 Posted March 26, 2010 The first one is the most 'stripped out' example, and will use all default settings (Standard TextStyle etc). Quote
stevesfr Posted March 26, 2010 Posted March 26, 2010 The first one is the most 'stripped out' example, and will use all default settings (Standard TextStyle etc). got it , thanks.... S Quote
asos2000 Posted March 26, 2010 Posted March 26, 2010 How is the text height set in the first program? I understand the latter two settings.S by adding more codes See this link for more DXF codes for text Quote
stevesfr Posted March 26, 2010 Posted March 26, 2010 by adding more codes I thought by paying my Car Insurance Premium would have enlightened me, but it didn't Quote
Lee Mac Posted March 26, 2010 Posted March 26, 2010 by adding more codes I thought by paying my Car Insurance Premium would have enlightened me, but it didn't I never made that thread! 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.