Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

sequential layer name and creation

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
CRThorn
584 Views, 4 Replies

sequential layer name and creation

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

4 REPLIES 4
Message 2 of 5
Moshe-A
in reply to: CRThorn

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

 

 

 

 

Message 3 of 5
Kent1Cooper
in reply to: CRThorn


@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.

Kent Cooper, AIA
Message 4 of 5
CRThorn
in reply to: Kent1Cooper

Thanks,

 

I'll have aplay with these during the week and let you know how it goes.

 

Chris

Message 5 of 5
CRThorn
in reply to: CRThorn

Thanks that did the trick nicely

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost