Jump to content

Is there a way to make autocad type in the drawing name on the model?


tiffanysml

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

(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))

Link to comment
Share on other sites

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))

Link to comment
Share on other sites

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

Link to comment
Share on other sites

The first one is the most 'stripped out' example, and will use all default settings (Standard TextStyle etc).

 

got it :roll:, thanks.... S

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...