Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
*Jim Pehrsson
Message 1 of 24 (533 Views)

Convert Field to Text

533 Views, 23 Replies
08-01-2006 05:25 AM
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
*R.K. McSwain
Message 2 of 24 (533 Views)

Re: Convert Field to Text

08-01-2006 05:38 AM in reply to: *Jim Pehrsson
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
*Joe Burke
Message 3 of 24 (533 Views)

Re: Convert Field to Text

08-01-2006 06:51 AM in reply to: *Jim Pehrsson
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
*Jim Pehrsson
Message 4 of 24 (533 Views)

Re: Convert Field to Text

08-01-2006 05:03 PM in reply to: *Jim Pehrsson
Thank you Joe & RK

Jim
Valued Mentor
Ian_Bryant
Posts: 362
Registered: ‎06-02-2005
Message 5 of 24 (533 Views)

Re: Convert Field to Text

08-01-2006 05:34 PM in reply to: *Jim Pehrsson
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
*R.K. McSwain
Message 6 of 24 (533 Views)

Re: Convert Field to Text

08-02-2006 05:26 AM in reply to: *Jim Pehrsson
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
*Joe Burke
Message 7 of 24 (533 Views)

Re: Convert Field to Text

08-02-2006 06:32 AM in reply to: *Jim Pehrsson
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
Distinguished Contributor
devon.middleditch
Posts: 307
Registered: ‎12-09-2003
Message 8 of 24 (533 Views)

Re: Convert Field to Text

11-20-2006 03:34 PM in reply to: *Jim Pehrsson
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
Valued Mentor
Ian_Bryant
Posts: 362
Registered: ‎06-02-2005
Message 9 of 24 (533 Views)

Re: Convert Field to Text

11-22-2006 03:44 PM in reply to: *Jim Pehrsson
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
Active Contributor
badder2
Posts: 28
Registered: ‎05-13-2005
Message 10 of 24 (533 Views)

Re: Convert Field to Text

11-14-2007 01:55 PM in reply to: *Jim Pehrsson
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
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.