Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Customizing Field Expressions

7 REPLIES 7
Reply
Message 1 of 8
Anonymous
6128 Views, 7 Replies

Customizing Field Expressions

I have created a dynamic scale bar that is linked to my viewport and will update automatically whenever I change the scale of my drawing. But, I'm having an issue with customizing the field expression. Below is the expression I'm using in my mtext to display my scale (i.e. 1:50 scale will display 50 with this expression below). What I'm wanting to do is try and divide this number in half so my scale bar will display a 50 and a 25 for the 1" and 1/2" scales. Can anyone help me figure out how I can customize this expression so it will display half the current viewport scale?

%<\AcObjProp Object(%<\_ObjId 2125536032>%).CustomScale \f "%lu2%ct1%qf28161">%


**If you want to try this expression in your own drawing, you can replace my ObjId by typing 'field' into the command line and selecting Object in the Field Names. Then select your viewport and your id will be displayed in the formula at the bottom of the Field dialog box.
7 REPLIES 7
Message 2 of 8
Anonymous
in reply to: Anonymous

you could
is the field expression in an attribute tag??
if it is get the value of the attribute value aka field expression
divide it by 2 then put it in another attribute to display the information...
Message 3 of 8
Anonymous
in reply to: Anonymous

(defun C:CHATT ( / ss x blk att atts blockname tagname NewValue blkname elist oldval newval); Change Attribute Tag..
(vl-load-com)
(setq ss nil)
;;;**************FROM BLOCK ATTRIBUTE
(setq tagname1 (getstring "\nGet which Attribute Tag from Block ?: "))

;get block information


(setq ss nil)
;; Case, you want to Pick Them..
(prompt "Pick Block to get source Field:")
(setq ss (ssget)); pick individual, Window, Crossing.. etc.
(if ss
(progn
(setq x 0)
(repeat (sslength ss)
(setq blk (vlax-ename->vla-object (ssname ss x)))
(setq elist (entget (ssname ss x)))
(setq blkname (cdr (assoc 2 elist)))
(progn
(if (safearray-value (setq atts (vlax-variant-value (vla-getattributes blk))))
(progn
(setq atts (vlax-safearray->list (vlax-variant-value (vla-getattributes blk))))
(foreach att atts
(setq tag (strcase (vla-get-tagstring att))); tagname
(if (= tagname1 tag)
;(princ (strcat "\nObjectID: "(rtos (vla-get-objectId att) 2 0)))
; (setq tagval_id (strcat (rtos (vla-get-objectId att) 2 0)))

;(setq tagstringval (strcase (vla-get-TextString att))); tagstring value
(setq OLDVAL (strcase (vla-get-TextString att)))
); if
); foreach
); progn
); if
); progn
(setq x (+ x 1))
); repeat length ss
); progn
); if

;;;**************TO BLOCK ATTRIBUTE****************
;; ask some questions and set some values to those questions
(setq tagname2 (getstring "\nInsert Into Which Attribute Tagname?: "))


;********modified lines below:*****************
(setq TRIM_VALUE 3);TRIM VALUE FOR THE PRIFIX
(setq NewVal (substr oldval TRIM_VALUE));;NEW VALUE TRIM 2 on PREFIX
(setq NEWVAL (atof NEWVAL));CONVERT TO NUMBER
(SETQ NEWVAL (/ NEWVAL 2.0));DIVIDE BY 2 AND INSERT THE BUGGER
;*modified lines above***********


(setq ss nil)
;; Case, you want to Pick Them..
(prompt "Pick Block to get source Field:")
(setq ss (ssget)); pick individual, Window, Crossing.. etc.
(if ss
(progn
(setq x 0)
(repeat (sslength ss)
(setq blk (vlax-ename->vla-object (ssname ss x)))
(setq elist (entget (ssname ss x)))
(setq blkname (cdr (assoc 2 elist)))
(progn
(if (safearray-value (setq atts (vlax-variant-value (vla-getattributes blk))))
(progn
(setq atts (vlax-safearray->list (vlax-variant-value (vla-getattributes blk))))
(foreach att atts
(setq tag (strcase (vla-get-tagstring att))); tagname
(if (= tagname2 tag)
;(princ (strcat "\nObjectID: "(rtos (vla-get-objectId att) 2 0)))
; (setq tagval_id (strcat (rtos (vla-get-objectId att) 2 0)))
(vla-put-textstring att newval)


); if
); foreach
); progn
); if
); progn
(setq x (+ x 1))
); repeat length ss
); progn
); if


(princ)
); function

Edited by: Msclout72 on Nov 6, 2009 8:09 AM

Edited by: Msclout72 on Nov 6, 2009 8:09 AM

Edited by: Msclout72 on Nov 6, 2009 8:10 AM

Edited by: Msclout72 on Nov 6, 2009 8:11 AM

Edited by: msclout72 on Nov 6, 2009 2:32 PM Edited by: msclout72 on Nov 6, 2009 2:34 PM
Message 4 of 8
Anonymous
in reply to: Anonymous

No, all I've done is copied the field expression and took the "1:" out of the formula and pasted the altered expression into an mtext field.
Message 5 of 8
Anonymous
in reply to: Anonymous

see the edited lisp
Message 6 of 8
H.vanZeeland
in reply to: Anonymous

Hi,
Try the formula, something like this
%<\AcExpr (0.5/
%<\AcObjProp Object(%<\_ObjId xxxxxxxxxx>%).CustomScale \f "%lu2%qf2816">%
) \f "%lu2%pr0">%

%<\AcExpr (1.0/
%<\AcObjProp Object(%<\_ObjId xxxxxxxxxx>%).CustomScale \f "%lu2%qf2816">%
) \f "%lu2%pr0">%

Cheers
Harrie Edited by: h.vanzeeland on Nov 7, 2009 10:14 AM
Message 7 of 8
vladimir.ninic
in reply to: Anonymous

yes! formula above works.

for me it looked like this:

%<\AcExpr (1000/ %<\AcObjProp Object(%<\_ObjId 2128517968>%).CustomScale \f "%lu2%qf2816">%) \f "%lu2%pr0">%


trick is to insert a FORMULA field so autocad can do math with viewport field values...

thnx!!!
Message 8 of 8
Anonymous
in reply to: Anonymous

Thanks Vanzeeland, it worked perfectly!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost