Author Topic: EntMake'ing fields (need help)  (Read 9747 times)

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5251
EntMake'ing fields (need help)
« on: December 10, 2007, 01:48:33 PM »
I thought it might be fun, and a good learning experience, to figure out how to create a field though lisp.  I was not able to figure it out using ActiveX, so I went the Lisp route with dxf codes.  It seems to want to create it, but it will freeze Acad.  I have not use entmake with dictionaries, so I'm looking for any advice.  Here is the code.

Thanks in advance.

Code: [Select]
(progn
(setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(setq ActLo (vla-get-ActiveLayout ActDoc))
(if
(and
(setq Sel (nentsel "\n Select object to change field value: "))
(setq EntData (entget (car Sel)))
(vl-position (value 0 EntData) '("MTEXT" "ATTRIB" "ATTDEF"))
(setq ExDict
(vlax-vla-object->ename
(vla-GetExtensionDictionary
(vlax-ename->vla-object (car Sel))
)
)
)
)
(progn
(setq FDict
(if (setq FDictData (dictsearch ExDict "ACAD_FIELD"))
(value -1 FDict)
(dictadd ExDict "ACAD_FIELD"
(entmakex
'(
(0 . "DICTIONARY")
(100 . "AcDbDictionary")
(280 . 1)
(281 . 1)
)
)
)
)
)
(setq FEnt
(if (setq FEnt (dictsearch FDict "TEXT"))
(value -1 FEnt)
(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")
'(2 . "\\AcObjProp Object(%<\\_ObjIdx 0>%).Name")
'(90 . 0)
'(97 . 1)
(cons 331 (vlax-vla-object->ename ActLo))
'(4 . "")
'(91 . 63)
'(92 . 0)
'(94 . 59)
'(95 . 2)
'(96 . 0)
'(300 . "")
'(6 . "ObjectPropertyName")
'(90 . 4)
'(1 . "Name")
'(7 . "ACAD_FIELD_VALUE")
'(90 . 4)
(cons 1 (vla-get-Name ActLo))
(cons 301 (vla-get-Name ActLo))
'(98 . 7)
)
)
)
'(97 . 0) ; Number of object IDs used in the field code
'(4 . "") ; Format string
'(91 . 63) ; Evaluation option
'(92 . 0) ;Filling option
'(94 . 5) ;Field state flag
'(95 . 1) ;Evaluation status
'(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
'(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 . "")
'(98 . 0)
)
)
)
)
)
)
)
)
Tim

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

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: EntMake'ing fields (need help)
« Reply #1 on: December 10, 2007, 03:59:12 PM »
This is working.  I took out some code that i felt didn't need to be there, and I looked in the ObjectArx docs to find out what some of the codes meant.  Now to make it better   :evil:  as it will only work on objects that don't have a field associated with it.

Code: [Select]
(progn
(setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(setq ActLo (vla-get-ActiveLayout ActDoc))
(if
(and
(setq Sel (nentsel "\n Select object to change field value: "))
(setq EntData (entget (car Sel)))
(vl-position (value 0 EntData) '("MTEXT" "ATTRIB" "ATTDEF"))
(setq ExDict
(vlax-vla-object->ename
(vla-GetExtensionDictionary
(vlax-ename->vla-object (car Sel))
)
)
)
)
(progn
(setq FDict
(if (setq FDictData (dictsearch ExDict "ACAD_FIELD"))
(value -1 FDict)
(dictadd ExDict "ACAD_FIELD"
(entmakex
'(
(0 . "DICTIONARY")
(100 . "AcDbDictionary")
(280 . 1)
(281 . 1)
)
)
)
)
)
(setq FEnt
(if (setq FEnt (dictsearch FDict "TEXT"))
(value -1 FEnt)
(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
'(2 . "\\AcObjProp Object(%<\\_ObjIdx 0>%).Name")
'(90 . 0) ; Number of child fields
'(97 . 1) ; Number of object ids
(cons 331 (vlax-vla-object->ename ActLo)) ; 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 . "ObjectPropertyName") ; key string for the field data
'(90 . 4) ; data type of field
'(1 . "Name") ; name of property
'(7 . "ACAD_FIELD_VALUE") ; key string for the evaluated cache
'(90 . 4) ; data type of field
(cons 1 (vla-get-Name ActLo)) ; field value
'(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
)
)
)
)
)
)
)
)
Tim

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

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: EntMake'ing fields (need help)
« Reply #2 on: December 10, 2007, 06:06:43 PM »
Here is something I'm happy with right now.  It is a sub that will add a field to an item that has an existing field or not.  It will let you add any property that will return a string.  I'm pretty sure it will link to any object that can be converted to an ename.  Like a document won't work since you can't convert it to an ename, but a layout can be converted, so you can link to it.

Hope you like.  Any comments/ideas welcomed.

Code: [Select]
(defun AddObjectField (AddToEname LinkObj PropName / EntData ExDict FDict)
(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)
)
)
)
)
(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 . "ObjectPropertyName") ; key string for the field data
'(90 . 4) ; data type of field
'(1 . "Name") ; name of property
'(7 . "ACAD_FIELD_VALUE") ; key string for the evaluated cache
'(90 . 4) ; data type of field
(cons 1 (vlax-get LinkObj PropName)) ; field value
'(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)
)
)
)
Tim

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

