LEE MAC AreaLabelV1-9.lsp (USE LETTERS AND NOT NUMBERS)

LEE MAC AreaLabelV1-9.lsp (USE LETTERS AND NOT NUMBERS)

NMichperry
Explorer Explorer
582 Views
4 Replies
Message 1 of 5

LEE MAC AreaLabelV1-9.lsp (USE LETTERS AND NOT NUMBERS)

NMichperry
Explorer
Explorer

I have this routine from LEE MAC I have used for awhile now. My new job likes it as well however it labels the hatch areas with numbers and not letters, for dumb reasons I don't care to explain we have to use ABC to label the areas, 

 

 

I thought it would be as easy as changing this this line everywhere in the code. but it looks like its more complicated than that. 

 

Any ideas

 

 

(strcat pf (itoa *al:num) sf) TO (strcat pf (chr (+ 64 *al:num)) sf)

 

 

Area Label | Lee Mac Programming

 

 

0 Likes
583 Views
4 Replies
Replies (4)
Message 2 of 5

paullimapa
Mentor
Mentor

may want to contact him directly for this revision:

Contact | Lee Mac Programming


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 5

Sea-Haven
Mentor
Mentor

Agree with @paullimapa, but if you must you can use (chr x) this will return "A" for x=65 B=66 and so on. if you exceed 26 ie Z then there is a way to do AA AB and so on.

 

I will leave it up to you to work out the change in Lee's code.

0 Likes
Message 4 of 5

NMichperry
Explorer
Explorer

 

Was able to work it out,

 

Leaving this here for the future if anyone tries the same thing. This version uses letters for the area markers and just inserts the area data as text and not use the ugly Autocad table 

 

(defun c:AT ( / *error* _startundo _endundo _centroid _text acdoc acspc cm el p1 ts ucsxang ucszdir label areas pt ent inspt cf alstart)

(setq cf 0.00694444) ; square inches to square feet

(defun *error* ( msg )
(if cm (setvar 'CMDECHO cm))
(_EndUndo acdoc)
(if (and el (entget el)) (entdel el))
(princ (strcat "\nError: " msg))
(princ))

(defun _StartUndo ( doc ) (_EndUndo doc) (vla-StartUndoMark doc))
(defun _EndUndo ( doc ) (if (= 8 (logand 8 (getvar 'UNDOCTL))) (vla-EndUndoMark doc)))

(defun _centroid ( space objs / reg cen )
(setq reg (car (vlax-invoke space 'addregion objs))
cen (vlax-get reg 'centroid))
(vla-delete reg)
(trans cen 1 0))

(defun _text ( space point string height rotation / text )
(setq text (vla-addtext space string (vlax-3D-point point) height))
(vla-put-alignment text acalignmentmiddlecenter)
(vla-put-textalignmentpoint text (vlax-3D-point point))
(vla-put-rotation text rotation)
text)

;; Initialize
(setq acdoc (vla-get-activedocument (vlax-get-acad-object))
acspc (if (= 1 (getvar 'CVPORT))
(vla-get-paperspace acdoc)
(vla-get-modelspace acdoc))
ucszdir (trans '(0 0 1) 1 0 t)
ucsxang (angle '(0 0 0) (trans (getvar 'UCSXDIR) 0 ucszdir))
ts 48.0 ; label text height
cm (getvar 'CMDECHO))

(setvar 'CMDECHO 0)
(_StartUndo acdoc)

;; Prompt for starting letter index (A=0, B=1, ..., Z=25)
(prompt "\nSpecify Starting Letter [A=0, B=1, ..., Z=25] <0>: ")
(setq alstart (getint))
(if (not alstart) (setq alstart 0))
(setq *al:num* alstart)

(setq areas '())

;; Area selection loop
(while (setq p1 (getpoint "\nPick Area [click inside or select closed object] <Enter to finish>: "))
(cond
;; Click in space: create boundary
((vl-consp p1)
(setq el (entlast))
(vl-cmdf "_.-boundary" "_A" "_I" "_N" "" "_O" "_P" "" "_non" p1 "")
(if (not (equal el (setq el (entlast))))
(progn
(setq ent (vlax-ename->vla-object el))
(setq label (chr (+ 65 *al:num*)))
(setq *al:num* (1+ *al:num*))
(setq inspt (_centroid acspc (list ent)))
(_text acspc inspt label ts ucsxang)
(setq areas (append areas (list (list label (* cf (vla-get-area ent))))))
(redraw el 3))
(prompt "\nCould not create boundary.")))

;; Select existing object
((and (listp p1) (eq (type (car p1)) 'ENAME))
(setq ent (vlax-ename->vla-object (car p1)))
(if (and (vlax-property-available-p ent 'area)
(or (eq "AcDbRegion" (vla-get-objectname ent))
(vlax-curve-isclosed (car p1))))
(progn
(setq label (chr (+ 65 *al:num*)))
(setq *al:num* (1+ *al:num*))
(setq inspt (_centroid acspc (list ent)))
(_text acspc inspt label ts ucsxang)
(setq areas (append areas (list (list label (* cf (vla-get-area ent))))))
)
(prompt "\nInvalid selection.")))))

;; Insert area data as plain text
(if areas
(progn
(setq pt (getpoint "\nPick point to place area data: "))
(foreach row areas
(_text acspc pt (strcat (car row) ": " (rtos (cadr row) 2 2) " sqft") 24.0 0.0)
(setq pt (polar pt (/ pi 2) -30.0)))))

(_EndUndo acdoc)
(setvar 'CMDECHO cm)
(princ))

(vl-load-com)
(princ "\n:: AreaLabelAtoZ.lsp | A-Z Labeling with Text Output ::")
(princ "\n:: Command: AT ::")
(princ)

 

0 Likes
Message 5 of 5

Sea-Haven
Mentor
Mentor

A simpler way if your happy to start with A=1. Thanks to Gilles Chanteau. Note 27 = "AA"

 

;-------------------------------------------------------------------------------
; Number2Alpha - Converts Number into Alpha string
; Function By: Gilles Chanteau from Marseille, France
; Arguments: 1
;   Num# = Number to convert
; Syntax example: (Number2Alpha 731) = "ABC"
;-------------------------------------------------------------------------------
(defun Number2Alpha (Num# / Val#)
  (if (< Num# 27)
    (chr (+ 64 Num#))
    (if (= 0 (setq Val# (rem Num# 26)))
      (strcat (Number2Alpha (1- (/ Num# 26))) "Z")
      (strcat (Number2Alpha (/ Num# 26)) (chr (+ 64 Val#)))
    )
  )
);defun Number2Alpha

 

 

0 Likes