Author Topic: Entmaking fields w/Formatting  (Read 5425 times)

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Entmaking fields w/Formatting
« Reply #15 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>
Tim

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

Please think about donating if this post helped you.

Joe Burke

  • Guest
Re: Entmaking fields w/Formatting
« Reply #16 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.