hardwired Posted November 24, 2010 Posted November 24, 2010 Hi, I'm trying to sort this small command out, which basically get the current layer, sets a specific layer to be current, then does the single viewport command, then should switch back to the previously current layer.. ; VP COMMAND.. (defun C:VP() (setq clr (getvar "clayer")) (command "-layer" "S" "LSC-VPORT" "") (command "-vports") (command "-layer" "S" clr "") ) It all works except for the switch back to the previous current layer. It does the viewport command then thats its, doesnt switch layers, just stays on the specific "LSC-VPORT" layer.. Anyone see why it won't do what i want it to? Quote
pBe Posted November 24, 2010 Posted November 24, 2010 (command "-vports") ) [/code] maybe beacuse..... you leave this line hanging...... :wink: after this line is succesful .. then and only then the next line will be be invoked and whats the point of changing layers for? that i dont get? Think hardwired.. you can do it Quote
hardwired Posted November 24, 2010 Author Posted November 24, 2010 Ok, thats probably it but what i want to achieve is: Draw a viewport on a specific layer and return autocad to the previous layer it was on before the command was envoked. But instead it just stays on the layer (LSC-VPORT) that it draws the viewport on. I dont want users to have to manually return back to the layer they were working on.. so if you're correct pBe, how do i code it to wait until the user draws the viewport? Quote
pBe Posted November 24, 2010 Posted November 24, 2010 Ok, thats probably it but what i want to achieve is: Draw a viewport on a specific layer and return autocad to the previous layer it was on before the command was envoked. But instead it just stays on the layer (LSC-VPORT) that it draws the viewport on. I dont want users to have to manually return back to the layer they were working on.. so if you're correct pBe, how do i code it to wait until the user draws the viewport? Maybe you meant "Mview" ? Specify corner of viewport or [ON/OFF/Fit/Shadeplot/Lock/Object/Polygonal/Restore/LAyer/2/3/4] <Fit>: Which i may add that includes multiple options too but if you want to create 1 viewport .. you can use this (command "mview" pause pause) in place of (command "-vports") there are more efficient way of doing this.. but we'll start with your code Quote
Lee Mac Posted November 24, 2010 Posted November 24, 2010 If I understand you correctly, it sounds like you would be better using a command reactor to switch/reset layers, here's an old one I wrote: ;;--------------------=={ Layer Director }==------------------;; ;; ;; ;; Uses a command reactor to automatically set the layer ;; ;; upon the user invoking certain commands. ;; ;; ;; ;; Layer settings are stored in the list at the top of the ;; ;; program. The first entry in the list is the command on ;; ;; which the reactor will trigger, it may use wildcards. ;; ;; The second entry is the designated layer for the command ;; ;; entered, this layer will be created if non-existent. ;; ;; The third entry is the layer colour that will be used if ;; ;; the layer is to be created in the drawing. ;; ;; ;; ;; The Reactor is set to be enabled upon loading the program ;; ;; it can furthermore be toggled on and off using by typing ;; ;; 'LD' at the command line. ;; ;;------------------------------------------------------------;; ;; Author: Lee McDonnell, 2010 ;; ;; ;; ;; Copyright © 2010 by Lee McDonnell, All Rights Reserved. ;; ;; Contact: Lee Mac @ TheSwamp.org, CADTutor.net ;; ;;------------------------------------------------------------;; (defun c:LD nil (LM:LayerDirector T)) (defun LM:LayerDirector ( msg ) (vl-load-com) ;; © Lee Mac 2010 (setq *LayerData* '( ("*TEXT" "TEXT" 2) ("*DIM*,*QLEADER" "DIMENSIONS" 2) ("*VPORT*" "DEFPOINTS" 7) ) ) ( (lambda ( data callback1 callback2 / 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) (vlr-add react) ) (setq react (vlr-command-reactor data (list (cons :vlr-commandWillStart callback1) (cons :vlr-commandEnded callback2) (cons :vlr-commandCancelled callback2) ) ) ) ) (if msg (if (and react (vlr-added-p react)) (princ "\n<< Layer Director Enabled >>" ) (princ "\n<< Layer Director Disabled >>") ) ) ) "LayerDirector" 'LayerDirectorSet 'LayerDirectorReset ) (princ) ) (defun LM:MakeLayer ( name colour ) (or (tblsearch "LAYER" name) (entmakex (list (cons 0 "LAYER") (cons 100 "AcDbSymbolTableRecord") (cons 100 "AcDbLayerTableRecord") (cons 2 name) (cons 62 colour) (cons 70 0) ) ) ) ) (defun LayerDirectorSet ( reactor arguments / layerdetails layer ) (vl-load-com) ;; © Lee Mac 2010 (if (and (setq layerdetails (vl-some (function (lambda ( x ) (if (wcmatch (strcase (car arguments)) (car x)) (cdr x) ) ) ) *LayerData* ) ) (LM:MakeLayer (setq layer (car layerdetails)) (cadr layerdetails)) (zerop (logand 1 (cdr (assoc 70 (tblsearch "LAYER" layer) ) ) ) ) ) (progn (setq *oldlayer* (getvar 'CLAYER)) (setvar 'CLAYER layer) ) ) (princ) ) (defun LayerDirectorReset ( reactor arguments ) (vl-load-com) ;; © Lee Mac 2010 (if (and (not (wcmatch (strcase (car arguments)) "*UNDO")) *oldlayer* (tblsearch "LAYER" *oldlayer*) (zerop (logand 1 (cdr (assoc 70 (tblsearch "LAYER" *oldlayer*) ) ) ) ) ) (progn (setvar 'CLAYER *oldlayer*) (setq *oldlayer* nil) ) ) (princ) ) (princ) (LM:LayerDirector nil) (princ) The reactor is activated when the code is loaded and will automatically switch/reset layers depending on the commands you use. The list of commands/layers is at the top of the code, and all is explained in the code header. If you have any trouble, just ask. Lee Quote
pBe Posted November 24, 2010 Posted November 24, 2010 hardwired We can continue with your code...... If I understand you correctly, it sounds like you would be better using a command reactor to switch/reset layers, or that this would be very usefull Lee ....Nice Quote
alanjt Posted November 24, 2010 Posted November 24, 2010 mmm layer reactors, I wrote one to set the layers for XRefs, Images and Viewports and couldn't imagine not having it (don't forget to add "VPCLIP" for the viewport one, also). BTW, there are reports of serious crashing issues with putting objects on the DefPoints layer in new version of AutoCAD. I would avoid it at all costs. Hell, it's not difficult to create a viewport layer and set it to NoPlot. 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.