Message 1 of 8
Not applicable
12-22-2014
04:44 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have a script that finds an area of a polyline and creates a field that list the area and places the field in the polyline. My only problem is I would like it to round the field up to the nearest 10 (example 323 would become 330). See code below
;; local defun
;; get center of closed object
(defun getcenter (obj / acsp cen rgn)
(setq acsp (vla-get-modelspace
(vla-get-activedocument
(vlax-get-acad-object)))
rgn (car (vlax-invoke acsp 'Addregion (list obj)))
cen (vlax-get rgn 'Centroid)
)
(vla-delete rgn)
cen
)
;; main part
;; label [plines w]/area field in sq. meters
(defun c:GAREA (/ acsp adoc axss cpt ins ss txt mtxtobj)
(vl-load-com)
(or adoc
(setq adoc (vla-get-activedocument
(vlax-get-acad-object)
)
)
)
(or acsp
(setq acsp (vla-get-modelspace
adoc
)
)
)
(if
(setq ss (ssget (list (cons 0 "*POLYLINE,*CONTOUR"))))
(progn
(setq axss (vla-get-activeselectionset adoc))
;; iterate through the active selection set collection
(vlax-for obj axss
; get a curve center
(setq cpt (trans (getcenter obj) 0 1))
(setq txt
; displayed in meters to 3 decimal place:
;;; (strcat "%<\\AcObjProp Object(%<\\_ObjId "
;;; (itoa (vlax-get obj 'ObjectID))
;;; ">%).Area \\f \"%lu2%pr3%ps[, m2]%ct8[1e-006]\">%"
;;; )
; displayed in engineering to 2 decimal place:
; (strcat "%<\\AcObjProp Object(%<\\_ObjId "
; (itoa (vlax-get obj 'ObjectID))
; ">%).Area \\f \"%pr2%lu2%ct4%qf1\">%");<--pr2 means 2 decimal places, change to your suit
; displayed in engineering to 2 decimal place with addition SQ. FT.:
(strcat "%<\\AcObjProp Object(%<\\_ObjId "
(if (vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE"))
(vlax-invoke-method
(vla-get-Utility adoc)
'GetObjectIdString
obj
:vlax-false
)
(itoa (vla-get-Objectid obj))
)
">%).Area \\f \"%pr0%lu2%ct4%qf1 SF.\">%")
)
; add mtext object to model space
(setq mtxtobj (vlax-invoke
acsp 'AddMText
cpt ;insertion point
0.0 ; mtext width, optional = 0
txt ;string (field value)
))
; change mtext height accordingly to current dimension style text height:
;(vlax-put mtxtobj 'Height (getvar "dimtxt")); change (getvar "dimtxt") on text height you need
(vlax-put mtxtobj 'Height "11")
; set justifying to middle center
(vlax-put mtxtobj 'AttachmentPoint acAttachmentPointMiddleCenter)
)
)
)
(vla-regen adoc acactiveviewport)
(princ)
)
(princ "\n Type GAREA to label objects with area field")
(princ)
Solved! Go to Solution.