Announcements

Community notifications may experience intermittent interruptions between 10–12 November during scheduled maintenance. We appreciate your patience.

Limit Field Options and Format

Limit Field Options and Format

rafaelricardorj
Contributor Contributor
570 Views
4 Replies
Message 1 of 5

Limit Field Options and Format

rafaelricardorj
Contributor
Contributor

I'm trying to create a multileader that displays a polyline length in a field (in order to prevent the user of typing it). I created the multiline and placed the field but always when I double click the field (to change the object reference), it displays again the Field Options Menu, and when I select a new object the field loses the previous Property selected and the Additional format configuration (Prefix and Sufix).

+ When I try to use the same multileader in a different drawing it loses all the fields presets. 
Is it possible to have a field/lisp or block that automaticaly takes only the polyline length even when you change the reference/drawing without losing its presets?

0 Likes
571 Views
4 Replies
Replies (4)
Message 2 of 5

rkmcswain
Mentor
Mentor
We have something similar, and we use autolisp code to populate the field data. Takes the options away from the user so that the object reference is correct.
R.K. McSwain     | CADpanacea | on twitter
0 Likes
Message 3 of 5

rafaelricardorj
Contributor
Contributor

it's exactly what I need, could you help me with that?

0 Likes
Message 4 of 5

rkmcswain
Mentor
Mentor
Take a look at this:
http://www.lee-mac.com/quickfield.html

R.K. McSwain     | CADpanacea | on twitter
0 Likes
Message 5 of 5

rafaelricardorj
Contributor
Contributor

The code is great, I already changed the prefix and sufix of the field but I don't know how to change the properties (layer, color, TextStyle) of the resultant field inside this code and how to do it all inside a multileader or block, could you help me?

 

(defun c:test2 ( ) (LM:QuickField "Length" "%lu2%pr2%ps[C= ,m]" 3))
(defun LM:quickfield ( prop format mode / ent ins obj str )  
    (if (setq str (LM:quickfield:constructfieldstring prop format))
        (cond
            (   (= 1 mode)
                (if (setq ent (LM:quickfield:selectifhasprop "Textstring" nentsel))
                    (progn
                        (setq obj (vlax-ename->vla-object ent))
                        (vla-put-textstring obj "") ;; To clear any existing field
                        (vla-put-textstring obj str)
                        (if (= "ATTRIB" (cdr (assoc 0 (entget ent))))
                            (vl-cmdf "_.updatefield" ent "")
                        )
                    )
                )
            )
            (   (= 2 mode)
                (if (setq ins (getpoint "\nSpecify point for text: "))
                    (vla-addtext
                        (vlax-get-property (LM:quickfield:acdoc)
                            (if (= 1 (getvar 'cvport))
                                'paperspace
                                'modelspace
                            )
                        )
                        str (vlax-3D-point (trans ins 1 0)) (getvar 'textsize)
                    )
                )
            )
            (   (= 3 mode)
                (if (setq ins (getpoint "\nSpecify point for mtext: "))
                    (vla-addmtext
                        (vlax-get-property (LM:quickfield:acdoc)
                            (if (= 1 (getvar 'cvport))
                                'paperspace
                                'modelspace
                            )
                        )
                        (vlax-3D-point (trans ins 1 0)) 0.0 str
                    )
                )
            )
        )
    )
    (princ)
)

(defun LM:quickfield:selectifhasprop ( prop func / ent )
    (while
        (progn
            (setvar 'errno 0)
            (setq ent (car (func (strcat "\nSelect object with " prop " property: "))))
            (cond
                (   (= 7 (getvar 'errno))
                    (princ "\nMissed, try again.")
                )
                (   (null ent)
                    nil
                )
                (   (not (vlax-property-available-p (vlax-ename->vla-object ent) prop))
                    (princ (strcat "\nSelected object does not have " prop " property."))
                )
            )
        )
    )
    ent
)

(defun LM:quickfield:acdoc nil
    (eval (list 'defun 'LM:quickfield:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object))))
    (LM:quickfield:acdoc)
)

(   (lambda nil (vl-load-com)
        (eval
            (list 'defun 'LM:quickfield:constructfieldstring '( prop format / ent )
                (list 'if '(setq ent (LM:quickfield:selectifhasprop prop entsel))
                    (list 'strcat "%<\\AcObjProp Object(%<\\_ObjId "
                        (if (vlax-method-applicable-p    (vla-get-utility (LM:quickfield:acdoc)) 'getobjectidstring)
                            (list 'vla-getobjectidstring (vla-get-utility (LM:quickfield:acdoc)) '(vlax-ename->vla-object ent) ':vlax-false)
                           '(itoa (vla-get-objectid (vlax-ename->vla-object ent)))
                        )
                        ">%)." 'prop '(if (/= "" format) (strcat " \\f \"" format "\">%") ">%")
                    )
                )
            )
        )
    )
)
(princ)

 

0 Likes