Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
dglenn9000
516 Views, 2 Replies

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

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)

 

2 REPLIES 2
Message 2 of 3
pbejse
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

 

Message 3 of 3
dglenn9000
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.

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

”Boost