Please think about donating if this post helped you.

JohnK

  • Administrator
  • Seagull
  • Posts: 10604
Re: EntMake'ing fields (need help)
« Reply #3 on: December 10, 2007, 08:20:18 PM »
This looks like a great thread T.Willey. Let me see if i cant give this some thought in the morn.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

T.Willey

  • Needs a day job
  • Posts: 5251
Re: EntMake'ing fields (need help)
« Reply #4 on: December 11, 2007, 11:18:36 AM »
This looks like a great thread T.Willey. Let me see if i cant give this some thought in the morn.
Thanks Se7en.  I will continue to see what else I can learn with this.  I want to be able to link any property, which means I have to study what is different between the types (list, integer, real ....).
Tim

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

Please think about donating if this post helped you.

JohnK

  • Administrator
  • Seagull
  • Posts: 10604
Re: EntMake'ing fields (need help)
« Reply #5 on: December 11, 2007, 11:47:17 AM »
No problem; I'll help as much as i can.

First look:
Code: [Select]
(vl-position (value 0 EntData) '("MTEXT" "ATTRIB" "ATTDEF"))
I dont have a `value' function so i cant run this.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

T.Willey

  • Needs a day job
  • Posts: 5251
Re: EntMake'ing fields (need help)
« Reply #6 on: December 11, 2007, 11:52:43 AM »
No problem; I'll help as much as i can.

First look:
Code: [Select]
(vl-position (value 0 EntData) '("MTEXT" "ATTRIB" "ATTDEF"))
I dont have a `value' function so i cant run this.


Dang!  Thought I didn't use one of the subs.  Guess I wasn't sure if I was going to post the code.  :wink:
Here you go.
Code: [Select]
(defun VALUE (num ent /)
(cdr (assoc num ent))
)
Tim

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

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: EntMake'ing fields (need help)
« Reply #7 on: December 11, 2007, 02:17:14 PM »
Here is the next version.  It will now support Integers, Reals, Lists and Strings.  It looks like fields can support more items, but I don't know which properties to test for them.  No formatting though, but I think that isn't too hard from what I see, but you will have to know what is allowed.  You will need the code above, that I forgot to post first.  I will highlight where the changes are in the code.

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
[color=red](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]
'(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)
)
)
)
Tim

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

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: EntMake'ing fields (need help)
« Reply #8 on: February 09, 2011, 05:55:52 PM »
Here is a new update.  It will allow you to pass a list of objects and properties to create a single field associated with an existing valid text ( based ) entity.  It will separate each value with a space ( can be changed if desired ).

Code: [Select]
(defun AddObjectField (AddToEname objPropList / EntData ExDict FDict cnt str len )
   
    ; AddToEname = value ename that the field(s) will be added to.
    ; objPropList = list of lists, that have a valid vla object and property,
    ;   ie: ((#<VLA-OBJECT IAcadText 0ee928cc> . "TextString") (#<VLA-OBJECT IAcadText 0ee92764> . "TextString"))
   
    (if
        (and
            (setq EntData (entget AddToEname))
            (vl-position (value 0 EntData) '("TEXT" "MTEXT" "ATTRIB" "ATTDEF"))
            (setq ExDict
                (vlax-vla-object->ename
                    (vla-GetExtensionDictionary
                        (vlax-ename->vla-object AddToEname)
                    )
                )
            )
            (setq cnt -1)
            (setq str "")
            (setq len (length objPropList))
        )
        (progn
            (dictremove ExDict "ACAD_FIELD")
            (setq FDict
                (dictadd ExDict "ACAD_FIELD"
                    (entmakex
                        '(
                            (0 . "DICTIONARY")
                            (100 . "AcDbDictionary")
                            (280 . 1)
                            (281 . 1)
                        )
                    )
                )
            )
            (dictadd FDict "TEXT"
                (entmakex
                    (append
                        (list
                            '(0 . "FIELD")
                            '(100 . "AcDbField")
                            '(1 . "_text")
                            (cons 2 (repeat len (setq str (strcat str "%<\\_FldIdx " (itoa (setq cnt (1+ cnt))) ">%" (if (equal (1+ cnt) len) "" " ")))))
                            ;'(2 . "%<\\_FldIdx 0>%")
                            (cons 90 (length objPropList)) ;Number of child fields
                        )
                        (mapcar
                            (function
                                (lambda ( x / LinkObj PropName PropType PropValue )
                                    (setq LinkObj (car x))
                                    (setq PropName (cdr x))
                                    (setq PropType
                                        (type
                                            (setq PropValue
                                                (vlax-get LinkObj PropName)
                                            )
                                        )
                                    )
                                    (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
                                            )
                                        )
                                    )
                                )
                            )
                            objPropList
                        )
                        (list
                            '(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)
        )
    )
)

Example
Code: [Select]
(
    (lambda ( a b )
        (AddObjectField a (list (cons b "ObjectName") (cons b "Layer")))
    )
    (car (nentsel "\n Select entity to assign field to: "))
    (vlax-ename->vla-object (car (nentsel)))
)
Tim

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

Please think about donating if this post helped you.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: EntMake'ing fields (need help)
« Reply #9 on: February 09, 2011, 09:05:05 PM »
This is incredible Tim!
I can't wait to check it out on Monday - can't believe I never saw this.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox