Associate Scale Bar block with user-selected viewport "custom scale" property

Associate Scale Bar block with user-selected viewport "custom scale" property

Anonymous
Not applicable
1,468 Views
5 Replies
Message 1 of 6

Associate Scale Bar block with user-selected viewport "custom scale" property

Anonymous
Not applicable

Hi All,

 

My objective is to make a scale bar block that updates automatically with the viewport scale.

I imagine this can be best accomplished with a lisp file that loads automatically on startup. Pseudocode below (I don't know any LISP, so sorry if it's rough):

 

When

(INSERT->"BLOCKNAME"  <--My block's name is "SCALEBAR"

  Prompt user to select viewport to associate with block

  Get Custom Scale from viewport and store it  <-- for this example, store as "CS"

  Replace "BLOCKNAME" attribute 1 value with formula: 1/CS  <-- My attribute 1 is named "VPSCALE"

  Replace "BLOCKNAME" attribute 2 value with formula: 2/CS  <-- My attribute 2 is named "VPSCALEX2"

)

 

Things I've tried so far (and their limitations):

1) The option which has given me the best results is to insert my scale bar block and then edit the attributes (VPSCALE and VPSCALEX2) with a field containing the formula: 1/"Object->Viewport->Custom Scale". If I then copy and paste the paired viewport and scale bar, I can create a new paired viewport and scale bar. The main limitation is that my coworkers are terrible with blocks, probably don't even know what fields are, and this option doesn't give them the flexibility to just insert the scale bar block and easily be able to associate it with a viewport.

 

2) I've tried using the SheetSetPlaceholder "ViewportScale" in various configurations without success. The main problems are twofold: 1) My office doesn't really use SSM and especially not named views, which is a requisite to get ViewportScale to work (must be inserted from SSM->Named View->Callout Block; and 2) that it seems ViewportScale can't be used in a formula (reverts to ####).

2a) I tried using it directly in a formula field for VPSCALE: 1/"SheetSetPlaceholder->ViewportScale" (failed, reverted to ####).

2b) I tried using ViewportScale in an attribute called GETVALUE, and then using that in a formula for VPSCALE: 1/"Object->Attribute (GETVALUE)->Value" (failed, reverted to ####).

2c) It also can't be in a nested block (it has to be on the top level). I tried making a block called TEST which only contained the attribute GETVALUE. Then, in my scale bar block, I inserted the block TEST and changed the formula for VPSCALE to 1/"Object->Block Reference->GETVALUE" (failed, when the scale bar block is inserted, TEST/GETVALUE displays VIEWPORTSCALE).

 

3) I edited the code from this link to work with my scale bar block. The main limitation with this option are twofold: 1) The scale bar is static: If I change the viewport scale, the scale bar does not automatically update. 2) Requires a different workflow to insert the scale bar than every other block. Instead of using "INSERT->BLOCKNAME", users must now know to use "APPLOAD->MYLISP.LSP;->MYLISP".

0 Likes
1,469 Views
5 Replies
Replies (5)
Message 2 of 6

Moshe-A
Mentor
Mentor

@Anonymous  hi,

 

Hope this still actual?!

 

To handle such an issue a database reactor must be used (do you know what it is?) wrap this code in a lisp file and load it with appload startup suite (so it will be available at all times).

 

at load time the database reactor called 'acdbReactor' is install in AutoCAD memory and waits for action Smiley LOL 

if an object is modified the reactor fired and call (AcDbOnObjectModified) callback function and if the Reactor is identified (as "Grant_Herrman") and if the object is a viewport the program goes to (ModifyScaleBar) function to update the attributes. when such actions take place, you have to be aware (please, read this very carefully)

 

1. the program will react on each touch of any viewport in current layout and set the block scale attributes even if your change to viewport was something else or did not change anything at all cause it does not monitor any viewport properties and it can't know what was change.

 

2. the progarm search for all blocks scale in the current layout and set their attributes respectively, so make sure only one scale block is exist aside the viewport.

 

3. when the attributes is set the fields (exist in your block) is removed

 

4. if you notice AutoCAD Nervousness, the system crashes more often then it used to? uninstall this lisp.

cause some times AutoCAD tend to be unstable with activex reactors.

 

enjoy

moshe

 

 

 

