Hatch Area LISP

Hatch Area LISP

dlnmadushanka
Explorer Explorer
10,818 Views
3 Replies
Message 1 of 4

Hatch Area LISP

dlnmadushanka
Explorer
Explorer

I'm using this LSP file to get the hatch area, but I want to divide that value by 2.5. I look forward to your support for this matter

 

(defun c:DR nil (c:Areas2Field))

(defun c:Areas2Field ( / *error* _StartUndo _EndUndo acdoc acspc format pt ss ) (vl-load-com)
;; © Lee Mac 2011

(setq format "%lu6%qf1") ;; Field Formatting

(defun *error* ( msg )
(if acdoc (_EndUndo acdoc))
(or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
(princ (strcat "\n** Error: " msg " **")))
(princ)
)

(defun _StartUndo ( doc ) (_EndUndo doc)
(vla-StartUndoMark doc)
)

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

(setq acdoc (vla-get-ActiveDocument (vlax-get-acad-object))
acspc (vlax-get-property acdoc (if (= 1 (getvar 'CVPORT)) 'Paperspace 'Modelspace))
)

(if
(and
(ssget '((0 . "ARC,CIRCLE,ELLIPSE,HATCH,*POLYLINE,REGION,SPLINE")))
(setq pt (getpoint "\nPick Point for Field: "))
)
(
(lambda ( ss fld ) (_StartUndo acdoc)
(vlax-for obj ss
(setq fld
(strcat fld "%<\\AcObjProp Object(%<\\_ObjId "
(LM:GetObjectID acdoc obj) ">%).Area>% + "
)
)
)
(vla-addMText acspc (vlax-3D-point (trans pt 1 0)) 0.
(setq fld
(strcat
(substr fld 1
(- (strlen fld) (if (< 1 (vla-get-Count ss)) 3 5))
)
" \\f \"" format "\">%"
)
)
)
(vla-delete ss) (_EndUndo acdoc)
)
(setq ss (vla-get-ActiveSelectionSet acdoc))
(if (< 1 (vla-get-Count ss)) "%<\\AcExpr " "")
)
)
(princ)
)
Accepted solutions (3)
10,819 Views
3 Replies
Replies (3)
Message 2 of 4

hak_vz
Advisor
Advisor
Accepted solution

@dlnmadushanka wrote:

I'm using this LSP file to get the hatch area, but I want to divide that value by 2.5. I look forward to your support for this matter


(setq ss (vla-get-ActiveSelectionSet acdoc))
(if (< 1 (vla-get-Count ss)) "%<\\AcExpr " "")
)
)

;add code here

(setq bo (vlax-ename->vla-object (entlast)))
(setq n (/(atof(vlax-get bo 'TextString)) 2.5))
(vla-put-textstring bo n)

(princ)
)


 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 3 of 4

pbejse
Mentor
Mentor
Accepted solution

 


@dlnmadushanka wrote:

I'm using this LSP file to get the hatch area, but I want to divide that value by 2.5. I look forward to your support for this matter


 

Change

(setq format "%lu6%qf1")

to

(setq format "%lu6%qf1%ct8[0.4]")

 

HTH

 

Message 4 of 4

andkal
Collaborator
Collaborator
Accepted solution

alternatiely you can use >this< and set "Divide By" factor to 2.5
1.JPG


• www.autolisps.blogspot.com - Productivity plugins for Autocad and Autocad MEP
• Autodesk AppStore