Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
*Expert Elite*
2,535 Posts
306 Kudos
Registered: ‎11-24-2009
Post 21 of 29

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
20 Posts
0 Kudos
Registered: ‎05-30-2009
Post 22 of 29

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
55 Posts
0 Kudos
Registered: ‎11-08-2010
Post 23 of 29

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
20 Posts
0 Kudos
Registered: ‎05-30-2009
Post 24 of 29

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
55 Posts
0 Kudos
Registered: ‎11-08-2010
Post 25 of 29

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
1 Posts
0 Kudos
Registered: ‎01-05-2013
Post 26 of 29

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!!!!!!!!

New Member
1 Posts
0 Kudos
Registered: ‎06-12-2014
Post 27 of 29

Re: AutoLisp and Fields

10-10-2014 06:39 AM in reply to: abaluuuu

Thank you about the rutine display above, it returns with Mtext

 

is it possible to obtain text version of it? 

 

thank you again. 

Active Contributor
44 Posts
0 Kudos
Registered: ‎12-30-2008
Post 28 of 29

Re: AutoLisp and Fields

10-11-2014 11:43 AM in reply to: korayozal

Just curious has anyone been able to do the reverse of a field? Find the object that field if refering to? Example, if have text thats value is the contents of another text entity. How can i find where the refernce is coming from?

Leland
Civil3d 2012
Windows 7 64x (16 gigs ram)
*Expert Elite*
3,561 Posts
542 Kudos
Registered: ‎12-17-2004
Post 29 of 29

Re: AutoLisp and Fields

10-11-2014 02:15 PM in reply to: lelandleahy4987

lelandleahy4987 wrote:

Just curious has anyone been able to do the reverse of a field? Find the object that field if refering to? Example, if have text thats value is the contents of another text entity. How can i find where the refernce is coming from?


Hi Leland,

 

one way at go.lsp by jdvillarreal...

 

Hope that helps

Henrique

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!