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

Auto scale bar

4 REPLIES 4
Reply
Message 1 of 5
sean.keohane
1823 Views, 4 Replies

Auto scale bar

Hi,

I have set up our standard template, so that the scale bar attributes are linked to the viewport/plot scale and automatically updates. However, when a bright spark decides to delete the scale bar in a drawing, puting it back is a pain. The easiest way is to go back to the template and copy and paste the viewport and scale bar together. Assign a saved view to the new viewport and delete the old one.

Now, is there any way a lisp could insert the scale bar to a drawing and input the fields for each value after selecting the viewport you wish to associate with it? The field setup is in attached dwg.

I'm stumped on this one, Any help is appreciated.

Thanks

Sean

4 REPLIES 4
Message 2 of 5
markruys2
in reply to: sean.keohane

i would group them together in the template, all the 3 objects which reference each other with their fields.

Message 3 of 5
lgabriel
in reply to: sean.keohane

See program below. Assumptions include:

 

1. Only one viewport per layout tab

2. Scale Bar and Site Plan block are entered at an X and Y scale of 1 and a rotational angle of 0

 

;asb.lsp l, gabriel 04.27.11
;
;object: to automatically insert Scale Bar and Sit Plan scale based upon annotation scale of viewport
;

(defun echooff ()
  (setq oldecho (getvar "CMDECHO"))
  (setq oldblip (getvar "BLIPMODE"))
  (setq oldosm (getvar "OSMODE"))
  (setvar "CMDECHO" 0)
  (setvar "BLIPMODE" 0)
  (setvar "OSMODE" 0)
  (setq olderror_echo *ERROR*)
  (terpri)
  (defun *ERROR* (msg)
    (princ " \n")
    (princ msg)
    (echoon)
  )
)
;
(defun echoon ()
  (setvar "CMDECHO" oldecho)
  (setvar "BLIPMODE" oldblip)
  (setvar "OSMODE" oldosm)
  (setq *ERROR* olderror_echo)
  (princ)
)
;Main Program
(defun c:asb ()
  (echooff)
  (setq oldattreq (getvar "ATTREQ"))
  (setq oldattdia (getvar "ATTDIA"))
  (setq ss (ssget "X" '((0 . "VIEWPORT"))))
  (setq ent (ssname ss 0))
  (setq cvscale (vla-get-customscale (vlax-ename->vla-object ent)))
  (setq scale (strcat "Scale 1:" (rtos (/ 1 cvscale) 2 0)))
  (setq d0 "0m")
  (setq d1 (strcat (rtos (/ 1 (* cvscale 100)) 2 2) "m"))
  (setq d2 (strcat (rtos (/ 1 (* cvscale 50)) 2 2) "m"))
  (setq d3 (strcat (rtos (/ 1 (* cvscale 33.33)) 2 2) "m"))
  (setq d4 (strcat (rtos (/ 1 (* cvscale 25)) 2 2) "m"))
  (setq d5 (strcat (rtos (/ 1 (* cvscale 20)) 2 2) "m"))
  (setq d6 (strcat (rtos (/ 1 (* cvscale 16.66)) 2 2) "m"))
  (setq d7 (strcat (rtos (/ 1 (* cvscale 14.29)) 2 2) "m"))
  (setq d8 (strcat (rtos (/ 1 (* cvscale 12.50)) 2 2) "m"))
  (setq d9 (strcat (rtos (/ 1 (* cvscale 11.11)) 2 2) "m"))
  (setq d10 (strcat (rtos (/ 1 (* cvscale 10)) 2 2) "m"))
  (princ "\nSelect insertion point for scale bar: ")
  (command "-INSERT" "Scale bar" (getpoint) 1 1 0 d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 d10 scale)
  (princ "\nSelect insertion point for Site Plan scale: ")
  (command "-INSERT" "Detail-title" (getpoint) 1 1 0 "" "%%USITE PLAN" scale)
  (setvar "ATTDIA" oldattdia)
  (setvar "ATTREQ" oldattreq)
  (echoon)
)

 

ECHOON and ECHOOFF functions are used to turn off the prompts while the program runs. Give it a try and let me know

Message 4 of 5
sean.keohane
in reply to: lgabriel

Hi Lgabriel,

Thank you for your reply. I loaded your lisp. I grayed out some of it  to focus just on the scale bar input and it works. Thank you.

However, I was hoping the attribute values could be fields associated with a chosen viewport. The attached image is how my template drawing is set up.The scale bar is always live and updates when the viewport scale is changed and when the drawing is plotted to a different scale. I have quite a lot of existing drawings which had there scale bars deleted by a  #^%~~# person. (freezing the scalebar layer or making it non printable just wasn't an option !!!).

Is there any way that could be done?

Thanks again for your time,

Much appreciated,

Regards

Sean

Message 5 of 5
Shneuph
in reply to: sean.keohane

HI Sean,

  You should be able to do what you want.  If I'm not mistaken, the field is referencing the viewport scale via the object ID (2125944320 in your jpg).  You need the program to insert the scale block and then automatically update the attrib field string with the new obj id.  I'll give it a shot tomorrow and update this post w/ the code.

---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)

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

Post to forums  

Autodesk Design & Make Report

”Boost