Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Enthusiast
59 Posts
Post 1 of 3
Accepted Solution

None of the get area scripts I have or searched for work in 2013. Dont know why

288 Views, 2 Replies
05-09-2013 04:17 PM

I have one get area script I have used for the last few years in 2008-2009 autocad.  Now in 2013 all I get is ####. The script is suppose to get the area of a polyline and puts the number in a text field. I have searched online and found a few others that dont work in 2013 either.  I am wondering is it a setting I need to change in my 2013, or if the scripts really are not compatible.

 

;; 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:larea (/ 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 "
;;;			(itoa (vlax-get obj 'ObjectID))
;;;			">%).Area \\f \"%pr2%lu2%ct4%qf1 SQ. FT.\">%")
	 ); 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
; set justifying to middle center
(vlax-put  mtxtobj  'AttachmentPoint acAttachmentPointMiddleCenter)  
       )      
     )
  )
     (vla-regen adoc acactiveviewport)

  (princ)
)
(princ "\n   Type LAF to label objects with area field")
(princ)

 


dglenn9000 wrote:

I have one get area script I have used for the last few years in 2008-2009 autocad.  Now in 2013 all I get is ####. The script is suppose to get the area of a polyline and puts the number in a text field. I have searched online and found a few others that dont work in 2013 either.  I am wondering is it a setting I need to change in my 2013, or if the scripts really are not compatible.

 

;; local defun
.........
; 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 the blue text to

 

(if (vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE"))
(vlax-invoke-method
(vla-get-Utility adoc)
'GetObjectIdString
obj
:vlax-false
)
(itoa (vla-get-Objectid obj))
)

 

HTH

 

AUTODESK EXPERT ELITE
2621 Posts
342 Kudos
256 Solutions
Post 2 of 3

Re: None of the get area scripts I have or searched for work in 2013. Dont know

05-09-2013 08:47 PM in reply to: dglenn9000

dglenn9000 wrote:

I have one get area script I have used for the last few years in 2008-2009 autocad.  Now in 2013 all I get is ####. The script is suppose to get the area of a polyline and puts the number in a text field. I have searched online and found a few others that dont work in 2013 either.  I am wondering is it a setting I need to change in my 2013, or if the scripts really are not compatible.

 

;; local defun
.........
	 ; 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 the blue text to

 

(if (vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE"))
			  (vlax-invoke-method
			    (vla-get-Utility adoc)
			    'GetObjectIdString
			    obj
			    :vlax-false
			  )
			  (itoa (vla-get-Objectid obj))
			)

 

HTH

 

Enthusiast
59 Posts
Post 3 of 3

Re: None of the get area scripts I have or searched for work in 2013. Dont know

06-19-2014 10:56 AM in reply to: pbejse

Thanks pbejse!  I didn't get around to using it at the time but a year laterI just found myself in the same predicament and updated my old script to work.

 

 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post