Hi,
Sorry if this has been covered before, I'm new to lisp and my search on the board didn't give me any help.
Basicaly I'm trying to build a lisp routine that will insert a block from the toolpallete but each time it is entered it put in on a new layer.
We have created a dynamic scale bar that sits within model space so when a drawing is plotted we can check the scale is correct. But with multiple viewports they end up showing all over the place so we place them on different layers Scale Bar 1. scale bar 2, etc... and just freeze them off in different view. Idealy the new layer would be frozzen in all viewports as defult (layer creation setting I think)
Can anyone help with this.?
Thanks
Chris
Solved! Go to Solution.
Solved by CRThorn. Go to Solution.
Solved by Kent1Cooper. Go to Solution.
Chris,
take a look at this code:
(defun c:insert_scale_bar (/ taglay) ; using USERS1 sysvar to store default layer (if (eq (getvar "users1") "") (setvar "users1" (getvar "clayer")) ) ; tarlay is target layer (if (eq (setq tarlay (getstring (strcat "\nScale bar layer name <" (getvar "users1") ">: "))) "") (setq tarlay (getvar "users1")) (setvar "users1" tarlay) ) (command "._layer" "make" tarlay "" "._insert" "scale_bar" pause pause pause) (princ) )
of course you can specify a pre defined X-Scale and Y-Scale factor and Rotation angle for your scale bar or
figure it out by your current drawing scale factor.
cheers
Moshe
@Anonymous wrote:....
Basicaly I'm trying to build a lisp routine that will insert a block from the toolpallete but each time it is entered it put in on a new layer.
We have created a dynamic scale bar ... we place them on different layers Scale Bar 1. scale bar 2, etc... and just freeze them off in different view. Idealy the new layer would be frozzen in all viewports as defult (layer creation setting I think)
....
For the sequential Layers and Block insertions, something like this, perhaps, assuming you're not using the USERI5 System Variable for anything else:
(command
"_.layer" "_make" (strcat "Scale Bar " (setvar 'USERI5 (1+ (getvar 'USERI5))))
"_.insert" "YourBlockName" pause "" "" ""
;; adjust scales/rotation as needed, and/or deal with attributes, any dynamic aspects, etc.
)
(entmod (subst '(70 . 2) '(70 . 0) (entget (tblobjname "layer" (getvar 'clayer)))))
The first time you do that, if USERI5 hasn't been used and is at its default value of 0, it will make a Layer called "Scale Bar 1" and put the Block on it, and set USERI5 to 1, so that the next time, it will be "Scale Bar 2", etc. The value of using a USERIx System Variable is that it's saved in the drawing, so the sequence will continue even after you've closed the drawing and gotten back into it later.
The last line is to set the new Layer to be frozen in any new Viewports. As to having it frozen in all pre-existing ones except where you put it, I think that would be complicated, if even possible by Lisp, but I haven't worked with that kind of thing, so I'd have to experiment.
Thanks,
I'll have aplay with these during the week and let you know how it goes.
Chris