; callback
(defun AcDbOnObjectModified (Reactor Obj^ / modifyScaleBar ; local function AcDbObject) (defun modifyScaleBar (/ elist ss AcDbBlkRef) (vlr-remove Reactor) ; disable reactor

(if (and (setq elist (entget (vlax-vla-object->ename AcDbObject))) ; get viewport database (setq ss (ssget "_x" (list '(0 . "insert") '(2 . "`*U*") '(66 . 1) (assoc '410 elist)))) ; fetch blocks ) (foreach ename (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))) (setq AcDbBlkRef (vlax-ename->vla-object ename)) (if (eq (strcase (vla-get-effectiveName AcDbBlkRef)) "SCALE") (foreach AcDbAttrib (vlax-invoke AcDbBlkRef 'GetAttributes) (cond ((eq (strcase (vla-get-tagString AcDbAttrib)) "VPSCALE") (vla-put-textString AcDbAttrib (rtos (/ (cdr (assoc '45 elist)) (cdr (assoc '41 elist))) 2 0)) ) ((eq (strcase (vla-get-tagString AcDbAttrib)) "VPSCALEX2") (vla-put-textString AcDbAttrib (rtos (* (/ (cdr (assoc '45 elist)) (cdr (assoc '41 elist))) 2) 2 0)) ) ); cond (vlax-release-object AcDbAttrib) ); foreach ); if (vlax-release-object AcDbBlkRef) ); foreach ); if
(vlr-add Reactor) ; enable reactor
); modifyScaleBar
(if (and (eq (vlr-data Reactor) "Grant_Herrman") (setq AcDbObject (vlax-ename->vla-object (cadr Obj^))) (eq (vla-get-objectname AcDbObject) "AcDbViewport") ) (progn (modifyScaleBar) (vlax-release-object AcDbObject) ) ); if ); AcDbOnObjectModified ; install database reactor (if (or (not acdbReactor) (not (vlr-added-p acdbReactor)) ) (setq acdbReactor (vlr-acdb-reactor "Grant_Herrman" '((:vlr-objectModified . AcDbOnObjectModified)))) )

 

 

 

0 Likes
Message 3 of 6

hencoop
Advisor
Advisor

Hello @Anonymous,

 

If a reactor causes you too much trouble or overhead (as they sometimes do) you could just opt to have your routine read the viewport scale and insert the appropriate bar scale for that scale.  It is even possible to remove the previous barscale (if any) using a search restricted to the current viewport.

 

I use this approach which may be of use to you:

 

My lisp reads the dimscale or the viewport scale if dimscale=0 and inserts the appropriate block for decimal feet (Civil) or creates an architectural bar scale and groups it for everything else (assumes architectural-inches).  It does all of my housekeeping, I.e. sets the CLG layer(s) and calculates the rotation for it to appear horizontal in a twisted view.  I have a collection of civil bar scale blocks ranging from 1"=1' to 1"=<different numbers of miles>.  The architectural scales are all created fresh and put in a group.  Architectural bar scales meet the U.S. Army Corps of Engineers standard bar scale for Architectural units as published when I wrote the routine.

 

I can share it with you or whomever is interested.  Below is the comment header to the main lisp file (notice "Required:", I use subroutines and some of them use other subroutines, all of which I will share):

;;;	Places engineering or architectural bar scales by dimscale or, if dimscale=0, by viewport scale.
;;;	The type of barscale is determined by LUNITS and INSUNITS.
;;;	If both = 2 then a 1:1 bar scale block matching the dimscale or viewport scale is inserted.
;;;	Otherwise, an architectural bar scale matching the dimscale or viewport scale is created.
;;;	Architectural bar scales are added to a new group created of its parts (it is not a block, [Ctrl+H] is the group lock toggle).
;;;	The architectural bar scale varies in the tic marks and divisions used as appropriate for various architectural scales.
;;;
;;;	Uses blocks named nBARS where n=dimscale as integer.
;;;	for Decimal linear units [LUNITS] and FEET insert units [INSUNUITS].
;;;	All other conditions are assumed to be Architectural units in inches.
;;;
;;;	Creates the U.S. Army Corps of Engineers standard
;;;	bar scale for Architectural units based upon dimscale.
;;;
;;;	AUTHOR: Henry C. Francis
;;;		425 N. ASHE ST.
;;;		SOUTHERN PINES, N.C. 28387
;;;		All rights reserved without prejudice.
;;;		http://paracadd.com
;;;
;;;	Copyright:	2-4-92
;;;	Edited:		5-20-2019
;;;
;;;	Requires:	GVPNO.LSP, MKLAYR.LSP, DIMSCL.LSP, TXTSIZE.LSP, SET_MJRG.LSP, UPOINT.LSP, UREAL.LSP, UINT.LSP, UKWORD.LSP, USTR.LSP,
;;;			MAKE_LAYER_ENT.LSP, SETWILDCARDLITERAL.LSP, SRSTRING.LSP, CHKKWDS.LSP, STDLTYPES.LSP, ERRORTRAP.LSP,
;;;			CHECK_FOR_DOSLIB.LSP & McNeel & Assoc. "DOSLIB" (free @ https://wiki.mcneel.com/doslib/home)
;;;			(These lisp files must be available on your "AutoCAD Support File Search Path" (under the Options Files tab).
;;;

P.S. I have a modified version of Autodesk's autoload.lsp (I think that is its name) that I call customload.lsp
I put init functions for my lisp commands in this customload file just as Autodesk does in theirs and I put my customload.lsp in the Startup Suite in the APPLOAD dialog.  Then, whenever I need to add another custom lisp command for our users I just add it to customload and the next time they start AutoCAD (or reload customload.lsp) they have the new command.  Initiallty I had just added my custom commands to Autodesk's lisp file so I did not even need to mess with APPLOAD but upgrades always overwrote it.  It is important that the lisp files are in a network accessible location and that that location is included in the users "AutoCAD Support File Search Path" in Options under the Files tab on each user's CAD machine.

AutoCAD User since 1989. Civil Engineering Professional since 1983
Product Version: 13.6.1963.0 Civil 3D 2024.4.1 Update Built on: U.202.0.0 AutoCAD 2024.1.6
                        27.0.37.14 Autodesk AutoCAD Map 3D 2024.0.1
                        8.6.52.0 AutoCAD Architecture 2024
0 Likes
Message 4 of 6

hencoop
Advisor
Advisor

@Anonymous 

P.P.S.

I still use my function to place barscales in my views since Sheet Sets fields only provide a numeric scale value.  Meaningful bar scales are required on our drawings.  I have been slowly getting our people to use Sheet Sets and the SSM with Views.   It is well worth the effort to make the change.  The benefits of using Sheet Sets goes well beyond the ViewportScale field.  It will save time and money.

AutoCAD User since 1989. Civil Engineering Professional since 1983
Product Version: 13.6.1963.0 Civil 3D 2024.4.1 Update Built on: U.202.0.0 AutoCAD 2024.1.6
                        27.0.37.14 Autodesk AutoCAD Map 3D 2024.0.1
                        8.6.52.0 AutoCAD Architecture 2024
0 Likes
Message 5 of 6

Anonymous
Not applicable

@Moshe-A , @hencoop ,

 

Thank you both for your suggestions. I'll try them out and report back later this week.

0 Likes
Message 6 of 6

hencoop
Advisor
Advisor

@Anonymous I realized that I don't need your private email.  I can just post the file here.

 

I believe all the required lisp files are in the attached Zip file.  I've included customload.lsp as you requested.

 

I’ve included all of my bar scale blocks.  They are named “<# of feet per inch>BARS.DWG”

The bar scale blocks may vary a little in appearance but they do generally meet the USACE standard for civil bar scales at the time I created the routine.  I do remember that the USACE minimum text height standard (plotted) was 1/8” (0.125).  We rarely do USACE work anymore and our standard is 0.11” plotted.  They will have a wipeout  or faded image masking for them.  This could be just a wipeout, just an image (1x1.bmp), or a non-uniform scaled block named hdbox.dwg containing one or the other.

If they use 1x1.bmp you will need that image (which I have included just in case) somewhere on your “AutoCAD Support File Search Path”.

I generally will create a new bar scale block matching the appearance of my latest ones whenever I find I need one I don’t have.  I have to remember to WBLOCK it to my block collection folder (the name must be ###BARS.DWG where ### is the number of feet per inch).  BSCL.LSP constructs the name it needs from the viewport scale or dimscale and will insert it if it exists.

If you find that a lisp file is missing (you see an “Error: no function definition: <name>” or "Unknown command <name>" message) just let me know and I'll see if I can send it to you.

AutoCAD User since 1989. Civil Engineering Professional since 1983
Product Version: 13.6.1963.0 Civil 3D 2024.4.1 Update Built on: U.202.0.0 AutoCAD 2024.1.6
                        27.0.37.14 Autodesk AutoCAD Map 3D 2024.0.1
                        8.6.52.0 AutoCAD Architecture 2024
0 Likes