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

AutoLisp and Fields

33 REPLIES 33
SOLVED
Reply
Message 1 of 34
angiegauthier
10532 Views, 33 Replies

AutoLisp and Fields

Hi Everyone,

 

Is it possible to access fields with autolisp? I'd like to be able to link them with dimension text, but I want the user to be able to select the dimension they want, and then the field would update (using autolisp). I know very little about fields, and haven't been able to see how to change/update them using Lisp. (I'm using ACAD 2008, if that makes a difference.)

 

Angie

33 REPLIES 33
Message 2 of 34
Moshe-A
in reply to: angiegauthier

Angie,

 

it's true that there are (at least i couldn't find) no VisualLisp functions to control Fields

but there are DXF group code for field and you can access it with (entget) if you like to dig.

 

but...as far as i understand fields are aimed to simple user who can not write a autolisp programs

if you know VisualLisp (especially Reactors) you could do 'almost' every thing that fields do.

 

what is the task you trying to achieve?

 

Moshe

 

Message 3 of 34

I want to have text linked with the dimensions. I know how to create the text from the dimensions using autolisp, but I'd like to have the text remain linked with the dimensions so that if the user makes a manual change to the drawing, the text showing the measurement would update without the user having to remember to run another program. Seems like using fields would be the answer.

Angie

Message 4 of 34
Patchy
in reply to: angiegauthier

"Seems like using fields would be the answer"  so what is the obstacle?

Field, object, pick the text of dimension,measurement ? 

 

Message 5 of 34
angiegauthier
in reply to: Patchy

How do I create a field linked to a dimension using autolisp? I can do it manually, but I'd like it to be part of the autolisp program so the user doesn't have to do it.

Message 6 of 34
markruys2
in reply to: angiegauthier

 

do the field you desire, then copy the strange text shown at the bottom ... this example is for area...

%<\AcObjProp Object(%<\_ObjId 8796079302672>%).Area \f "%pr0%lu2%ct4%qf1 SQ. FT.">%

use subst &  entmod in lisp to apply the field to the text/attrib/mtext object.

HTH

Message 7 of 34
_Tharwat
in reply to: markruys2

Not tested , but I think it is working if your OS is 32 .

 

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

 Tharwat

Message 8 of 34
angiegauthier
in reply to: _Tharwat

Oh fantastic! that is just what I needed. Thank you so much!

Angie

Message 9 of 34
_Tharwat
in reply to: angiegauthier

You're welcome .

 

Tharwat

Message 10 of 34
eddyrichardson
in reply to: _Tharwat

I have been wanting to know how to use fields in lisp for a long time..

 

The routine submitted has shown me the way how to do it.

 

I have adapted the routine to generate the name of a block and also the layer name, something I have been doing long hand for a while now for block libraries Thanks for that.

 

Just one question, what does the expression 4. do?

Message 11 of 34

 

Can Lisp, or another method, be used to modify Fields in Sheetset etc. I'd like to modify or update dates, text, and revision fields within several large drawing packages which use Sheetsets, is this possible, what would be the best tool / method to use?

 

 

 

Thanks ! ! !

Message 12 of 34

why is not working?

 

(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)))
">%)Area \f "%lu2%pr2%ps[, m²]%ct8[0.0001]">%"
)
)
(princ)
)
(princ)
)

 

 

Thanks!

Tags (1)
Message 13 of 34
kakt00z
in reply to: Gustavo_Bernardi

may be u need to add slash before quotes

something liske that :

"%<\AcObjProp Object(%<\_ObjId "

(itoa (vla-get-ObjectID (vlax-ename->vla-object ss)))

">%).Area \f \"%lu2\">%

Message 14 of 34
pbejse
in reply to: Gustavo_Bernardi


@Gustavo_Bernardi wrote:

why is not working?

 

Thanks!


(strcat
  "%<\\AcObjProp.16.2 Object(%<\\_ObjId "
  (itoa (vla-get-ObjectID (vlax-ename->vla-object ss)))
  ">%).Area \\f \"%lu2%pr2%ps[,m²]\">%"
  )

 

HTH

 

Message 15 of 34

nothing yet ...

I need to measure the area that is in centimeters and put text in square meters. It would be great if you could put the unit at the end of the text (m2).

Thanks for now

Message 16 of 34
pbejse
in reply to: Gustavo_Bernardi


@Gustavo_Bernardi wrote:

nothing yet ...

I need to measure the area that is in centimeters and put text in square meters. It would be great if you could put the unit at the end of the text (m2).

Thanks for now


Nothing happens? no prompt for text location or no text at all? whats the error?

sq centimeters to sq meters -- > 15000 = 1.5 ?

64 bit OS?

 

It would help if you'll give us more info.

 

Message 17 of 34

Hi, yes my OS is 64-bit.

The object selection is no problem, the base point is then asked me the error that appears is this:
"Specify Text Location:, error: bad argument type: nil stringp"

What I did was take the code at the beginning of this topic. So I changed that part of the field by code provided by window creation field with my desired properties.

Yes, what I need is a measure of area with the value 15000 return me the value 1.5

 

Thanks for your patience

 

The code works for you?

 

(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)))
">%)Area \f "%lu2%pr2%ps[, m²]%ct8[0.0001]">%"
)
)
(princ)
)
(princ)
)

 

Message 18 of 34
pbejse
in reply to: Gustavo_Bernardi

Try the attached file

 

Message 19 of 34
Gustavo_Bernardi
in reply to: pbejse

The field works well ... thank you

 

Just wish I could control the width of the text box so that the symbol is not in the second row.

In another lisp that I created, I used the code STRLEN to get the text length (in letters) and multiply by an average width.

 

I still have to study these VL-something ... I do not understand any of this, I create my lisps only with get--- and command

 

Thank you for your attention

Message 20 of 34
pbejse
in reply to: Gustavo_Bernardi


@Gustavo_Bernardi wrote:

The field works well ... thank you

 

Just wish I could control the width of the text box so that the symbol is not in the second row.

In another lisp that I created, I used the code STRLEN to get the text length (in letters) and multiply by an average width.

  

Thank you for your attention


You are welcome, I will look into that width thingy tommorrow.

 

Cheers

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

Post to forums  

Autodesk Design & Make Report

”Boost