CADTutor: The best free help for AutoCAD on the web

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
Go Back   AutoCAD Forums > AutoCAD > AutoLISP, VBA, the CUI & Customisation

Reply
 
Thread Tools
Old 3rd Nov 2009, 06:29 pm   #1
hokie555
Junior Member
 
Using: AutoCAD 2007
 
Join Date: Aug 2009
Posts: 18
Default entmake text w/ centered justification

I've got a routine where I'm placing text with bottom centered justification. The insertion point (tp) is where I want the text to be centered upon, and is being used for group code 10. How can I find group code 11? Currently it places the text anyway but breaks out of the routine (error: bad DXF group: (11)). Thanks for your help!

Here's what I got:

Code:
 (setq tp (getpoint "\nSelect Text Insertion Point: "))
 (setq bln (getstring "\nEnter Text: "))
  (entmake
    (list
      (cons 0 "TEXT")
      (cons 8 lyr) 
      (cons 10 tp) 
      (cons 11 tp) 
      (cons 40 0.062) 
      (cons 1 bln) 
      (cons 50 0) 
      (cons 7 "ROMANS") 
      (cons 71 0) 
      (cons 72 1) 
      (cons 73 0) 
    )
)

EDIT: hmm seems to be working now. found the error that came from somewhere else.

Last edited by hokie555 : 3rd Nov 2009 at 08:11 pm.
hokie555 is offline   Reply With Quote
Old 3rd Nov 2009, 09:27 pm   #2
The Buzzard
Super Member
 
Using: AutoCAD 2009
 
Computer Details
 
Join Date: Oct 2008
Location: New York, New York
Posts: 1,252
Default

hokie 555,

I hope you do not mind, But I made a complete function out of it. I hope this helps you.
I did not bother to add any snaps or orthomode.

I will be glad to answer your questions after you test it.

I basically created the entity with respect to 0,0,0 and moved it to the insertion point.

Code:
(defun C:MTCJ (/ EXDR TFBP TSBP BLN INPT)                               ;Define function (Make Text Center Justified), Declare local variables
  (setq EXDR (list 0.0 0.0 1.0))                                        ;Set extrusion direction (Needed for 3D only)
  (setq TFBP  (list 0.0 0.0 0.0))                                       ;Set text first base point
  (setq TSBP  (list -0.023619 -0.031 0.0))                              ;Set text second base point
  (MTCJ_LAYER "TEXT" "2" "")                                            ;Set layer name, color & linetype
  (MTCJ_FONT)                                                           ;Set font
  (setq BLN (getstring "\nEnter Text: "))                               ;Enter the string
  (setq INPT  (getpoint "\nSelect Text Insertion Point: "))             ;Enter the insertion point
  (entmake                                                              ;Start entity make
    (list                                                               ;Start list
      (cons 0   "TEXT")                                                 ;Entity type
      (cons 8   "TEXT")                                                 ;Layer name
      (cons 10   TSBP)                                                  ;Text second base point
      (cons 40   0.062)                                                 ;Text height
      (cons 1    BLN)                                                   ;Text string 
      (cons 50   0.0)                                                   ;Text rotation
      (cons 41   1.0)                                                   ;Relative x scale factor
      (cons 51   0.0)                                                   ;Oblique angle
      (cons 7   "ROMANS")                                               ;Text style
      (cons 71   0)                                                     ;Text generation flag
      (cons 72   1)                                                     ;Horizontal justification flag center
      (cons 11   TFBP)                                                  ;Text first base point
      (cons 210  EXDR)                                                  ;Extrusion direction (Needed for 3D)
      (cons 73   2)                                                     ;Vertical justification
    )                                                                   ;End list
  )                                                                     ;End entity make
 
  (command "_.move" "_l" "" TFBP INPT "")                               ;Move command, last object from text first base point to insertion point 
  (prompt "\nRotation Angle: ")                                         ;Get rotation angle
  (command "_.rotate" "_l" "" INPT pause)                               ;Rotate command, last object, rotate on insertion point
)                                                                       ;End defun
(defun MTCJ_FONT ()                                                     ;Define function (FONT)
  (command "_.STYLE" "romans" "romans.shx" "0.0" "1.0" "0" "N" "N" "N") ;style command
  (princ)                                                               ;Exit quietly
)                                                                       ;End defun
(defun MTCJ_LAYER (NLAY CLR LT / LAY FRZ)                               ;Define function (Make Layer), Declare local varibles & arguments
  (setq LAY (tblsearch "layer" NLAY))                                   ;Search drawing for layer
  (if (not LAY)                                                         ;If layer not found
    (command "_.-layer" "_m" NLAY "_c" CLR "" "_lt" LT "" "")           ;Make layer, color & linetype
    (progn                                                              ;Then do the following
      (setq FRZ (cdr (assoc 70 LAY)))                                   ;Look for frozen layers from last edit
      (if (= FRZ 65)                                                    ;if any layers frozen
        (progn                                                          ;Then do the following
          (command "_.-layer" "_t" NLAY "")                             ;Thaw layer
          (command "_.-layer" "_s" NLAY "")                             ;Set layer
        )                                                               ;End progn
        (command "_.-layer" "_s" NLAY "")                               ;Set layer
      )                                                                 ;End if
    )                                                                   ;End progn
  )                                                                     ;End if
  (princ)                                                               ;Exit quietly
)                                                                       ;End defun

