• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Visual LISP, AutoLISP and General Customization

    Reply
    *Jim Pehrsson

    Convert Field to Text

    267 Views, 22 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
    Please use plain text.
    *R.K. McSwain

    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
    Please use plain text.
    *Joe Burke

    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
    Please use plain text.
    *Jim Pehrsson

    Re: Convert Field to Text

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

    Jim
    Please use plain text.
    Valued Mentor
    Posts: 361
    Registered: ‎06-02-2005

    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
    Please use plain text.
    *R.K. McSwain

    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
    Please use plain text.
    *Joe Burke

    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
    Please use plain text.
    Distinguished Contributor
    Posts: 305
    Registered: ‎12-09-2003

    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
    Please use plain text.
    Valued Mentor
    Posts: 361
    Registered: ‎06-02-2005

    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
    Please use plain text.
    Active Contributor
    Posts: 28
    Registered: ‎05-13-2005

    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
    Please use plain text.