Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Active Contributor
dglenn9000
Posts: 48
Registered: ‎07-10-2007
Message 1 of 3 (219 Views)
Accepted Solution

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

219 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)

 

*Expert Elite*
pbejse
Posts: 2,406
Registered: ‎11-24-2009
Message 2 of 3 (208 Views)

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

 

Active Contributor
dglenn9000
Posts: 48
Registered: ‎07-10-2007
Message 3 of 3 (44 Views)

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.

 

 

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community