Last edited by The Buzzard : 3rd Nov 2009 at 10:23 pm.

The Buzzard is offline   Reply With Quote
Old 3rd Nov 2009, 10:41 pm   #3
The Buzzard
Super Member
 
Using: AutoCAD 2009
 
Computer Details
 
Join Date: Oct 2008
Location: New York, New York
Posts: 1,252
Default

If this helps any, This is how I get the entity list.

Code:
(defun C:pdxf (/ pick)
  (if (setq pick (car (entsel "\nSelect Object: ")))
    (progn (textscr)
    (foreach x (entget pick)
      (print x))))
  (princ))

Run this program and select the entity.
A list will be returned.

The Buzzard is offline   Reply With Quote
Old 3rd Nov 2009, 10:51 pm   #4
The Buzzard
Super Member
 
Using: AutoCAD 2009
 
Computer Details
 
Join Date: Oct 2008
Location: New York, New York
Posts: 1,252
Default

Sorry,

This one is bottom centered. The first code was middle centered.

Sorry for the mix up.

Type MTBC for this code.

Code:
(defun C:MTBC (/ EXDR TFBP TSBP BLN INPT)                               ;Define function (Make Text Center Justified), Declare local variables
  (setq EXDR (list 0.0 0.0 1.0))                                        ;Set extrusion direction (Needed for 3D only)
  (setq TFBP (list 0.0 0.0 0.0))                                        ;Set text first base point
  (setq TSBP (list -0.023619 0.0206667 0.0))                            ;Set text second base point
  (MTCJ_LAYER "TEXT" "2" "")                                            ;Set layer name, color & linetype
  (MTCJ_FONT)                                                           ;Set font
  (setq BLN  (getstring "\nEnter Text: "))                              ;Enter the string
  (setq INPT (getpoint "\nSelect Text Insertion Point: "))              ;Enter the insertion point
  (entmake                                                              ;Start entity make
    (list                                                               ;Start list
      (cons 0   "TEXT")                                                 ;Entity type
      (cons 8   "TEXT")                                                 ;Layer name
      (cons 10   TSBP)                                                  ;Text second base point
      (cons 40   0.062)                                                 ;Text height
      (cons 1    BLN)                                                   ;Text string 
      (cons 50   0.0)                                                   ;Text rotation
      (cons 41   1.0)                                                   ;Relative x scale factor
      (cons 51   0.0)                                                   ;Oblique angle
      (cons 7   "ROMANS")                                               ;Text style
      (cons 71   0)                                                     ;Text generation flag
      (cons 72   1)                                                     ;Horizontal justification flag center
      (cons 11   TFBP)                                                  ;Text first base point
      (cons 210  EXDR)                                                  ;Extrusion direction (Needed for 3D)
      (cons 73   1)                                                     ;Bottom justification
    )                                                                   ;End list
  )                                                                     ;End entity make
  (command "_.move" "_l" "" TFBP INPT "")                               ;Move command, last object from text first base point to insertion point 
  (prompt "\nRotation Angle: ")                                         ;Get rotation angle
  (command "_.rotate" "_l" "" INPT pause)                               ;Rotate command, last object, rotate on insertion point
)                                                                       ;End defun
(defun MTCJ_FONT ()                                                     ;Define function (FONT)
  (command "_.STYLE" "romans" "romans.shx" "0.0" "1.0" "0" "N" "N" "N") ;style command
  (princ)                                                               ;Exit quietly
)                                                                       ;End defun
(defun MTCJ_LAYER (NLAY CLR LT / LAY FRZ)                               ;Define function (Make Layer), Declare local varibles & arguments
  (setq LAY (tblsearch "layer" NLAY))                                   ;Search drawing for layer
  (if (not LAY)                                                         ;If layer not found
    (command "_.-layer" "_m" NLAY "_c" CLR "" "_lt" LT "" "")           ;Make layer, color & linetype
    (progn                                                              ;Then do the following
      (setq FRZ (cdr (assoc 70 LAY)))                                   ;Look for frozen layers from last edit
      (if (= FRZ 65)                                                    ;if any layers frozen
        (progn                                                          ;Then do the following
          (command "_.-layer" "_t" NLAY "")                             ;Thaw layer
          (command "_.-layer" "_s" NLAY "")                             ;Set layer
        )                                                               ;End progn
        (command "_.-layer" "_s" NLAY "")                               ;Set layer
      )                                                                 ;End if
    )                                                                   ;End progn
  )                                                                     ;End if
  (princ)                                                               ;Exit quietly
)                                                                       ;End defun

