CADkitt Posted November 15, 2010 Posted November 15, 2010 I can't find how to do this, I have this script to set dimensions on layers, but now it doesn't princ the dimension value at the end, and some engineers used that value for measuring. (can't get them to use the measure tool..) So how can I output the value of the last placed dimension? (DEFUN c:newdimlinear (/ |clayer| |cmdecho| |olderror| |orthomode| |polarmode| |pt1| |pt2| ) (COMMAND "undo" "begin") (SETQ |olderror| *error*) (SETQ *error* |dimerror|) (SETQ |clayer| (GETVAR "clayer")) (SETQ |cmdecho| (GETVAR "cmdecho")) (SETQ |orthomode| (GETVAR "orthomode")) (SETQ |polarmode| (GETVAR "polarmode")) (SETVAR "cmdecho" 0) (SETVAR "orthomode" 0) (IF (NOT (TBLSEARCH "layer" "01 Dimensions")) (COMMAND "_.-layer" "_make" "01 Dimensions" "_color" "1" "01 Dimensions" "" ) (COMMAND "_.-layer" "_thaw" "01 Dimensions" "_on" "01 Dimensions" "_set" "01 Dimensions" "" ) ) (COMMAND "dimlinear" pause pause pause) (SETVAR "clayer" |clayer|) (SETVAR "cmdecho" |cmdecho|) (SETVAR "orthomode" |orthomode|) (SETVAR "polarmode" |polarmode|) (SETQ *error* |olderror|) (COMMAND "undo" "end") (PRINC) ) Quote
lpseifert Posted November 15, 2010 Posted November 15, 2010 something like this maybe? (princ (rtos (cdr (assoc 42 (entget (entlast)))))) Quote
CADkitt Posted November 15, 2010 Author Posted November 15, 2010 Yeah, I thought it should be really easy for some one who knows it I am not really familiar with the assoc and the dxf code ( I thought it was dxf code?). But it worked like a charm. tnx Quote
Lee Mac Posted November 15, 2010 Posted November 15, 2010 Hi CADKitt, To be honest, for your purpose, you would be better off using a Command Reactor to control your layers - this way you can have one LISP control a multitude of command layers, without having to use different command sytaxes. I wrote this a while back: ;;--------------------=={ 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) ("*EXECUTETOOL" "4" 4) ) ) ( (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) (princ "\n:: LayerDirector.lsp | Copyright © 2010 by Lee McDonnell ::") (princ "\n:: Type \"LD\" to Toggle Reactor ::\n") (princ) (LM:LayerDirector nil) It uses a command reactor which will automatically change your layers, depending on the commands listed at the top of the code. You only need to load it at startup, and it will do the rest for you. You can deactivate it using 'LD' at the command line, (this will toggle it on/off). If you have any questions about the code, or need help modifying the layers to suit your company standards, just ask. Lee Quote
CADkitt Posted November 15, 2010 Author Posted November 15, 2010 Cool stuff, gonna figure that out tomorrow. It's looks pretty clear to me. Only asking myself why the hell isn't this standard stuff in Autocad? I thought mechanical has something like this, but not autocad. Quote
Lee Mac Posted November 15, 2010 Posted November 15, 2010 Cool stuff, gonna figure that out tomorrow. It's looks pretty clear to me. Only asking myself why the hell isn't this standard stuff in Autocad? True, and it really isn't too hard to implement (after all, I can write it lol) Quote
alanjt Posted November 15, 2010 Posted November 15, 2010 What if the user has multiple layers for the same objects? eg. I put text on a *-TEXT layer, corresponding to the primary layer. You could also just set cmdecho to 1 before executing the Dimension command. Quote
Lee Mac Posted November 15, 2010 Posted November 15, 2010 What if the user has multiple layers for the same objects? eg. I put text on a *-TEXT layer, corresponding to the primary layer. Then my code as it stands is perhaps not suitable for such a case and should be engineered to suit the user. Quote
alanjt Posted November 15, 2010 Posted November 15, 2010 Then my code as it stands is perhaps not suitable for such a case and should be engineered to suit the user. Some standards allow for the layer command reactor (I tried it myself a couple years back), but mostly it's just neat. BTW, why'd you add *EXECUTETOOL, isn't that the Tool Palettes command? Quote
Lee Mac Posted November 15, 2010 Posted November 15, 2010 BTW, why'd you add *EXECUTETOOL, isn't that the Tool Palettes command? Yeah, was needed when I wrote it. Quote
alanjt Posted November 15, 2010 Posted November 15, 2010 Yeah, was needed when I wrote it. Really!?!? Tool Palettes can encompass anything and unless the specified tool is set to use the current layer, instead of a predefined one, it's completely pointless. Strangeness. Quote
Lee Mac Posted November 15, 2010 Posted November 15, 2010 Really!?!? Tool Palettes can encompass anything and unless the specified tool is set to use the current layer, instead of a predefined one, it's completely pointless. Strangeness. It was for '04, so I'm not sure if that was the reason... Quote
alanjt Posted November 15, 2010 Posted November 15, 2010 It was for '04, so I'm not sure if that was the reason... Can't vouch for '04 Tool Palettes - skipped over that release. It still seems strange. Here's a simple one I use for labeling the dimensions off building corners. I went the 'modifying entlast option' but setting the current layer before and after is just as good. Probably a little less labor intensive, but I guess I didn't have my thinking cap on all the way that day. (defun c:BB (/ *error* el ov vl p1 p2 e) ;; Alan J. Thompson (defun *error* (msg) (and ov (mapcar 'setvar vl ov)) (if (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*QUIT*,"))) (princ (strcat "\nError: " msg)) ) ) (setq el (entlast)) (setq ov (mapcar 'getvar (setq vl '("CMDECHO" "OSMODE")))) (mapcar 'setvar vl '(0 1)) (if (and (setq p1 (getpoint "\nSpecify building corner: ")) (setvar 'osmode 128) (setq p2 (getpoint p1 "\nSpecify boundary line: ")) (vl-cmdf "_.dimaligned" "_non" p1 "_non" p2 "_non" PAUSE) (not (eq el (setq e (entlast)))) ) (progn (vla-put-color (vla-add (vla-get-layers (cond (*AcadDoc*) ((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object) ) ) ) ) ) "C-BLDG-DIMS" ) 10 ) (vla-put-layer (vlax-ename->vla-object e) "C-BLDG-DIMS") ) ) (*error* nil) (princ) ) Quote
CADkitt Posted November 16, 2010 Author Posted November 16, 2010 (edited) it works way better then changing the dim commands! (doesn't need to modify the old commands) I added : ("*VIEW*" "15 Viewport" 7) for the mview command, hope it doesn't screw anything up since *view* is a bit general. Mview didn't work. Edited November 16, 2010 by CADkitt Quote
Lee Mac Posted November 16, 2010 Posted November 16, 2010 it works way better then changing the dim commands! (doesn't need to modify the old commands) I added : ("*VIEW*" "15 Viewport" 7) for the mview command, hope it doesn't screw anything up since *view* is a bit general. Mview didn't work. Glad it works for you 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.