Author Topic: Fields Not Recognised in "Entmade" MText  (Read 3354 times)

0 Members and 1 Guest are viewing this topic.

Lee Mac

  • Seagull
  • Posts: 12927
  • London, England
Fields Not Recognised in "Entmade" MText
« on: September 17, 2009, 01:47:34 PM »
When I use EntMake to create some MText containing fields - it seems that I have to "ddedit" the MText after program completion for the fields to be recognised.

Has anyone else had this problem, and, if so, is there any way around it?

Your help and patience are appreciated.   :-)


Lee

gile

  • Gator
  • Posts: 2520
  • Marseille, France
Re: Fields Not Recognised in "Entmade" MText
« Reply #1 on: September 17, 2009, 02:25:51 PM »
Hi,

The FIELD object is stored in a dictionary ("TEXT") which is stored in a dictionary ("ACAD_FIELD") which is stored in the extension dictionary of the text, mtext or attribute. So you'll have to entmake these entries (dictionaries) in the mtext extension dictionary, more a "FIELD" object...

You'd rather use (vla-put-TextString ...) which works with field codes.

I wrote a routine to get the field code of TEXT, MTEXT or ATTRIBUTES because vla-FieldCode doesn't work with attributes. You can get some inspiration if you really need to use entmake...

Code: [Select]
;; gc:FieldCode (gile)
;; Retourne la chaîne de caractère d'un attribut, texte ou mtexte
;; avec le(s) code(s) de champ(s)
;;
;; Argument : nom d'entité de l'objet (ENAME)

(defun gc:FieldCode (ent / foo elst xdict dict field str)

  ;;--------------------------------------------------------;;
  (defun foo (field str / pos fldID objID)
    (setq pos 0)
    (if (setq pos (vl-string-search "\\_FldIdx " str pos))
      (while (setq pos (vl-string-search "\\_FldIdx " str pos))
        (setq fldId (entget (cdr (assoc 360 field)))
              field (vl-remove (assoc 360 field) field)
              str   (strcat
                      (substr str 1 pos)
                      (if (setq objID (cdr (assoc 331 fldId)))
                        (vl-string-subst
                          (strcat "ObjId " (itoa (gc:EnameToObjectId objID)))
                          "ObjIdx"
                          (cdr (assoc 2 fldId))
                        )
                        (foo fldId (cdr (assoc 2 fldId)))
                      )
                      (substr str (1+ (vl-string-search ">%" str pos)))
                    )
        )
      )
      str
    )
  )
  ;;--------------------------------------------------------;;
 
  (setq elst (entget ent))
  (if (and
(member (cdr (assoc 0 elst)) '("ATTRIB" "MTEXT" "TEXT"))
(setq xdict (cdr (assoc 360 elst)))
(setq dict (dictsearch xdict "ACAD_FIELD"))
(setq field (dictsearch (cdr (assoc -1 dict)) "TEXT"))
      )
    (setq str (foo field (cdr (assoc 2 field))))
  )
)
Speaking English as a French Frog

Lee Mac

  • Seagull
  • Posts: 12927
  • London, England
Re: Fields Not Recognised in "Entmade" MText
« Reply #2 on: September 17, 2009, 02:33:23 PM »
Many thanks for your reply Gile - that is very informative  :-)

I didn't know that the Field was stored in that hierarchy - but I shall study your code a bit more to familiarise myself with it.

I think I will go down the vla-put-TextString route after all - great alternative.

Thanks,

Lee


T.Willey

  • Needs a day job
  • Posts: 5251
Re: Fields Not Recognised in "Entmade" MText
« Reply #3 on: September 17, 2009, 02:49:30 PM »
This may help.  Its a thread I created when I was working on entmaking fields.  Working code is in there also.

[ http://www.theswamp.org/index.php?topic=20446.0 ]
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Lee Mac

  • Seagull
  • Posts: 12927
  • London, England
Re: Fields Not Recognised in "Entmade" MText
« Reply #4 on: September 17, 2009, 02:51:52 PM »
Thanks Tim, will check it out mate  :-)

gile

  • Gator
  • Posts: 2520
  • Marseille, France
Re: Fields Not Recognised in "Entmade" MText
« Reply #5 on: September 17, 2009, 03:53:05 PM »
Great work Tim :lol:
Speaking English as a French Frog

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Fields Not Recognised in "Entmade" MText
« Reply #6 on: September 17, 2009, 04:01:10 PM »
Thanks Tim, will check it out mate  :-)

You're welcome Lee.  Hope you can find it useful.


Great work Tim :lol:

Thanks Gile.  I forget how long it took to figure some of that stuff out, but was a good challenge.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Lee Mac

  • Seagull
  • Posts: 12927
  • London, England
Re: Fields Not Recognised in "Entmade" MText
« Reply #7 on: September 17, 2009, 04:06:37 PM »
I second Gile's sentiment... superb work - not sure how you came by all the information on the DXF codes - but there sure are a lot of them!

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Fields Not Recognised in "Entmade" MText
« Reply #8 on: September 17, 2009, 04:14:12 PM »
I second Gile's sentiment... superb work - not sure how you came by all the information on the DXF codes - but there sure are a lot of them!

Thanks Lee.  I think I had to look in the Arx Sdk for a lot of information.  And then there was still a lot of trial and error when figuring it out.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Lee Mac

  • Seagull
  • Posts: 12927
  • London, England
Re: Fields Not Recognised in "Entmade" MText
« Reply #9 on: September 17, 2009, 04:14:40 PM »
I second Gile's sentiment... superb work - not sure how you came by all the information on the DXF codes - but there sure are a lot of them!

Thanks Lee.  I think I had to look in the Arx Sdk for a lot of information.  And then there was still a lot of trial and error when figuring it out.

Time well spent  :-)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Fields Not Recognised in "Entmade" MText
« Reply #10 on: September 17, 2009, 04:16:12 PM »
I second Gile's sentiment... superb work - not sure how you came by all the information on the DXF codes - but there sure are a lot of them!

Thanks Lee.  I think I had to look in the Arx Sdk for a lot of information.  And then there was still a lot of trial and error when figuring it out.

Time well spent  :-)

Not yet for me, as we don't use fields here, but was fun still.   :-)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.