woodman78 Posted May 27, 2011 Posted May 27, 2011 I have a lisp that we use in our office for plotting. I am interested in using the annotative scaling for hatches in our drawings because they will always match the legend items that are blocks. I found a routine called "getvpscale.lsp" and I have tried to incorporate that into my routine. I am having problems and I am wondering if it is to do with the viewport scale needing to be converted to a string? This is the code I have: I would appreciate it if someone could have a look. ;Based on PageSetups from Alan J. Thompson (defun c:A3_1 (/ SS X VP_SC VP1 a) (PlotReactorOFF) (if (findfile "T:/Drawing Tools/Templates/CCC2009.dwt") (progn (command "_.psetupin" (findfile "T:/Drawing Tools/Templates/CCC2009.dwt") "A3") (while (wcmatch (getvar "cmdnames") "*PSETUPIN*") (command "_yes") ) ;_ while T ) ;_ progn ) ;_ if (command "-plot" "n" "" "A3" "" "n" "y" "n") (command "_-purge" "a" "*" "N") (command "updatefield" "all" "") (setq SS (ssget "X" (list '(0 . "VIEWPORT")(cons 410 (getvar "ctab"))))) (setq VP_SC (/ 1 (vla-get-customscale (vlax-ename->vla-object (ssname SS 0))))) (setq VP1 1000/VP_SC) (setq a (strcat "1:"VP1)) (command "Mspace") (command "cannoscale" a) (command "pspace") (command "regenall") (command "_zoom" "e") (initdia) (command "._plot") (PlotReactorON) ;(princ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun PlotReactorON nil (vl-load-com) ;; © Lee Mac 2010 ( (lambda ( data foo / react ) (if (setq react (vl-some (function (lambda ( reactor ) (if (eq data (vlr-data reactor)) reactor) ) ) (cdar (vlr-reactors :vlr-command-reactor) ) ) ) (if (not (vlr-added-p react)) (vlr-add react) ) (setq react (vlr-command-reactor data (list (cons :vlr-commandwillstart foo) ) ) ) ) (if (vlr-added-p react) (princ "\n** Reactor Activated **") (princ "\n** Reactor Failed to Activate **") ) react ) "Plot-Reactor" 'Plot-Callback ) (princ) ) (defun PlotReactorOFF nil (vl-load-com) ;; © Lee Mac 2010 ( (lambda ( data foo / react ) (if (setq react (vl-some (function (lambda ( reactor ) (if (eq data (vlr-data reactor)) reactor) ) ) (cdar (vlr-reactors :vlr-command-reactor) ) ) ) (if (vlr-added-p react) (vlr-remove react) ) ) (if (or (not react) (not (vlr-added-p react))) (princ "\n** Reactor Deactivated **") (princ "\n** Reactor Failed to Deactivate **") ) react ) "Plot-Reactor" 'Plot-Callback ) (princ) ) (defun Plot-Callback ( reactor arguments ) (vl-load-com) (if (eq (strcase (car arguments)) "PLOT") (LM:Popup "Warning" 64 "Gotcha!!! Please use the NNRDO Plot tools when plotting standard layouts!!") ) (princ) ) (defun LM:Popup ( title flags msg / WSHShell result ) ;; © Lee Mac 2010 (setq WSHShell (vlax-create-object "WScript.Shell")) (setq result (vlax-invoke WSHShell 'Popup msg 0 title flags)) (vlax-release-object WSHShell) result ) Quote
irneb Posted May 27, 2011 Posted May 27, 2011 As a start-point you may look at the incomplete code in this: http://caddons.svn.sourceforge.net/viewvc/caddons/General/Scales.LSP?revision=54&view=markup Note it also uses the vlaxx.lsp file in: http://caddons.svn.sourceforge.net/viewvc/caddons/Libraries/ You may want to see what the functions in that does to actually get it to work. Also you may find the attached file helpful when trying to determine what the VP's actual AnnoScale is as compared to its ViewScale (which may be different from each other). PSVports.LSP Quote
woodman78 Posted May 31, 2011 Author Posted May 31, 2011 irneb, I tried your "matchvpscale" and "matchallvpscale" and no joy. They didn't seem to change anything. Maybe I am picking this up wrong but what I want to do is the following: I have created lisps to insert hatch patterns into model space (footpath, carriageway etc.) I have created blocks for the legend that are dropped into paper space. I want to use annotative scaling so that the scale on the hatch on the drawing always matches that on the legend. I was trying to link annotative scale with viewport scale. When I set through the commands similar to my lisp above it works but I want to automate it so that when someone goes to print the drawing it will flick into model and set the "cannoscale" based on the viewport scale in the first layout tab. Am i going about this all wrong?? Quote
irneb Posted May 31, 2011 Posted May 31, 2011 Nope, you're not going wrong:wink: It's just that my code is to be used as a starting point, so you can see one way of get/set the VP's anno scale. You may need some extra stuff to add to the Hatches and so. BTW - perhaps just setting the AnnoAutoScale might do the trick, though I'd steer clear of keeping it turned on though. Quote
woodman78 Posted June 1, 2011 Author Posted June 1, 2011 I have made progress with this. I have set it up to print the values of the variables to the screen and it prints VP1 fine but not VP2. I am thinking that it is a maths problem. I have run a manual test on this and it works fine. Could someone have a look please? I looked in AnnoAutoScale but I don't see how that will help. ;Based on PageSetups from Alan J. Thompson (defun c:A3_1 (/ SS X VP_SC VP1 VP2 a) (PlotReactorOFF) (if (findfile "T:/Drawing Tools/Templates/CCC2009.dwt") (progn (command "_.psetupin" (findfile "T:/Drawing Tools/Templates/CCC2009.dwt") "A3") (while (wcmatch (getvar "cmdnames") "*PSETUPIN*") (command "_yes") ) ;_ while T ) ;_ progn ) ;_ if (command "-plot" "n" "" "A3" "" "n" "y" "n") (command "_-purge" "a" "*" "N") (command "updatefield" "all" "") (setq SS (ssget "X" (list '(0 . "VIEWPORT")(cons 410 (getvar "ctab"))))) (setq VP_SC (/ 1 (vla-get-customscale (vlax-ename->vla-object (ssname SS 0))))) ;(princ vp_sc) (setq VP1 (rtos VP_SC)) [color=red](princ vp1)[/color] (setq VP2 (1000 (/ VP1))) [color=red](princ vp2)[/color] (setq a (strcat "1:"VP2)) (command "_Mspace") (command "cannoscale" a) (command "_pspace") (command "regenall") (command "_zoom" "e") (initdia) (command "._plot") (PlotReactorON) ;(princ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun PlotReactorON nil (vl-load-com) ;; © Lee Mac 2010 ( (lambda ( data foo / react ) (if (setq react (vl-some (function (lambda ( reactor ) (if (eq data (vlr-data reactor)) reactor) ) ) (cdar (vlr-reactors :vlr-command-reactor) ) ) ) (if (not (vlr-added-p react)) (vlr-add react) ) (setq react (vlr-command-reactor data (list (cons :vlr-commandwillstart foo) ) ) ) ) (if (vlr-added-p react) (princ "\n** Reactor Activated **") (princ "\n** Reactor Failed to Activate **") ) react ) "Plot-Reactor" 'Plot-Callback ) (princ) ) (defun PlotReactorOFF nil (vl-load-com) ;; © Lee Mac 2010 ( (lambda ( data foo / react ) (if (setq react (vl-some (function (lambda ( reactor ) (if (eq data (vlr-data reactor)) reactor) ) ) (cdar (vlr-reactors :vlr-command-reactor) ) ) ) (if (vlr-added-p react) (vlr-remove react) ) ) (if (or (not react) (not (vlr-added-p react))) (princ "\n** Reactor Deactivated **") (princ "\n** Reactor Failed to Deactivate **") ) react ) "Plot-Reactor" 'Plot-Callback ) (princ) ) (defun Plot-Callback ( reactor arguments ) (vl-load-com) (if (eq (strcase (car arguments)) "PLOT") (LM:Popup "Warning" 64 "Gotcha!!! Please use the NNRDO Plot tools when plotting standard layouts!!") ) (princ) ) (defun LM:Popup ( title flags msg / WSHShell result ) ;; © Lee Mac 2010 (setq WSHShell (vlax-create-object "WScript.Shell")) (setq result (vlax-invoke WSHShell 'Popup msg 0 title flags)) (vlax-release-object WSHShell) result ) Quote
irneb Posted June 1, 2011 Posted June 1, 2011 I looked in AnnoAutoScale but I don't see how that will help.My thought was to turn on that variable (say set it to 1), then change the CAnnoScale and it "should" then automatically apply the newly used scale to all annotative objects. BTW, I think from your code you're miscalculating the AnnoScale. Usually the VP scale is the result of what you get from the 1/###XP zoom method. E.g. 1/100XP would give you a value of 0.01, but the corresponding AnnoScale would be 1:100 (without any decimals). Forget the rtos on the VP1 variable - this will cause errors later. So first you need to find the inverse of the VP1 scale: (setq VP2 (/ 1 VP1)) Now to get the corresponding AnnoScale: (setq VP2A (strcat "1:" (rtos VP2 2 0))) Now you could send that to the CAnnoScale system variable: (setvar "CAnnoScale" VP2A) Note this will only do so for the currently active viewport. So you'll need to ensure that you're in Model Space and that the CVPORT is that of the viewport's ID (DXF code 69). Also if that scale exists it should change correctly, if not there will probably be an error. Quote
woodman78 Posted June 1, 2011 Author Posted June 1, 2011 Thanks for all your help irneb. This works. I had to change (setq VP2 (\ 1 VP1)) to (setq VP2 (* 1 VP1)) ;Based on PageSetups from Alan J. Thompson (defun c:A3_1 (/ SS X VP_SC VP1 VP2 a) (PlotReactorOFF) (if (findfile "T:/Drawing Tools/Templates/CCC2009.dwt") (progn (command "_.psetupin" (findfile "T:/Drawing Tools/Templates/CCC2009.dwt") "A3") (while (wcmatch (getvar "cmdnames") "*PSETUPIN*") (command "_yes") ) ;_ while T ) ;_ progn ) ;_ if (command "-plot" "n" "" "A3" "" "n" "y" "n") (command "_-purge" "a" "*" "N") (command "updatefield" "all" "") (setq SS (ssget "X" (list '(0 . "VIEWPORT")(cons 410 (getvar "ctab"))))) (setq VP_SC (/ 1 (vla-get-customscale (vlax-ename->vla-object (ssname SS 0))))) (setq VP2 (* 1000 VP_SC)) (setq a (strcat "1:" (rtos VP2 ))) (command "_Mspace") (setvar "cannoscale" a) (command "_pspace") (command "regenall") (command "_zoom" "e") (initdia) (command "._plot") (PlotReactorON) ;(princ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun PlotReactorON nil (vl-load-com) ;; © Lee Mac 2010 ( (lambda ( data foo / react ) (if (setq react (vl-some (function (lambda ( reactor ) (if (eq data (vlr-data reactor)) reactor) ) ) (cdar (vlr-reactors :vlr-command-reactor) ) ) ) (if (not (vlr-added-p react)) (vlr-add react) ) (setq react (vlr-command-reactor data (list (cons :vlr-commandwillstart foo) ) ) ) ) (if (vlr-added-p react) (princ "\n** Reactor Activated **") (princ "\n** Reactor Failed to Activate **") ) react ) "Plot-Reactor" 'Plot-Callback ) (princ) ) (defun PlotReactorOFF nil (vl-load-com) ;; © Lee Mac 2010 ( (lambda ( data foo / react ) (if (setq react (vl-some (function (lambda ( reactor ) (if (eq data (vlr-data reactor)) reactor) ) ) (cdar (vlr-reactors :vlr-command-reactor) ) ) ) (if (vlr-added-p react) (vlr-remove react) ) ) (if (or (not react) (not (vlr-added-p react))) (princ "\n** Reactor Deactivated **") (princ "\n** Reactor Failed to Deactivate **") ) react ) "Plot-Reactor" 'Plot-Callback ) (princ) ) (defun Plot-Callback ( reactor arguments ) (vl-load-com) (if (eq (strcase (car arguments)) "PLOT") (LM:Popup "Warning" 64 "Gotcha!!! Please use the NNRDO Plot tools when plotting standard layouts!!") ) (princ) ) (defun LM:Popup ( title flags msg / WSHShell result ) ;; © Lee Mac 2010 (setq WSHShell (vlax-create-object "WScript.Shell")) (setq result (vlax-invoke WSHShell 'Popup msg 0 title flags)) (vlax-release-object WSHShell) result ) 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.