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

Convert Field to Text

27 REPLIES 27
Reply
Message 1 of 28
Anonymous
6538 Views, 27 Replies

Convert Field to Text

What is the Command that Converts a Field to Text so that I can stop a Field
updating after the initial set-up?

I need to apply this in lisp.

TIA

Jim
27 REPLIES 27
Message 2 of 28
Anonymous
in reply to: Anonymous

Jim Pehrsson said the following On 8/1/2006 7:25 AM:
> What is the Command that Converts a Field to Text

EXPLODE

--
R.K. McSwain
http://rkmcswain.blogspot.com
Message 3 of 28
Anonymous
in reply to: Anonymous

Explode does the trick given a text object. But fields may be contained in mtext
objects. In that case explode would destroy the mtext object as well.

So if fields in mtext are a concern, you would have to strip out the field control
characters to maintain the mtext object. Or explode the mtext and make a new mtext
object from the strings contained in the previous selection set.

From a programming standpoint, AFAIK the only way to determine whether a text or
mtext object contains a field is by using the FieldCode method.

(setq ename (car (entsel "\nSelect text or mtext: ")))
(setq obj (vlax-ename->vla-object ename))
(if
(not
(eq
(vlax-get obj 'TextString)
(vlax-invoke obj 'FieldCode)
)
)
;then the object contains a field
;else the object doesn't
)

Joe Burke


"R.K. McSwain" wrote in message
news:5254433@discussion.autodesk.com...
Jim Pehrsson said the following On 8/1/2006 7:25 AM:
> What is the Command that Converts a Field to Text

EXPLODE

--
R.K. McSwain
http://rkmcswain.blogspot.com
Message 4 of 28
Anonymous
in reply to: Anonymous

Thank you Joe & RK

Jim
Message 5 of 28
Ian_Bryant
in reply to: Anonymous

Hi,
adapt the following.
You need to regen to see the result.
(defun C:R-FIELD ( / ent)
(if (setq ent (car (nentsel "\nPick a field object: ")))
(entdel (cdr (assoc -1
(dictsearch (cdr (assoc 360 (entget ent))) "ACAD_FIELD")
))))
(princ)
)

Regards Ian
Message 6 of 28
Anonymous
in reply to: Anonymous

Joe Burke said the following On 8/1/2006 8:51 AM:
> Explode does the trick given a text object. But fields may be contained in mtext
> objects. In that case explode would destroy the mtext object as well.
>
> So if fields in mtext are a concern, you would have to strip out the field control
> characters to maintain the mtext object. Or explode the mtext and make a new mtext
> object from the strings contained in the previous selection set.

Good point. I was simply thinking of a single line object created with
the FIELD command and getting it back to a TEXT object (as the subject
stated).

--
R.K. McSwain
http://rkmcswain.blogspot.com
Message 7 of 28
Anonymous
in reply to: Anonymous

R.K. McSwain,

I was only adding to what you said... 🙂

Jim,

You're welcome.

Joe Burke


"R.K. McSwain" wrote in message
news:5255956@discussion.autodesk.com...
Joe Burke said the following On 8/1/2006 8:51 AM:
> Explode does the trick given a text object. But fields may be contained in mtext
> objects. In that case explode would destroy the mtext object as well.
>
> So if fields in mtext are a concern, you would have to strip out the field control
> characters to maintain the mtext object. Or explode the mtext and make a new mtext
> object from the strings contained in the previous selection set.

Good point. I was simply thinking of a single line object created with
the FIELD command and getting it back to a TEXT object (as the subject
stated).

--
R.K. McSwain
http://rkmcswain.blogspot.com
Message 8 of 28
devon.middleditch
in reply to: Anonymous

Would it be possible in this case to go one step further?

Run the code on 1 particular attribute tag eg "drawing_number" convert field it to text, then remove the last 3 charachters from the text string??

thanks
Devon
Message 9 of 28
Ian_Bryant
in reply to: Anonymous

Hi,
try the attached lsp file.
If you want to be able pick a block insert
and change on the attribute tagged "drawing_number"
use (att_trim "drawing_number").
If you want to attributes tagged "drawing_number"
in all block inserts in the drawing
use (att_trim_all "drawing_number").
If you want to include nested block's you will
have to adapt the second function to step through
the block table checking any inserts in each block definition.
The functions don't allow for duplicate attribute tags in
a block definition, if you want to do this, you can change
the two lines commented with ***
from (setq ent nil) to (setq ent (entnext ent)).
Regards Ian
Message 10 of 28
badder2
in reply to: Anonymous

This routine works great, is their any easy way to make it work on a selection instead of one item at a time. I would like to convert all fields to text in modelspace.

thx
Message 11 of 28
Ian_Bryant
in reply to: Anonymous

Hi,
you could try the attached lsp.
It coverts all fields in modelspace
text, mtext, mleaders and block attributes.
It does not convert text within
a block, or anything in a nested block.

Regards Ian
Message 12 of 28
Ian_Bryant
in reply to: Anonymous

Hi,
as a p.s. I changed the
original field removal function
from the entdel version to the
dictremove version, because
the dictremove version ignores
locked layers, whereas the
entdel version does not.
Regards Ian
Message 13 of 28
onossa007
in reply to: Anonymous

Because of my drawing (with Fields both on attributes and mtext, on several paper space layouts) are intended to be inserted inside another drawing, with obviously the lost of requested Object IDs, I should replace all fields presents in my drawing before it could be inserted...
Do you have a solution to do it in only one command ?

Thanks a lot for all your help !

(please excuse my poor "french english")
Message 14 of 28
onossa007
in reply to: Anonymous

Hi Ian,

I've tried to use your code, but in paper space, because it's where I have all my fields...
I've disabled the space control inside your code to not switch to tilemode 1.
I obtain no error, but all my fields stayed in place...
Do you have an idea of the reason why it doesn't work in paper space ?
To match my need, do you know about a code wich works in paperspaces (several layouts... But I don't mind in launching a comand in each one...
Thanks a lot for you big help !!!

Olivier
Message 15 of 28
Ian_Bryant
in reply to: Anonymous

Hi,
that code was written a few years ago.
While it worked fine in Autocad 2007
I have since discovered that it does not work
properly with Mtext & Dimensions in 2008 & 2009.
Attached is a revised version which does work.
I have changed it to only modify entities in paperspace.

Change the file name from R-FIELDS-PS.TXT
to R-FIELDS-PS.LSP

Regards Ian
Message 16 of 28
MatteoJames
in reply to: Anonymous

Hi Ian,

Looking at your lisp "R-FIELDS-PS" and I like it a lot cause I'm using fields everyday, and at the moment I've got a few drawings with more than 2000 fields in texts, dims, mtexts and block attributes. I have used your old version of the lisp posted before and like it a lot.

Now, looking at the code of "R-FIELDS-PS", I can't find the way to make it work only in model space insted of only paper space.

Can you, or some one, give me a hand to modify your lisp please?



Matteo.
Message 17 of 28
Ian_Bryant
in reply to: Anonymous

Hi,
change
(ssget "X"
(list
(cons 0 "TEXT,MTEXT,MULTILEADER,DIMENSION")
(cons 67 1)
)
)
to
(ssget "X"
(list
(cons 0 "TEXT,MTEXT,MULTILEADER,DIMENSION")
(cons 67 0)
)
)
regards Ian
Message 18 of 28
MatteoJames
in reply to: Anonymous

Thanks Ian!

It had to be something as stupid as a 0/1 switch. Just what I need 🙂



Matteo
Message 19 of 28
Ian_Bryant
in reply to: Anonymous

Hi,
You also need to change
(setq ss1
(ssget "X"
(list (cons 0 "INSERT")
(cons 67 1)
(cons 66 1)
)
)
)
to
(setq ss1
(ssget "X"
(list (cons 0 "INSERT")
(cons 67 0)
(cons 66 1)
)
)
)

Regards Ian
Message 20 of 28
MatteoJames
in reply to: Anonymous

Yep, I got that one on my own!



Thanks



Matteo

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

Post to forums  

Autodesk Design & Make Report

”Boost