Its Possible Hatch Area Leader

Its Possible Hatch Area Leader

jaimuthu
Advocate Advocate
1,062 Views
9 Replies
Message 1 of 10

Its Possible Hatch Area Leader

jaimuthu
Advocate
Advocate

Here I attached Dwg in What i expect i select all hatch  draw leader first point is hatch origin draw leader text is hatch area

0 Likes
Accepted solutions (2)
1,063 Views
9 Replies
Replies (9)
Message 2 of 10

LDShaw
Collaborator
Collaborator

Looks like you can do what you want. 

A few questions.  (The more you want the more complicated it gets)

Does the text always say the same thing? Is it always the same word or do you want as an example the first hatched area to say
"part 1"
The second
"unit b"
And
"Area"
On the last hatch
as an example?

In your example how do you select height for the text on the second and third hatches? Can we go to the Center of Gravity point or do you need to choose it each time?

Is it always on the same side (Text Justification)? Never on the left top or bottom?


Message 3 of 10

jaimuthu
Advocate
Advocate

 i want textin each hatch area of the object textheight 600 leader may be left to right or right to left ask left or right may be better leader first point is center of the hatch 

0 Likes
Message 4 of 10

john.uhden
Mentor
Mentor

@LDShaw ,

Excellent questions!

I would guess that what he needs is an MLEADER, except if he chooses the label location to be inside the hatch, in which case we can just remove the leader.

Of course if he wants all the labels to be inside the hatches then he need not pick any location.  I would still suggest using an MLEADER in case he wants to move the label out at some later time; then he can just right-click and add a leader.

Another issue is the units of area.  AutoCAD has choices for linear units and angular units, but not to my knowledge for area units (sq in, sq ft, acrea, sq cm, sq m, hectare, and maybe others of which I am not aware).

John F. Uhden

Message 5 of 10

jaimuthu
Advocate
Advocate

Area unit is sq.m

0 Likes
Message 6 of 10

john.uhden
Mentor
Mentor

@jaimuthu ,

That's helpful.  It would be embarrassing to create a label "AREA=142.3"

John F. Uhden

0 Likes
Message 7 of 10

LDShaw
Collaborator
Collaborator
Accepted solution

Not finished by a longshot but lets get something up here to play with.

 

 

 

;;; ==============================================================================
;;; Lisp Name: heditboundry.lsp
;;; Author: Lonnie
;;; Date Created: 2024-08-01
;;; https://forums.autodesk.com/t5/forums/replypage/board-id/130/message-id/469610
;;; Last Edited: [Insert Last Edit Date]
;;;
;;; DESCRIPTION:
;;; A routine to select a hatch, create a leader starting from its center of gravity,
;;; and add text at the end of the leader.
;;;
;;; Usage:
;;; 1. Load the Lisp routine.
;;; 2. Run the command "HATCHLEADERTEXT" in AutoCAD.
;;;
;;; Parameters:
;;; None
;;;
;;; Returns:
;;; None
;;;
;;; Notes:
;;; - This routine helps to label hatches by creating a leader from the centroid 
;;;   of the hatch and attaching user-specified text to the end of the leader.
;;;
;;; ---------------------------- Main program --------------------------------;

