TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: mkweaver on June 03, 2008, 10:35:47 AM

Title: Entmaking fields w/Formatting
Post by: mkweaver on June 03, 2008, 10:35:47 AM
With the help of T.Willey's code in another thread (http://www.theswamp.org/index.php?topic=20446.0 (http://www.theswamp.org/index.php?topic=20446.0)) I am able to link the area of a pline to an attribute, but I have not been able to apply any formatting.  I took a shot in the dark and added the formatting string to T.Williy's code, but it isn't taking it for some reason.

Any help is appreciated:
Code: [Select]
(defun AddObjectField (AddToEname LinkObj PropName / EntData ExDict FDict PropType PropValue)
    (if
      (and
(setq EntData (entget AddToEname))
(assoc 0 EntData)
(member (cdr (assoc 0 EntData)) '("MTEXT" "ATTRIB" "ATTDEF"))
;;;            (vl-position (and
;;;    (assoc 0 EntData)
;;;    (cdr (assoc 0 entdata))
;;;    '("MTEXT" "ATTRIB" "ATTDEF"))
(setq ExDict
       (vlax-vla-object->ename
(vla-GetExtensionDictionary
   (vlax-ename->vla-object AddToEname)
   )
)
      )
(setq PropType
       
       (type
(setq PropValue
(vlax-get LinkObj PropName)
       )
)
      )
)
      (progn
(dictremove ExDict "ACAD_FIELD")
(setq FDict
       (dictadd ExDict "ACAD_FIELD"
(entmakex
  '(
    (0 . "DICTIONARY")
    (100 . "AcDbDictionary")
    (280 . 1)
    (281 . 1)
    )
  )
)
      )
(dictadd FDict "TEXT"
(entmakex
   (list
     '(0 . "FIELD")
     '(100 . "AcDbField")
     '(1 . "_text")
     '(2 . "%<\\_FldIdx 0>%")
     '(90 . 1) ;Number of child fields
     (cons 360 ;Child field ID
   (entmakex
     (list
       '(0 . "FIELD")
       '(100 . "AcDbField")
       '(1 . "AcObjProp") ; Field type
       (cons
2
(strcat
   "\\AcObjProp Object(%<\\_ObjIdx 0>%)."
   PropName
   )
)
       '(90 . 0) ; Number of child fields
       '(97 . 1) ; Number of object ids
       (cons 331 (vlax-vla-object->ename LinkObj)) ; Object id
       '(4 . "") ; format string
       '(91 . 63) ; evaluation option
       '(92 . 0) ; filling option
       ;'(94 . 59) ; field state flag
       ;'(95 . 2) ; evaluation status
       ;'(96 . 0) ; evaluation error code
       ;'(300 . "") ; evaluation error message
       '(6 . "ObjectPropertyId")
       '(90 . 64)
       (cons 330 (vlax-vla-object->ename LinkObj))
       '(6 . "ObjectPropertyName") ; key string for the field data
       '(90 . 4) ; data type of field
       (cons 1 PropName) ; name of property
       '(7 . "ACAD_FIELD_VALUE") ; key string for the evaluated cache
       (cons
90 ;data type of field
(cond
   ((equal PropType 'STR)
    4
    )
   ((equal PropType 'INT)
    1
    )
   ((equal PropType 'REAL)
    2
    )
   ((equal PropType 'LIST)
    32
    )
   )
)
       (cond ; field value
((equal PropType 'STR)
  (cons 1 PropValue)
  )
((equal PropType 'INT)
  (cons 91 PropValue)
  )
((equal PropType 'REAL)
  (cons 140 PropValue)
  )
((equal PropType 'LIST)
  (cons 11 Propvalue)
  )
)
       [color=red]'(301 . "%lu2%pr1%ct8[0.006944444444444444]") ; format string[/color]
       '(98 . 37) ; length of format string
       )
     )
   )
     '(97 . 0) ; Number of object IDs used in the field code
     [color=red]'(4 . "\\f %lu2%pr1%ct8[0.006944444444444444]") ; Format string[/color]
     ;;'(4 . "") ; Format string
     '(91 . 63) ; Evaluation option
     ;kDisable 0 Disable evaluation.
     ;kOnOpen (0x1 << 0) Evaluate during drawing load.
     ;kOnSave (0x1 << 1) Evaluate during drawing save.
     ;kOnPlot (0x1 << 2) Evaluate during drawing plot.
     ;kOnEtransmit (0x1 << 3) Evaluate during eTransmit.
     ;kOnRegen (0x1 << 4) Evaluate during regen.
     ;kOnDemand (0x1 << 5) Evaluate only on demand by the user or the API.
     ;kAutomatic (kOnOpen | kOnSave | kOnPlot | kOnEtransmit | kOnRegen | kOnDemand) Automatically evaluate fields during all the operations.
     '(92 . 0) ;Filling option
     ;kSkipFilingResult (0x1 << 0) Do not file out the cached evaluation result with the field.
     ;'(94 . 5) ;Field state flag
     ;kInitialized (0x1 << 0) Field is not yet intitalized with any field code or data.
     ;kCompiled (0x1 << 1) Field has been compiled.
     ;kModified (0x1 << 2) Field has been modified and not yet evaluated.
     ;kEvaluated (0x1 << 3) Field has been evaluated. Use evaluationStatus() to get the evaluation status.
     ;kHasCache (0x1 << 4) The field has a cache of the evaluated result.
     ;'(95 . 1) ;Evaluation status
     ;kNotYetEvaluated (0x1 << 0) Field is not yet evaluated.
     ;kSuccess (0x1 << 1) Field is evaluated successfully.
     ;kEvaluatorNotFound (0x1 << 2) Evaluator was not found.
     ;kSyntaxError (0x1 << 3) Syntax error in the field expression.
     ;kInvalidCode (0x1 << 4) Invalid field code or expression.
     ;kInvalidContext (0x1 << 5) Current context is invalid for evaluating the field.
     ;kOtherError (0x1 << 6) Evaluation has failed.
     ;'(96 . 0) ;Evaluation error code
     ;'(300 . "") ;Evaluation error message
     '(93 . 1) ;Number of the data set in the field
     '(6 . "ACFD_FIELDTEXT_CHECKSUM") ;Key string for field data
     '(90 . 2) ;Data type of field value
     '(140 . 33.0) ;Double value
     '(7 . "ACFD_FIELD_VALUE") ;Key string from the evaluated cache, hard coded as is shown here
     '(90 . 0) ;Data type of field value
     '(91 . 0) ;Long value
     [color=red]'(301 . "%lu2%pr1%ct8[0.006944444444444444]") ; format string
     '(98 . 34) ; format string length[/color]
     )
   )
)
(entupd AddToEname)
)
      )
    )
Title: Re: Entmaking fields w/Formatting
Post by: T.Willey on June 03, 2008, 11:52:24 AM
See if this works for you.  This leaves the '\f' in front of the string.

Code: [Select]
(defun AddObjectField (AddToEname LinkObj PropName / EntData ExDict FDict PropType PropValue)
    (if
        (and
            (setq EntData (entget AddToEname))
            (vl-position (value 0 EntData) '("MTEXT" "ATTRIB" "ATTDEF"))
            (setq ExDict
                (vlax-vla-object->ename
                    (vla-GetExtensionDictionary
                        (vlax-ename->vla-object AddToEname)
                    )
                )
            )
            (setq PropType
                (type
                    (setq PropValue
                        (vlax-get LinkObj PropName)
                    )
                )
            )
        )
        (progn
            (dictremove ExDict "ACAD_FIELD")
            (setq FDict
                (dictadd ExDict "ACAD_FIELD"
                    (entmakex
                        '(
                            (0 . "DICTIONARY")
                            (100 . "AcDbDictionary")
                            (280 . 1)
                            (281 . 1)
                        )
                    )
                )
            )
            (dictadd FDict "TEXT"
                (entmakex
                    (list
                        '(0 . "FIELD")
                        '(100 . "AcDbField")
                        '(1 . "_text")
                        '(2 . "%<\\_FldIdx 0>%")
                        '(90 . 1) ;Number of child fields
                        (cons 360 ;Child field ID
                            (entmakex
                                (list
                                    '(0 . "FIELD")
                                    '(100 . "AcDbField")
                                    '(1 . "AcObjProp") ; Field type
                                    (cons
                                        2
                                        (strcat
                                            "\\AcObjProp Object(%<\\_ObjIdx 0>%)."
                                            PropName
                                        )
                                    )
                                    '(90 . 0) ; Number of child fields
                                    '(97 . 1) ; Number of object ids
                                    (cons 331 (vlax-vla-object->ename LinkObj)) ; Object id
                                    [color=red]'(4 . "\\f %lu2%pr1%ct8[0.006944444444444444]") ; format string[/color]
                                    '(91 . 63) ; evaluation option
                                    '(92 . 0) ; filling option
                                    ;'(94 . 59) ; field state flag
                                    ;'(95 . 2) ; evaluation status
                                    ;'(96 . 0) ; evaluation error code
                                    ;'(300 . "") ; evaluation error message
                                    '(6 . "ObjectPropertyId")
                                    '(90 . 64)
                                    (cons 330 (vlax-vla-object->ename LinkObj))
                                    '(6 . "ObjectPropertyName") ; key string for the field data
                                    '(90 . 4) ; data type of field
                                    (cons 1 PropName) ; name of property
                                    '(7 . "ACAD_FIELD_VALUE") ; key string for the evaluated cache
                                    (cons
                                        90 ;data type of field
                                        (cond
                                            ((equal PropType 'STR)
                                                4
                                            )
                                            ((equal PropType 'INT)
                                                1
                                            )
                                            ((equal PropType 'REAL)
                                                2
                                            )
                                            ((equal PropType 'LIST)
                                                32
                                            )
                                        )
                                    )
                                    (cond ; field value
                                        ((equal PropType 'STR)
                                            (cons 1 PropValue)
                                        )
                                        ((equal PropType 'INT)
                                            (cons 91 PropValue)
                                        )
                                        ((equal PropType 'REAL)
                                            (cons 140 PropValue)
                                        )
                                        ((equal PropType 'LIST)
                                            (cons 11 Propvalue)
                                        )
                                    )
                                    '(301 . "") ; format string
                                    [color=red]'(98 . 34) ; length of format string[/color]
                                )
                            )
                        )
                        '(97 . 0) ; Number of object IDs used in the field code
                        '(4 . "") ; Format string
                        '(91 . 63) ; Evaluation option
                            ;kDisable 0 Disable evaluation.
                            ;kOnOpen (0x1 << 0) Evaluate during drawing load.
                            ;kOnSave (0x1 << 1) Evaluate during drawing save.
                            ;kOnPlot (0x1 << 2) Evaluate during drawing plot.
                            ;kOnEtransmit (0x1 << 3) Evaluate during eTransmit.
                            ;kOnRegen (0x1 << 4) Evaluate during regen.
                            ;kOnDemand (0x1 << 5) Evaluate only on demand by the user or the API.
                            ;kAutomatic (kOnOpen | kOnSave | kOnPlot | kOnEtransmit | kOnRegen | kOnDemand) Automatically evaluate fields during all the operations.
                        '(92 . 0) ;Filling option
                            ;kSkipFilingResult (0x1 << 0) Do not file out the cached evaluation result with the field.
                        ;'(94 . 5) ;Field state flag
                            ;kInitialized (0x1 << 0) Field is not yet intitalized with any field code or data.
                            ;kCompiled (0x1 << 1) Field has been compiled.
                            ;kModified (0x1 << 2) Field has been modified and not yet evaluated.
                            ;kEvaluated (0x1 << 3) Field has been evaluated. Use evaluationStatus() to get the evaluation status.
                            ;kHasCache (0x1 << 4) The field has a cache of the evaluated result.
                            ;'(95 . 1) ;Evaluation status
                            ;kNotYetEvaluated (0x1 << 0) Field is not yet evaluated.
                            ;kSuccess (0x1 << 1) Field is evaluated successfully.
                            ;kEvaluatorNotFound (0x1 << 2) Evaluator was not found.
                            ;kSyntaxError (0x1 << 3) Syntax error in the field expression.
                            ;kInvalidCode (0x1 << 4) Invalid field code or expression.
                            ;kInvalidContext (0x1 << 5) Current context is invalid for evaluating the field.
                            ;kOtherError (0x1 << 6) Evaluation has failed.
                        ;'(96 . 0) ;Evaluation error code
                        ;'(300 . "") ;Evaluation error message
                        '(93 . 1) ;Number of the data set in the field
                        '(6 . "ACFD_FIELDTEXT_CHECKSUM") ;Key string for field data
                        '(90 . 2) ;Data type of field value
                        '(140 . 33.0) ;Double value
                        '(7 . "ACFD_FIELD_VALUE") ;Key string from the evaluated cache, hard coded as is shown here
                        '(90 . 0) ;Data type of field value
                        '(91 . 0) ;Long value
                        '(301 . "") ; format string
                        [color=red]'(98 . 34) ; format string length[/color]
                    )
                )
            )
            (entupd AddToEname)
        )
    )
)
Title: Re: Entmaking fields w/Formatting
Post by: mkweaver on June 03, 2008, 12:29:09 PM
Strange.  The field is still displayed to six decimal places, but if I edit the field, the formatting is set and previews correctly (less the conversion factor).

 
Title: Re: Entmaking fields w/Formatting
Post by: T.Willey on June 03, 2008, 12:42:39 PM
When I select it, it only shows one decimal place.  My string looks like

\f 214.9
Title: Re: Entmaking fields w/Formatting
Post by: mkweaver on June 03, 2008, 01:10:54 PM
See the attached screenshot.

Thanks for the help,
Mike
Title: Re: Entmaking fields w/Formatting
Post by: T.Willey on June 03, 2008, 01:21:27 PM
Can you post a sample drawing that this is happening in?  I have tried it in two different drawings, and both have worked as described.  Maybe there is some settings that are different in the drawings you are using, and the ones I am.  I don't know if this matters, but I'm on '06 Electrical.
Title: Re: Entmaking fields w/Formatting
Post by: T.Willey on June 03, 2008, 01:43:20 PM
If your using '08, try this one.

Code: [Select]
(defun AddObjectField (AddToEname LinkObj PropName / EntData ExDict FDict PropType PropValue)
    (if
        (and
            (setq EntData (entget AddToEname))
            (vl-position (value 0 EntData) '("MTEXT" "ATTRIB" "ATTDEF"))
            (setq ExDict
                (vlax-vla-object->ename
                    (vla-GetExtensionDictionary
                        (vlax-ename->vla-object AddToEname)
                    )
                )
            )
            (setq PropType
                (type
                    (setq PropValue
                        (vlax-get LinkObj PropName)
                    )
                )
            )
        )
        (progn
            (dictremove ExDict "ACAD_FIELD")
            (setq FDict
                (dictadd ExDict "ACAD_FIELD"
                    (entmakex
                        '(
                            (0 . "DICTIONARY")
                            (100 . "AcDbDictionary")
                            (280 . 1)
                            (281 . 1)
                        )
                    )
                )
            )
            (dictadd FDict "TEXT"
                (entmakex
                    (list
                        '(0 . "FIELD")
                        '(100 . "AcDbField")
                        '(1 . "_text")
                        '(2 . "%<\\_FldIdx 0>%")
                        '(90 . 1) ;Number of child fields
                        (cons 360 ;Child field ID
                            (entmakex
                                (list
                                    '(0 . "FIELD")
                                    '(100 . "AcDbField")
                                    '(1 . "AcObjProp") ; Field type
                                    (cons
                                        2
                                        (strcat
                                            "\\AcObjProp Object(%<\\_ObjIdx 0>%)."
                                            PropName
                                        )
                                    )
                                    '(90 . 0) ; Number of child fields
                                    '(97 . 1) ; Number of object ids
                                    (cons 331 (vlax-vla-object->ename LinkObj)) ; Object id
                                    '(4 . "\\f %lu2%pr1%ct8[0.006944444444444444]") ; format string
                                    '(91 . 63) ; evaluation option
                                    '(92 . 0) ; filling option
                                    ;'(94 . 59) ; field state flag
                                    ;'(95 . 2) ; evaluation status
                                    ;'(96 . 0) ; evaluation error code
                                    ;'(300 . "") ; evaluation error message
                                    '(6 . "ObjectPropertyId")
                                    '(90 . 64)
                                    (cons 330 (vlax-vla-object->ename LinkObj))
                                    '(6 . "ObjectPropertyName") ; key string for the field data
                                    '(90 . 4) ; data type of field
                                    (cons 1 PropName) ; name of property
                                    '(7 . "ACAD_FIELD_VALUE") ; key string for the evaluated cache
                                    (cons
                                        90 ;data type of field
                                        (cond
                                            ((equal PropType 'STR)
                                                4
                                            )
                                            ((equal PropType 'INT)
                                                1
                                            )
                                            ((equal PropType 'REAL)
                                                2
                                            )
                                            ((equal PropType 'LIST)
                                                32
                                            )
                                        )
                                    )
                                    (cond ; field value
                                        ((equal PropType 'STR)
                                            (cons 1 PropValue)
                                        )
                                        ((equal PropType 'INT)
                                            (cons 91 PropValue)
                                        )
                                        ((equal PropType 'REAL)
                                            (cons 140 PropValue)
                                        )
                                        ((equal PropType 'LIST)
                                            (cons 11 Propvalue)
                                        )
                                    )
                                    [color=red]'(300 . "\\f %lu2%pr1%ct8[0.006944444444444444]") ; format string[/color]
                                    '(301 . "") ; format string
                                    '(98 . 34) ; length of format string
                                )
                            )
                        )
                        '(97 . 0) ; Number of object IDs used in the field code
                        '(4 . "\\f %lu2%pr1%ct8[0.006944444444444444]") ; Format string
                        '(91 . 63) ; Evaluation option
                            ;kDisable 0 Disable evaluation.
                            ;kOnOpen (0x1 << 0) Evaluate during drawing load.
                            ;kOnSave (0x1 << 1) Evaluate during drawing save.
                            ;kOnPlot (0x1 << 2) Evaluate during drawing plot.
                            ;kOnEtransmit (0x1 << 3) Evaluate during eTransmit.
                            ;kOnRegen (0x1 << 4) Evaluate during regen.
                            ;kOnDemand (0x1 << 5) Evaluate only on demand by the user or the API.
                            ;kAutomatic (kOnOpen | kOnSave | kOnPlot | kOnEtransmit | kOnRegen | kOnDemand) Automatically evaluate fields during all the operations.
                        '(92 . 0) ;Filling option
                            ;kSkipFilingResult (0x1 << 0) Do not file out the cached evaluation result with the field.
                        ;'(94 . 5) ;Field state flag
                            ;kInitialized (0x1 << 0) Field is not yet intitalized with any field code or data.
                            ;kCompiled (0x1 << 1) Field has been compiled.
                            ;kModified (0x1 << 2) Field has been modified and not yet evaluated.
                            ;kEvaluated (0x1 << 3) Field has been evaluated. Use evaluationStatus() to get the evaluation status.
                            ;kHasCache (0x1 << 4) The field has a cache of the evaluated result.
                            ;'(95 . 1) ;Evaluation status
                            ;kNotYetEvaluated (0x1 << 0) Field is not yet evaluated.
                            ;kSuccess (0x1 << 1) Field is evaluated successfully.
                            ;kEvaluatorNotFound (0x1 << 2) Evaluator was not found.
                            ;kSyntaxError (0x1 << 3) Syntax error in the field expression.
                            ;kInvalidCode (0x1 << 4) Invalid field code or expression.
                            ;kInvalidContext (0x1 << 5) Current context is invalid for evaluating the field.
                            ;kOtherError (0x1 << 6) Evaluation has failed.
                        ;'(96 . 0) ;Evaluation error code
                        ;'(300 . "") ;Evaluation error message
                        '(93 . 1) ;Number of the data set in the field
                        '(6 . "ACFD_FIELDTEXT_CHECKSUM") ;Key string for field data
                        '(90 . 2) ;Data type of field value
                        '(140 . 33.0) ;Double value
                        '(7 . "ACFD_FIELD_VALUE") ;Key string from the evaluated cache, hard coded as is shown here
                        '(90 . 0) ;Data type of field value
                        '(91 . 0) ;Long value
                        '(301 . "") ; format string
                        '(98 . 34) ; format string length
                    )
                )
            )
            (entupd AddToEname)
        )
    )
)
Title: Re: Entmaking fields w/Formatting
Post by: mkweaver on June 03, 2008, 04:13:12 PM
We (you're  :-) ) getting so close.  Now I'm getting the precision, but I've also got a preceding "f ", and still no conversion factor.

I've attached a drawing that has three mtext objects, two with fields created by your code, and one with a field created manually.

Thanks for you help.

Mike
Title: Re: Entmaking fields w/Formatting
Post by: T.Willey on June 03, 2008, 06:40:51 PM
I see if I have time tomorrow to investigate more, but now *real* work calls.
Title: Re: Entmaking fields w/Formatting
Post by: T.Willey on June 10, 2008, 05:04:04 PM
Did you get this to work Mike?  If not, maybe a picture of what you are seeing, and what you want because when I open them on my comp they both look the same except for the 'f' but that is an easy fix.
Title: Re: Entmaking fields w/Formatting
Post by: Joe Burke on October 09, 2009, 08:28:01 AM
Hi Tim,

Your code may help me solve a problem I've been working on.

Maybe I'm thick, but I don't understand the arguments passed to the function.

(defun AddObjectField (AddToEname LinkObj PropName / ...)

Please explain each one in detail.

Thanks  :-)
Title: Re: Entmaking fields w/Formatting
Post by: T.Willey on October 09, 2009, 11:33:25 AM
Hi Tim,

Your code may help me solve a problem I've been working on.

Maybe I'm thick, but I don't understand the arguments passed to the function.

(defun AddObjectField (AddToEname LinkObj PropName / ...)

Please explain each one in detail.

Thanks  :-)

No problem Joe.

AddToEname - is the ename of the object you want to add the field to.

LinkObj - is a vla object that has the property ( which will be the argument PropName ) which you want to be associated with the field that will be added to the argument AddToEname.

PropName - is the name of the property of the LinkObj argument that you want represented in the field added to AddToEname.

So if you have a mtext item ( ent ) and a polyline object ( obj ) and you want the mtext to show the area property, then you would call the program like

(AddObjectField ent obj "Area")
Title: Re: Entmaking fields w/Formatting
Post by: Joe Burke on October 10, 2009, 05:06:29 AM
Thanks, Tim. This may be helpful.
Title: Re: Entmaking fields w/Formatting
Post by: Joe Burke on October 10, 2009, 09:49:12 AM
Hi Tim,

Have you tried your code given the example you mentioned?

Command: (AddObjectField e o "Area")
; error: bad DXF group: (1 . 21365.2)

Given "e" is the ename of an mtext object and "o" is a vla-object lwpline.

Command: (cdr (assoc 0 (entget e)))
"MTEXT"

Command: !o
#<VLA-OBJECT IAcadLWPolyline 07ffef04>

I added this function too.
(defun VALUE (num ent /)
  (cdr (assoc num ent))
)

Note, this value 21365.2 is the area property of the lwpline.
Title: Re: Entmaking fields w/Formatting
Post by: Joe Burke on October 12, 2009, 07:41:10 AM
Tim,

Your code was a useful example, regardless of fact it didn't work for me in terms of what it was designed to do.

Thanks
Title: Re: Entmaking fields w/Formatting
Post by: T.Willey on October 12, 2009, 11:09:34 AM
Joe,

  I did try it again to make sure with that same example, and it worked here.  I'm not sure if that is the most current code, as I don't use fields, so once I did it I never used it.  :-D  Here is the one from my library in case it is different.  Glad it was helpful, but I hope it will work for you.

Code: [Select]
(defun AddObjectField (AddToEname LinkObj PropName / EntData ExDict FDict PropType PropValue)
    (if
        (and
            (setq EntData (entget AddToEname))
            (vl-position (value 0 EntData) '("MTEXT" "ATTRIB" "ATTDEF"))
            (setq ExDict
                (vlax-vla-object->ename
                    (vla-GetExtensionDictionary
                        (vlax-ename->vla-object AddToEname)
                    )
                )
            )
            (setq PropType
                (type
                    (setq PropValue
                        (vlax-get LinkObj PropName)
                    )
                )
            )
        )
        (progn
            (dictremove ExDict "ACAD_FIELD")
            (setq FDict
                (dictadd ExDict "ACAD_FIELD"
                    (entmakex
                        '(
                            (0 . "DICTIONARY")
                            (100 . "AcDbDictionary")
                            (280 . 1)
                            (281 . 1)
                        )
                    )
                )
            )
            (dictadd FDict "TEXT"
                (entmakex
                    (list
                        '(0 . "FIELD")
                        '(100 . "AcDbField")
                        '(1 . "_text")
                        '(2 . "%<\\_FldIdx 0>%")
                        '(90 . 1) ;Number of child fields
                        (cons 360 ;Child field ID
                            (entmakex
                                (list
                                    '(0 . "FIELD")
                                    '(100 . "AcDbField")
                                    '(1 . "AcObjProp") ; Field type
                                    (cons
                                        2
                                        (strcat
                                            "\\AcObjProp Object(%<\\_ObjIdx 0>%)."
                                            PropName
                                        )
                                    )
                                    '(90 . 0) ; Number of child fields
                                    '(97 . 1) ; Number of object ids
                                    (cons 331 (vlax-vla-object->ename LinkObj)) ; Object id
                                    '(4 . "") ; format string
                                    '(91 . 63) ; evaluation option
                                    '(92 . 0) ; filling option
                                    ;'(94 . 59) ; field state flag
                                    ;'(95 . 2) ; evaluation status
                                    ;'(96 . 0) ; evaluation error code
                                    ;'(300 . "") ; evaluation error message
                                    '(6 . "ObjectPropertyId")
                                    '(90 . 64)
                                    (cons 330 (vlax-vla-object->ename LinkObj))
                                    '(6 . "ObjectPropertyName") ; key string for the field data
                                    '(90 . 4) ; data type of field
                                    (cons 1 PropName) ; name of property
                                    '(7 . "ACAD_FIELD_VALUE") ; key string for the evaluated cache
                                    (cons
                                        90 ;data type of field
                                        (cond
                                            ((equal PropType 'STR)
                                                4
                                            )
                                            ((equal PropType 'INT)
                                                1
                                            )
                                            ((equal PropType 'REAL)
                                                2
                                            )
                                            ((equal PropType 'LIST)
                                                32
                                            )
                                        )
                                    )
                                    (cond ; field value
                                        ((equal PropType 'STR)
                                            (cons 1 PropValue)
                                        )
                                        ((equal PropType 'INT)
                                            (cons 91 PropValue)
                                        )
                                        ((equal PropType 'REAL)
                                            (cons 140 PropValue)
                                        )
                                        ((equal PropType 'LIST)
                                            (cons 11 Propvalue)
                                        )
                                    )
                                    '(300 . "") ; format string for '08
                                    '(301 . "") ; format string
                                    '(98 . 0) ; length of format string
                                )
                            )
                        )
                        '(97 . 0) ; Number of object IDs used in the field code
                        '(4 . "") ; Format string
                        '(91 . 63) ; Evaluation option
                            ;kDisable 0 Disable evaluation.
                            ;kOnOpen (0x1 << 0) Evaluate during drawing load.
                            ;kOnSave (0x1 << 1) Evaluate during drawing save.
                            ;kOnPlot (0x1 << 2) Evaluate during drawing plot.
                            ;kOnEtransmit (0x1 << 3) Evaluate during eTransmit.
                            ;kOnRegen (0x1 << 4) Evaluate during regen.
                            ;kOnDemand (0x1 << 5) Evaluate only on demand by the user or the API.
                            ;kAutomatic (kOnOpen | kOnSave | kOnPlot | kOnEtransmit | kOnRegen | kOnDemand) Automatically evaluate fields during all the operations.
                        '(92 . 0) ;Filling option
                            ;kSkipFilingResult (0x1 << 0) Do not file out the cached evaluation result with the field.
                        ;'(94 . 5) ;Field state flag
                            ;kInitialized (0x1 << 0) Field is not yet intitalized with any field code or data.
                            ;kCompiled (0x1 << 1) Field has been compiled.
                            ;kModified (0x1 << 2) Field has been modified and not yet evaluated.
                            ;kEvaluated (0x1 << 3) Field has been evaluated. Use evaluationStatus() to get the evaluation status.
                            ;kHasCache (0x1 << 4) The field has a cache of the evaluated result.
                            ;'(95 . 1) ;Evaluation status
                            ;kNotYetEvaluated (0x1 << 0) Field is not yet evaluated.
                            ;kSuccess (0x1 << 1) Field is evaluated successfully.
                            ;kEvaluatorNotFound (0x1 << 2) Evaluator was not found.
                            ;kSyntaxError (0x1 << 3) Syntax error in the field expression.
                            ;kInvalidCode (0x1 << 4) Invalid field code or expression.
                            ;kInvalidContext (0x1 << 5) Current context is invalid for evaluating the field.
                            ;kOtherError (0x1 << 6) Evaluation has failed.
                        ;'(96 . 0) ;Evaluation error code
                        ;'(300 . "") ;Evaluation error message
                        '(93 . 1) ;Number of the data set in the field
                        '(6 . "ACFD_FIELDTEXT_CHECKSUM") ;Key string for field data
                        '(90 . 2) ;Data type of field value
                        '(140 . 33.0) ;Double value
                        '(7 . "ACFD_FIELD_VALUE") ;Key string from the evaluated cache, hard coded as is shown here
                        '(90 . 0) ;Data type of field value
                        '(91 . 0) ;Long value
                        '(301 . "") ; format string
                        '(98 . 0) ; format string length
                    )
                )
            )
            (entupd AddToEname)
        )
    )
)

Quote
Command: (addobjectfield (car (entsel "\n Select mtext: ")) (vlax-ename->vla-object (car (entsel "\n Select polyline: "))) "Area")

 Select mtext:
 Select polyline: <Entity name: 7ed2e040>
Title: Re: Entmaking fields w/Formatting
Post by: Joe Burke on October 13, 2009, 06:13:39 AM
Hi Tim,

I must have been using an older version before. Your recent post works as expected. I tested with both "Area" and "Length" properties.

What I'm working on is an updated version of my SwapText routine which supports swap fields from source to target object. I found the only reliable way to do it, allowing for all field types, is to essentially transfer the source field dictionary to target. So your example was very helpful.

Thanks again.