Author Topic: Select existing Field to modify its formula  (Read 2100 times)

0 Members and 1 Guest are viewing this topic.

GDF

  • Water Moccasin
  • Posts: 2081
Select existing Field to modify its formula
« on: April 14, 2018, 01:17:25 PM »
Is there a way to select an existing field and modify its formula?

The existing field is linked to the vport object. The existing formula needs to be changed to:
;;use scale name
;;%<\AcObjProp.16.2 Object(%<\_ObjId 516828608>%).CustomScale \f "%sn">%

Can this be done?

Gary
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 2081
Re: Select existing Field to modify its formula
« Reply #1 on: April 14, 2018, 02:28:53 PM »
I found this:
http://www.theswamp.org/index.php?topic=13445.msg162766#msg162766


I need help with the new part:

Code: [Select]
;;; VPort-Scale Lisp  11/09/2006  Ted Krush with a lot help from TheSwamp.org
;;; Adds the viewport scale factor to an existing textstring with use of a feild
;;;
(defun c:vpsc (/ ID)
  (princ)
  (vl-cmdf ".undo" "m")
  (vl-load-com)
  (setq ID (vla-get-objectid
     (vlax-ename->vla-object
       (car (entsel "\n Select Viewport Entity "))
     )
   )
  )

  (vla-put-TextString
    (vlax-ename->vla-object
      (car
(entsel "\n Select text entity to change: ")
      )
    )
    (strcat ""
    "%<\\AcObjProp Object(%<\\_ObjId "
    (itoa ID)
    ;;">%).CustomScale \\f \"%lu4%pr8%ct2%qf2816 = 1'-0\\\"\">%"
            ">%).CustomScale \\f \"%sn\">%"  ;;NEW
    )
  )
  (princ)
)

Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 2081
Re: Select existing Field to modify its formula
« Reply #2 on: April 14, 2018, 02:51:09 PM »
The routine will work except in one layout...see images...
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

Stefan

  • Bull Frog
  • Posts: 319
  • The most I miss IRL is the Undo button
Re: Select existing Field to modify its formula
« Reply #3 on: April 14, 2018, 08:13:51 PM »
Try this to change existing fields.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( / *error* e en ed fd vp)
  2.   (if
  3.     (and
  4.       (setq e  (car (entsel)))
  5.       (setq en (entget e))
  6.       (setq ed (cdadr (member '(102 . "{ACAD_XDICTIONARY") en)))
  7.       (setq fd (cdr (assoc -1 (dictsearch ed "ACAD_FIELD"))))
  8.       (setq vp
  9.         (cdr
  10.           (assoc 331
  11.             (entget
  12.               (cdr
  13.                 (assoc 360
  14.                   (dictsearch fd "TEXT")
  15.                 )
  16.               )
  17.             )
  18.           )
  19.         )
  20.       )
  21.       (eq (cdr (assoc 0 (entget vp))) "VIEWPORT")
  22.     )
  23.     (progn
  24.       (vla-put-textstring (setq e (vlax-ename->vla-object e)) "")
  25.       (vla-put-textstring e
  26.         (strcat
  27.           "%<\\AcObjProp Object(%<\\_ObjId "
  28.           (itoa (vla-get-objectid (vlax-ename->vla-object vp)))
  29.           ">%).CustomScale \\f \"%sn\">%"
  30.         )
  31.       )
  32.     )
  33.   )
  34.   (princ)
  35. )

If the viewport's scale is "Custom", the field will display the scale factor instead of the scale name.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Select existing Field to modify its formula
« Reply #4 on: April 15, 2018, 09:46:30 AM »
Thanks

This is not what I have found: "If the viewport's scale is "Custom", the field will display the scale factor instead of the scale name."

There must be some setting, setvar or setenv that would make one layout within the same drawing work with these routines and another one not...

I have included the drawing file...refer to layout A4-0 Ext Elevs.

Thanks
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 2081
Re: Select existing Field to modify its formula
« Reply #5 on: April 15, 2018, 09:55:34 AM »
Foot Note:
It appears this happens only in BricsCAD and not in AutoCAD.

Thanks

This is not what I have found: "If the viewport's scale is "Custom", the field will display the scale factor instead of the scale name."

There must be some setting, setvar or setenv that would make one layout within the same drawing work with these routines and another one not...

I have included the drawing file...refer to layout A4-0 Ext Elevs.

Thanks
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 2081
Re: Select existing Field to modify its formula
« Reply #6 on: April 15, 2018, 10:47:15 AM »
I have come up with a solution. First I deleted the bad layout and used LeeMac's Steal routine to import the replacement layout. FIXED!!!
A special thanks goes to Lee.

Code: [Select]
;;-----------------------------------------=={ Steal }==-----------------------------------------;;
;;                                                                                               ;;
;;                                                                                               ;;
;;                       --------------------------------------------------                      ;;
;;                                        Program Overview                                       ;;
;;                       --------------------------------------------------                      ;;
;;                                                                                               ;;
;;  Allows the user to import (humourously: 'steal') items from another drawing into the active  ;;
;;  drawing.                                                                                     ;;
;;                                                                                               ;;
;;  Upon running the program with 'Steal' at the AutoCAD command-line, the user is prompted to   ;;
;;  select a drawing to steal from (dwg/dwt/dws). Upon selection, if the selected drawing        ;;
;;  contains items not already present in the current drawing, a dialog will appear detailing    ;;
;;  items available for import.                                                                  ;;
;;                                                                                               ;;
;;  The user may choose multiple items from a list of:                                           ;;
;;                                                                                               ;;
;;    -  Blocks                                                                                  ;;
;;    -  Layers                                                                                  ;;
;;    -  Linetypes                                                                               ;;
;;    -  Dimension Styles                                                                        ;;
;;    -  Text Styles                                                                             ;;
;;    -  Table Styles                                                                            ;;
;;    -  MLeader Styles                                                                          ;;
;;    -  MLine Styles                                                                            ;;
;;    -  Layouts                                                                                 ;;
;;    -  Page Setups                                                                             ;;
;;    -  User Coordinate Systems                                                                 ;;
;;    -  Groups                                                                                  ;;
;;    -  Views                                                                                   ;;
;;    -  Layer States                                                                            ;;
;;    -  Scales                                                                                  ;;
;;    -  Materials                                                                               ;;
;;    -  Viewports                                                                               ;;
;;    -  Drawing Properties                                                                      ;;
;;    -  Custom Properties                                                                       ;;
;;                                                                                               ;;

Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

Stefan

  • Bull Frog
  • Posts: 319
  • The most I miss IRL is the Undo button
Re: Select existing Field to modify its formula
« Reply #7 on: April 15, 2018, 02:21:55 PM »
GDF, good for you if you fix it already, I imagine you are doing this setting just once so maybe it's not important, but I just want to tell you that you had some issues in the dwg sample: all the fields in "A4-0 Ext Elevs" are targeting the wrong viewport. The bottom most field is not set to "%sn" format.


GDF

  • Water Moccasin
  • Posts: 2081
Re: Select existing Field to modify its formula
« Reply #8 on: April 15, 2018, 02:35:16 PM »
Thanks

I did not think about that...
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64