Monday, December 5, 2011

Customize AreaText.LSP to change the text justification

I got a question how to customize this AutoLISP/Visual LISP AreaText.LSP to change the text justification. The solution is to make use of vla-put-attachmentPoint as seen in the example below.

(defun Get-ObjectIDx64 (obj / util)
  (setq util (vla-get-Utility (vla-get-activedocument (vlax-get-acad-object))))
  (if (= (type obj) 'ENAME)(setq obj (vlax-ename->vla-object obj)))
  (if (= (type obj) 'VLA-OBJECT)
    (if (> (vl-string-search "x64" (getvar "platform")) 0)
      (vlax-invoke-method util "GetObjectIdString" obj :vlax-False)
      (rtos (vla-get-objectid obj) 2 0)
    )
  )
)

(defun c:AT (/ entObject entObjectID InsertionPoint ad)
  (vl-load-com)
  (setq entObject (vlax-ename->vla-object(car (entsel)))
        entObjectID (Get-ObjectIDx64 entObject)
        InsertionPoint (vlax-3D-Point (getpoint "Select point: "))
        ad (vla-get-ActiveDocument (vlax-get-acad-object))
  )
  (vla-put-attachmentPoint (vla-addMText (if (= 1 (vla-get-activespace ad))
    (vla-get-modelspace ad)
    (if (= (vla-get-mspace ad) :vlax-true)
      (vla-get-modelspace ad)
      (vla-get-paperspace ad)
    )
  )
  InsertionPoint 0.0 (strcat
  "%<\\AcObjProp Object(%<\\_ObjId "
  entObjectID
  ">%).Area \\f \"%pr2%lu2%ct4%qf1 SQ. FT.\">%"
  )) acAttachmentPointMiddleCenter)
)

acAttachmentPointMiddleCenter can be changed to any of the following Visual LISP constants:

acAttachmentPointTopLeft
acAttachmentPointTopCenter
acAttachmentPointTopRight
acAttachmentPointMiddleLeft
acAttachmentPointMiddleCenter
acAttachmentPointMiddleRight
acAttachmentPointBottomLeft
acAttachmentPointBottomCenter
acAttachmentPointBottomRight

See also Customize AreaText.LSP for AutoCAD and AreaText.lsp updated for 64-bit AutoCAD.

6 comments:

  1. Hi! Thanks for this LISP its makes my job easier. I want to change the text height to 500 from 0.Can you please tell me how?

    ReplyDelete
  2. You cannot set the text height of the object to 0, only the for the text style.
    but if you want to set the height here is how to set it to 1 and if you want you can replace 1 with (getvar "textsize") for the current text height:

    (vla-put-Height (vla-addMText (if (= 1 (vla-get-activespace ad))
    (vla-get-modelspace ad)
    (if (= (vla-get-mspace ad) :vlax-true)
    (vla-get-modelspace ad)
    (vla-get-paperspace ad)
    )
    )
    InsertionPoint 0.0 (strcat
    "%<\\AcObjProp Object(%<\\_ObjId "
    entObjectID
    ">%).Area \\f \"%pr2%lu2%ct4%qf1 SQ. FT.\">%"
    )) 1)

    ReplyDelete
  3. I would like to round-up the square footage to the nearest 5 or 10. What changes need to be made to the lisp routine to make that happen?

    ReplyDelete
  4. Hi I have a question on how to show the area unit sqaure meter. I am using sqaure centimeter as my working units, so it always show square centimeter as the result. But in my country we use sqaure meter as area unit or another special unit that is not familiar in other countries. Is it possible to share how to modify the units in lisp?

    ReplyDelete
    Replies
    1. See http://blog.jtbworld.com/2007/10/customize-areatextlsp-for-autocad.html

      Delete

Some of the latest blog posts

Subscribe to RSS headline updates from:
Powered by FeedBurner

Contact Us | About JTB World | Subscribe to this blog
JTB World's website | Website General Terms of Use | Privacy Policy
^ Top of page

© 2004- JTB World. All rights reserved.