I have the following routine which i used to select the viewport and then select the scale bar (attributed block) and it updates the values via fields.
It works but at the end of the command in the command line it shows the following:
Pick a viewport:
Select Block: ; error: ADS request error
Not sure why it does this.
;;Links the Viewport Scale to the Scale Bar
(defun _getviewport (e)
(if e
(cond ((= "VIEWPORT" (cdr (assoc 0 (entget e)))) e)
((cdadr (member '(102 . "{ACAD_REACTORS") (entget e))))
)
)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun c:vpscale-link (/ fldobj util vpid vpobj)
(if (and (setq vpobj (_getviewport (car (entsel "\nPick a viewport: "))))
;; Add a check that it's a viewport selected
(setq fldobj (car (entsel "\nSelect Block: ")))
;; Add a check that it's your barscale selected
(setq vpid (vla-get-objectid (setq vpobj (vlax-ename->vla-object vpobj))))
)
(progn
(if (> (vl-string-search "x64" (getvar "platform")) 0)
(progn (setq util (vla-get-utility (vla-get-activedocument (vlax-get-acad-object)))
vpid (vlax-invoke-method util "GetObjectIdString" vpobj :vlax-false)
)
)
(setq vpid (vl-princ-to-string (vla-get-objectid vpobj)))
)
(foreach a '("half" "double" "full2" "full1" "verthalf" "vertfull" "vertdouble" "verthalfrot" "vertfullrot" "vertdoublerot" "tripple")
(setpropertyvalue
fldobj
a
(strcat "%<\\AcExpr ("
(cond ((= a "half") "2.0")
((= a "double") "0.5")
((= a "full2") "1.0")
((= a "full1") "1.0")
((= a "verthalf") "2.0")
((= a "vertfull") "1.0")
((= a "vertdouble") "0.5")
((= a "verthalfrot") "2.0")
((= a "vertfullrot") "1.0")
((= a "vertdoublerot") "0.5")
((= a "tripple") "0.25")
)
"*%<\\AcObjProp Object(%<\\_ObjId " vpid ">%).CustomScale>%) \\f \"%lu2%ct1%qf2816'\">%" ;;%lu2%ct1%qf2816%ps[,\']">%
)
)
)
(vla-regen (vla-get-activedocument (vlax-get-acad-object)) 1)
)
)
(vla-regen (vla-get-activedocument (vlax-get-acad-object)) 1)
(princ))