Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
*Expert Elite*
pbejse
Posts: 2,461
Registered: ‎11-24-2009
Message 21 of 26 (486 Views)

Re: AutoLisp and Fields

10-18-2012 06:29 AM in reply to: pbejse

<Not Tested for newer version>  2010 onwards 

 

(defun c:Oarea (/ Get-ObjectIDx64 space ss pt are sst tm)(vl-load-com)
;;;	Jimmy Bergmark			;;;
;;;	http://blog.jtbworld.com/	;;;
(defun Get-ObjectIDx64 (obj / util)
  (setq util (vla-get-Utility (vla-get-activedocument (vlax-get-acad-object))))
    (if (> (vl-string-search "x64" (getvar "platform")) 0)
      (vlax-invoke-method util "GetObjectIdString" obj :vlax-False)
      (itoa (vla-get-Objectid obj))
    )
  )
;;;		pBe Oct 18 2012		;;;
  (if (and (setq ss (car (entsel "\n Select Object for Area : ")))
	   (vlax-property-available-p (setq ss (vlax-ename->vla-object ss)) 'Area)
	   (setq pt (getpoint "\n Specify Text Location :"))
      )
	(progn
	  (setq are (rtos (* (vla-get-area ss) 0.0001) 2 2)
	        sst (vlax-invoke  (vlax-get (vla-get-ActiveLayout
	                 (vla-get-activedocument (vlax-get-acad-object)))
	                                         'Block)
	                                   'addMText pt 1.
			(strcat	"%<\\AcObjProp Object(%<\\_ObjId "
				(Get-ObjectIDx64 ss)
				">%).Area \\f \"%lu2%pr2%ps[, m²]%ct8[0.0001]\">%")
			)
		tm (textbox (list (cons 1 (strcat (vl-string-translate "1" "0" are) " m²"))
			      (cons 40 (vla-get-height sst))
			      (cons 7 (getvar 'TextStyle)))))
		(vla-put-width sst (distance (Car tm)(list (caadr tm)(cadar tm))))
	  )(princ "\nNo object for Area Text Selected"))
  (princ)
)

 

command: Oarea

 

HTH

 

Contributor
Gustavo_Bernardi
Posts: 20
Registered: ‎05-30-2009
Message 22 of 26 (474 Views)

Re: AutoLisp and Fields

10-18-2012 02:32 PM in reply to: pbejse

For the Arial font does not work only with this value. But if doubling works well.
I changed the code:

 

(vla-put-width sst (distance (Car tm)(list (caadr tm)(cadar tm))))

 

by

 

(vla-put-width sst (* 2(distance (Car tm)(list (caadr tm)(cadar tm)))))

and worked!

 

Thanks

 

I intend in the future to increase. I'll put a "GetString" to capture a name for the room. Also select the name of the layer via a hatch field to define the type of flooring. etc

Valued Contributor
angiegauthier
Posts: 55
Registered: ‎11-08-2010
Message 23 of 26 (375 Views)

Re: AutoLisp and Fields

01-17-2013 02:32 PM in reply to: eddyrichardson

I am working on another project were I need to use a field, but in this case we are showing imperial and metric in the dimension. (with alternate units) the field only shows the primary units. How can I get it to show both? I've tried monkeying around with it a bit using the field expression that shows up when I create the field with no luck.

Is it possible to do this?

 

angie

Contributor
Gustavo_Bernardi
Posts: 20
Registered: ‎05-30-2009
Message 24 of 26 (351 Views)

Re: AutoLisp and Fields

02-13-2013 10:21 AM in reply to: angiegauthier

I'm not sure how.

but you can convert the value using the following calculation:

1 m² = (3.28083989501) ² = 10.7639104167 ft ²

can see that in my case I need to convert from cm  to m² in the following line:

(setq are (rtos (* (vla-get-area ss) 0.0001) 2 2)

believe you can replicate content writing line area and do the conversion to their units (imperial)

 

I hope someone more expert can give a more concrete help.

 

 

Valued Contributor
angiegauthier
Posts: 55
Registered: ‎11-08-2010
Message 25 of 26 (329 Views)

Re: AutoLisp and Fields

02-14-2013 12:24 PM in reply to: pbejse

...so I cheated a little to make this work.

I drew a line along the edge I was dimensioning. then I had the field reference the length of the line instead of using the measurement. This way I was able to get the units I needed, and if the user stretches the object, the line I drew will stretch along with it and the field will still update. An extra step, but it works.

 

Angie

New Member
abaluuuu
Posts: 1
Registered: ‎01-05-2013
Message 26 of 26 (169 Views)

Re: AutoLisp and Fields

01-11-2014 05:23 AM in reply to: angiegauthier

This rutine is very good:smileyhappy:

 

(vl-load-com)
(defun c:Test (/ space ss pt)
  ; Tharwat 14. 06. 2011
  (setq space (vla-get-modelspace
                (vla-get-ActiveDocument (vlax-get-acad-object))
              )
  )
  (if (and (setq ss (car (entsel "\n Select a Dimension : ")))
           (setq pt (getpoint "\n Specify Text Location :"))
      )
    (vla-addMText
      space
      (vlax-3d-point pt)
      4.
      (strcat "%<\\AcObjProp Object(%<\\_ObjId "
              (itoa (vla-get-ObjectID (vlax-ename->vla-object ss)))
              ">%).Measurement \\f \"%lu6\">%"
      )
    )
    (princ)
  )
  (princ)
)

 

 

 

 

 

 

 

 

 

Can you help me how can write the mtext with text height 50? And after I need to explode it to convert for normal text.

 

Thank you!!!!!!!!

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 or visit the Installation and Licensing Forum to get help installing your software.