The Buzzard is offline   Reply With Quote
Old 3rd Nov 2009, 11:14 pm   #5
alanjt
Super Member
 
alanjt's Avatar
 
Using: Civil 3D 2009
 
Join Date: Apr 2008
Posts: 1,488
Default

This might also help for object info extraction:

Code:
;;; VLA & DXF Info of selected Primary or Nested object
;;; Alan J. Thompson
(defun c:Info (/ #Choice #Obj)
  (vl-load-com)
  (initget 0 "Nested Primary")
  (and (or (setq #Choice (getkword "\nNested or Primary object [Nested/<Primary>]: "))
           (setq #Choice "Primary")
       ) ;_ or
       (cond
         ((eq #Choice "Primary")
          (setq #Obj (entsel "\nSelect Primary object for VLA & DXF info: "))
         )
         ((eq #Choice "Nested")
          (setq #Obj (nentsel "\nSelect Nested object for VLA & DXF info: "))
         )
       ) ;_ cond
       (not (textscr))
       (princ "\nVLA Info:\n\n")
       (vlax-dump-object (vlax-ename->vla-object (car #Obj)) T)
       (princ "\nDXF Info:\n")
       (mapcar 'print (entget (car #Obj)))
  ) ;_ and
  (princ)
) ;_ defun

Seann: ...it went crazy ex-girlfriend on me...
eric_monceaux...
its pretty funny seeing two AutoCAD Gods give each other flak...
alanjt is offline   Reply With Quote
Old 3rd Nov 2009, 11:21 pm   #6
The Buzzard
Super Member
 
Using: AutoCAD 2009
 
Computer Details
 
Join Date: Oct 2008
Location: New York, New York
Posts: 1,252
Default

Quote:
Originally Posted by alanjt View Post
This might also help for object info extraction:

Code:
;;; VLA & DXF Info of selected Primary or Nested object
;;; Alan J. Thompson
(defun c:Info (/ #Choice #Obj)
  (vl-load-com)
  (initget 0 "Nested Primary")
  (and (or (setq #Choice (getkword "\nNested or Primary object [Nested/<Primary>]: "))
           (setq #Choice "Primary")
       ) ;_ or
       (cond
         ((eq #Choice "Primary")
          (setq #Obj (entsel "\nSelect Primary object for VLA & DXF info: "))
         )
         ((eq #Choice "Nested")
          (setq #Obj (nentsel "\nSelect Nested object for VLA & DXF info: "))
         )
       ) ;_ cond
       (not (textscr))
       (princ "\nVLA Info:\n\n")
       (vlax-dump-object (vlax-ename->vla-object (car #Obj)) T)
       (princ "\nDXF Info:\n")
       (mapcar 'print (entget (car #Obj)))
  ) ;_ and
  (princ)
) ;_ defun
Great program Alan,

I have something new for my toolbox.

Thanks!

The Buzzard is offline   Reply With Quote
Old 3rd Nov 2009, 11:24 pm   #7
alanjt
Super Member
 
alanjt's Avatar
 
Using: Civil 3D 2009
 
Join Date: Apr 2008
Posts: 1,488
Default

Quote:
Originally Posted by The Buzzard View Post
Great program Alan,

I have something new for my toolbox.

Thanks!
You're quite welcome.
I use it all the time.

Seann: ...it went crazy ex-girlfriend on me...
eric_monceaux...
its pretty funny seeing two AutoCAD Gods give each other flak...
alanjt is offline   Reply With Quote
Old 3rd Nov 2009, 11:29 pm   #8
The Buzzard
Super Member
 
Using: AutoCAD 2009
 
Computer Details
 
Join Date: Oct 2008
Location: New York, New York
Posts: 1,252
Default

Quote:
Originally Posted by alanjt View Post
You're quite welcome.
I use it all the time.
Its very versatile as it can be used for nested as well as primary &
dxf as well as vla. This will help me greatly in learning vla.

The Buzzard is offline   Reply With Quote
Old 3rd Nov 2009, 11:39 pm   #9
alanjt
Super Member
 
alanjt's Avatar
 
Using: Civil 3D 2009
 
Join Date: Apr 2008
Posts: 1,488
Default

Quote:
Originally Posted by The Buzzard View Post
Its very versatile as it can be used for nested as well as primary &
dxf as well as vla. This will help me greatly in learning vla.
I'm lazy so I always make sure I can stick everything in one nice little package.

Dig through my subroutine thread, there's a lot of VLA subroutines in there.

Seann: ...it went crazy ex-girlfriend on me...
eric_monceaux...
its pretty funny seeing two AutoCAD Gods give each other flak...
alanjt is offline   Reply With Quote
Old 3rd Nov 2009, 11:45 pm   #10
The Buzzard
Super Member
 
Using: AutoCAD 2009
 
Computer Details
 
Join Date: Oct 2008
Location: New York, New York
Posts: 1,252
Default

Quote:
Originally Posted by alanjt View Post
I'm lazy so I always make sure I can stick everything in one nice little package.

Dig through my subroutine thread, there's a lot of VLA subroutines in there.

I run out now to check out the sales!

The Buzzard is offline   Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Match text justification kool130 AutoCAD 2D Drafting, Object Properties & the Interface 3 24th Feb 2009 12:15 pm
Text formatting - Justification settings in Properties text override edwin AutoCAD General 7 20th Nov 2008 01:33 pm
Text - Justification Routine Help ILoveMadoka AutoLISP, VBA, the CUI & Customisation 3 15th Nov 2008 12:17 am
text justification acad 2009 - which variable to alter? sparklerach AutoCAD General 3 27th Aug 2008 03:32 pm
Attribute text justification paulmcz AutoCAD General 6 25th Feb 2007 06:46 pm

Why Donate?


All times are GMT +1. The time now is 12:05 pm.

RSS Feed for AutoCAD ForumsValid XHTML 1.0!Valid CSS!Creative Commons Licence