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.

4 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

Some of the latest blog posts

Subscribe to RSS headline updates from:
Powered by FeedBurner