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.


Some of the latest blog posts

Subscribe to RSS headline updates from:
Powered by FeedBurner