woodman78 Posted August 17, 2010 Posted August 17, 2010 I create maps that are registered with our land registry authority. They have a requirement that all maps indicate in Coord format the extents of the map window (see image attached). The thing is that the coords are to be in paperspace but relative to the extents of the viewport in modelspace. So that if I pan around inside the viewport and regen the coords they update. How would I best go about this? Can it be done using fields? I have looked at the VSMAX and VSMIN variables but I don't think that is correct because the values seem way off. I just had a thought that maybe I could do it by using VIEWCTR and that viewport scale to calculate the extents and write them out to block attributes.. Anyone done anything like this before??? Quote
woodman78 Posted August 17, 2010 Author Posted August 17, 2010 I have been using the lisp below to plot the viewport in modelspace for some time and have just realised that in fact all the information I need it there already. Problem I have is that sometimes it doesn't quite draw the border correctly. ;;*************************************************************************** ; VBORD.LSP V1.0 by Zoltan Toth ; ZOTO Technologies, ; 23 Greenhills Dve, ; Melton 3337. ; E-MAIL: [email="zoltan.toth@ains.net.au"]zoltan.toth@ains.net.au[/email] ; WWW: [url]http://www.ains.net.au/zoto/[/url] ;;***************************************************************************** ; Draws a border to the extents of the current viewport in layer ; DEFPOINTS so it will not plot. Layer DEFPOINTS will be created if ; needed. Useful for creating a border in Model space to indicate the ; extents of a Paper space viewport when working with TILEMODE = 1. ; This is done by changing Tilemode to zero, making a viewport current ; with the MSPACE command and then running VBORD. The border will be ; created automatically. Layer DEFPOINTS is sort of a "child" of layer ; 0 so anything you do to layer 0 will affect objects on layer ; DEFPOINTS as well. For some reason, you can't make changes to ; DEFPOINTS alone. ; ; Since most monitors have a slightly different dot pitch in the ; vertical and horizontal directions, a variable called PIX_RATIO is ; used to correct this. To determine what value PIX_RATIO should have, ; open a drawing and change TILEMODE to 0 if it isn't already and ; create a viewport whose X and Y dimensions are the values of your ; screen resolution ie. If your resolution is 1024x768 then your ; viewport dimensions should be 1024 drawing units wide and 768 ; drawing units high. Make that viewport active and run VBORD with ; PIX_RATIO at the default value of 1.0. Then TILEMODE to 1 and you ; should see the rectangle created by VBORD. You may need to zoom out ; if you can't see it. Run the CAL command and at the: ; >> Expression: ; prompt, key in: ; (1024/768)/(dist(end,end)/dist(end,end)) ; and hit <return>. The "(1024/768)" is assuming a video resolution of ; 1024x768. If yours is different, key that in. ; ; After you hit <return>, you will be faced with what looks like a ; pickbox the size of your APERTURE setting and a prompt on the command ; line: ; >> Select entity for _END snap: ; Pick the top left hand corner of the VBORD rectangle, then the top ; right corner of the rectangle, the top right again and then the bottom ; right corner. This compares the ratio of your video resolution ratio ; to the ratio of the width and height of the border drawn by VBORD - a ; ratio of ratios if you will. Once done, CAL will display a number on ; the command line which should be fairly close to 1. This is the value ; for PIX_RATIO. ; ; Make sure that you have configured the video display in AutoCAD to ; produce round circles and square squares prior to calculating the ; value for PIX_RATIO. Altering the video display ratio in the AutoCAD ; configuration will require you to recalculate PIX-RATIO. ; Should you have different machines on a network with different ; PIX-RATIO requirements, and they use the same VBORD.LSP, you can put ; in a COND function linked to either the _PKSER or LOGINNAME SETVAR to ; set PIX_RATIO according the the machine. ;;*************************************************************************** ;define program and localize variables (defun C:VBORD(/ CLAY2 PWID2 X_CEN YCEN SCRHGT X_DIM Y_DIM XY_RATIO PIX_RATIO SCRWID LEFTEX RIGHTEX BOTEX TOPEX PT2 PT3 PT4 PT5 ) (setq PIX_RATIO 1.0 ;set PIX_RATIO to horizontal/vertical dot pitch ratio of monitor CMD2 (getvar "CMDECHO") ;save current command echo status CLAY2 (getvar "CLAYER") ;save current layer PWID2 (getvar "PLINEWID") ;save current POLYLINE width ) (setvar "CMDECHO" 0) ;turn off command echoing (command "._UCS" "_VIEW") ;align UCS to view (setq X_CEN (car (getvar "VIEWCTR")) ;get X value of viewport centre Y_CEN (cadr (getvar "VIEWCTR")) ;get Y value of viewport centre SCRHGT (getvar "VIEWSIZE") ;get height of viewport in dwg units X_DIM (car (getvar "SCREENSIZE")) ;get height of viewport in pixels Y_DIM (cadr (getvar "SCREENSIZE")) ;get width of viewport in pixels XY_RATIO (/ X_DIM Y_DIM) ;calculate width:height ratio of viewport SCRWID (* SCRHGT XY_RATIO PIX_RATIO) ;calculate width of viewport in dwg units LEFTEX (- X_CEN (/ SCRWID 2.0)) ;\ calculate left, RIGHTEX (+ X_CEN (/ SCRWID 2.0)) ; \ right, BOTEX (- Y_CEN (/ SCRHGT 2.0)) ; / bottom and TOPEX (+ Y_CEN (/ SCRHGT 2.0)) ;/ top extents of viewport PT2 (list LEFTEX BOTEX 0.0) ;bottom left corner of viewport PT3 (list RIGHTEX BOTEX 0.0) ;bottom right corner of viewport PT4 (list RIGHTEX TOPEX 0.0) ;top right corner of viewport PT5 (list LEFTEX TOPEX 0.0) ;top left corner of viewport ) (command "._LAYER" "_MAKE" "CCC_LAYOUT_Viewport_Border" "") ;set current layer to DEFPOINTS (command "._PLINE" PT2 "_WIDTH" "0.0" "" PT3 PT4 PT5 "_CLOSE") ;draw border (command "._UCS" "_PREVIOUS") ;restore previous UCS (setvar "CMDECHO" CMD2) ;restore command echo status (setvar "CLAYER" CLAY2) ;restore previous layer (setvar "PLINEWID" PWID2) ;restore previous POLYLINE width (princ) ;exit quietly ) Quote
woodman78 Posted August 17, 2010 Author Posted August 17, 2010 It turns out that I hadn't update the PIX_RATIO setting for my monitor and that's why it didn't draw correctly sometimes. Bit of a one way conversation going on here.....eh!!!!! Quote
woodman78 Posted August 17, 2010 Author Posted August 17, 2010 I have created a block with attributes in place of the coords in the top image. How to I update the attibutes? Quote
lpseifert Posted August 17, 2010 Posted August 17, 2010 I see from the above code that the coordinates are savead as the variables PT2-PT5. If you were to "de-localize" them, you could use fields in your attributes (Field Name > LispVariable). You'd need to run the lisp and regenerate each time you want to update. Quote
woodman78 Posted August 17, 2010 Author Posted August 17, 2010 What do you mean by "de-localise" them? How do I go about setting it up to use LispVariables? Do I need to create new LispVariables within CAD? Is ti something to do with Diesel expressions? Quote
lpseifert Posted August 17, 2010 Posted August 17, 2010 When a variable is declared local, it's value is returned to it's original value once the lisp routine has finished (most likely nil). If it is not declared, it retains the value it was assigned during the routine. A variable is localized when it is after the / in the expression immediately after the the (defun... the variables in red below (defun C:VBORD(/ [color=darkred]CLAY2 PWID2 X_CEN YCEN SCRHGT X_DIM Y_DIM XY_RATIO PIX_RATIO SCRWID LEFTEX RIGHTEX BOTEX TOPEX PT2 PT3 PT4 PT5[/color] ) if you remove them from the expression you can use them in a field (defun C:VBORD(/ [color=darkred]CLAY2 PWID2 X_CEN YCEN SCRHGT X_DIM Y_DIM XY_RATIO PIX_RATIO SCRWID LEFTEX RIGHTEX BOTEX TOPEX[/color]); PT2 PT3 PT4 PT5 Quote
lpseifert Posted August 17, 2010 Posted August 17, 2010 I made a quick dwg using fields with LispVariables. You'll need to run the lisp routine (after removing the variables from being localized) and then do a regenall. Be aware that this will only work for 1 viewport at a time. hope it works for you Test.dwg Quote
woodman78 Posted August 18, 2010 Author Posted August 18, 2010 Thanks for that. It's great. It'll save a lot of time on our next job. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.