(defun c:HatchLeaderText (/ findctr hatch hatchObj centroid endPt text)
  ;; Function to find the center of a hatch by zooming to it and getting the view center
  (defun findctr (en / pt)
    (command "_.Zoom" "_Object" en "")
    (setq pt (getvar 'viewctr))
    (command "_.Zoom" "_Previous")
    pt
  )

  ;; Step 1: Choose a hatch
  (princ "\nSelect a hatch: ")
  (setq hatch (car (entsel "Select Hatch: ")))  ; Prompt user to select a hatch

  ;; Check if the selected object is a hatch
  (if (and hatch (eq (cdr (assoc 0 (entget hatch))) "HATCH"))
    (progn
      ;; Step 2: Get the center of gravity of the hatch
      (setq centroid (findctr hatch))

      ;; Print the centroid
      (princ (strcat "\nThe centroid of the hatch is: " (vl-prin1-to-string centroid)))

      ;; Step 3: Start a leader at the center of gravity
      (princ "\nSelect end point for the leader (Ortho On): ")
      (setq endPt (getpoint centroid "\nSelect end point: "))

      ;; Step 4: Ask for the text
      (setq text (getstring "\nEnter text for the leader: "))

      ;; Step 5: Add the leader and the text
      (command "_.LEADER" centroid endPt "" text)
    )
    (princ "\nSelected object is not a hatch.")
  )
  (princ)
)

(princ "\nType HATCHLEADERTEXT to run the routine.\n")

You can take out the header that's my standard one. I'd like you to leave the forum thread in it. 

I was thinking of using a fields to capture the area but I've not done that yet. 
Something along this line.

hatch.png

 

The other thing I was thinking about was a play on AREAP (Area Label - Part - Strata).lsp By www.lee-mac.com and using a block  with attribs or even steeling the front half of his lisp added to this lisp. 
"https://www.lee-mac.com/arealabel.html"

0 Likes
Message 8 of 10

Kent1Cooper
Consultant
Consultant

Something to consider....  If the Hatches are always rectangular areas [as they are in @jaimuthu's image], or other biaxially symmetrical shapes, it doesn't matter, but if not:

Kent1Cooper_0-1722613484694.png

In this kind of situation, the approach of Zooming to the Hatch OBject and then using the center of the view for the Leader arrowhead will give you the red location.

Using GCEN Object Snap on the perimeter Polyline, or taking the Centroid VLA property of a Region made from it, or taking the mathematical average of the three corners [which for a simple shape like this can be drawn directly from the Hatch pattern itself], will give you the yellow location, which I would find preferable for the arrowhead.

 

EDIT:  In fact, with the Zoom-to-OBject approach, you can get that red location that's actually outside the Hatch, with for example a shape like this:

Kent1Cooper_1-1722614588716.png

That yellow is from GCEN Osnap.  The Centroid is very slightly different from that.  The average of corners would be the same as above.

Kent Cooper, AIA
Message 9 of 10

LDShaw
Collaborator
Collaborator
Accepted solution
I know jaimuthu marked this as solved but be my guess to change it. Like I said I just wanted to get the ball rolling.
0 Likes
Message 10 of 10

LDShaw
Collaborator
Collaborator

STOP ME BEFORE I REPLY AGAIN!!!
Made some modifications. Added a field for the area. Not working great yet the area is still not defaulting like it should.
;; Define the field formatting
(setq fmt "%lu2%pr2%ps[,sq ft]") ; Length Unit

 

;;; ==============================================================================
;;; Lisp Name: heditboundry.lsp
;;; Author: Lonnie
;;; Date Created: 2024-08-01
;;; https://forums.autodesk.com/t5/forums/replypage/board-id/130/message-id/469610
;;; Last Edited: [2024-08-02]
;;;
;;; DESCRIPTION:
;;; A routine to select a hatch, create a leader starting from its center of gravity,
;;; and add text at the end of the leader.
;;;
;;; Usage:
;;; 1. Load the Lisp routine.
;;; 2. Run the command "HATCHLEADERTEXT" in AutoCAD.
;;;
;;; Parameters:
;;;  hatch centroid endPt textStr doc mtext
;;;
;;; Returns:
;;; None
;;;
;;; Notes:
;;; - This routine helps to label hatches by creating a leader from the centroid 
;;;   of the hatch and attaching user-specified text to the end of the leader.
;;;
;;; ---------------------------- Main program --------------------------------;

(defun c:HatchLeaderText (/ hatch centroid endPt textStr doc mtext)
  ;; Function to find the center of a hatch by zooming to it and getting the view center
  (defun findctr (en / pt)
    (command "_.Zoom" "_Object" en "")
    (setq pt (getvar 'viewctr))
    (command "_.Zoom" "_Previous")
    pt
  )

  ;; Define the field formatting
  (setq fmt "%lu2%pr2%ps[,sq ft]")  ; Length Unit 
  
  ;; Step 1: Choose a hatch
  (princ "\nSelect a hatch: ")
  (setq hatch (car (entsel "Select Hatch: ")))

  ;; Check if the selected object is a hatch
  (if (and hatch (eq (cdr (assoc 0 (entget hatch))) "HATCH"))
    (progn
      ;; Step 2: Get the centroid of the hatch
      (setq centroid (findctr hatch))
      (princ (strcat "\nThe centroid of the hatch is: " (vl-prin1-to-string centroid)))

      ;; Step 3: Select end point for the leader
      (princ "\nSelect end point for the leader (Ortho On): ")
      (setq endPt (getpoint centroid "\nSelect end point: "))

      ;; Step 4: Create the field string for the hatch area
      (setq textStr (strcat
        "%<\\AcObjProp Object(%<\\_ObjId "
        (LM:objectid (vlax-ename->vla-object hatch))
        ">%).Area \\f \"" fmt "\">%"
      ))

      ;; Step 5: Create the MText with the field at the specified location
      (setq doc (vla-get-activedocument (vlax-get-acad-object)))
      (setq mtext (vla-addMText (vla-get-modelspace doc) (vlax-3D-point endPt) 0.0 textStr))

      ;; Step 6: Add the leader pointing to the centroid of the hatch
      (command "_.LEADER" centroid endPt "")
    )
    (princ "\nSelected object is not a hatch.")
  )
  (princ)
)

;; ObjectID - Lee Mac
(defun LM:objectid (obj)
  (if (vlax-method-applicable-p (vla-get-utility (vla-get-activedocument (vlax-get-acad-object))) 'getobjectidstring)
    (vla-getobjectidstring (vla-get-utility (vla-get-activedocument (vlax-get-acad-object))) obj ':vlax-false)
    (itoa (vla-get-objectid obj))
  )
)

;; Entity Name to ObjectID - Lee Mac
(defun LM:ename->objectid (ent)
  (setq ent (vl-string-right-trim ">" (vl-prin1-to-string ent)))
  (setq ent (substr ent (+ (vl-string-position 58 ent) 3)))
  (LM:hex->decstr ent)
)

;; Hex to Decimal String - Lee Mac
(defun LM:hex->decstr (hex / lst rtn)
  (defun foo (lst rtn)
    (if lst
      (foo (cdr lst) (bar (- (car lst) (if (< 57 (car lst)) 55 48)) rtn))
      (apply 'strcat (mapcar 'itoa (reverse rtn)))
    )
  )
  (defun bar (int lst)
    (if lst
      (if (or (< 0 (setq int (+ (* 16 (car lst)) int))) (cdr lst))
        (cons (rem int 10) (bar (/ int 10) (cdr lst)))
      )
      (bar int '(0))
    )
  )
  (foo (vl-string->list (strcase hex)) nil)
)

;;----------------------------------------------------------------------;;

(vl-load-com)
(princ
  (strcat
    "\n:: HatchLeaderText.lsp | Version 1.0 ::"
    "\n:: Type \"HatchLeaderText\" to Invoke - Select hatch then leader endpoint ::"
  )
)
(princ)

 


Thanks once more goes out to Lee Mac.

0 Likes