lisp program to set up typical layout tabs

lisp program to set up typical layout tabs

Anonymous
Not applicable
1,457 Views
17 Replies
Message 1 of 18

lisp program to set up typical layout tabs

Anonymous
Not applicable

Hello, Im new to lisp and im trying to create a lisp program that goes through my typical layout tabs and sets up the layers to be frozen or thawed.

 

 

I would like to switch to each layout tab and set things up automatically 

1. set to model space

2. thaw the layers needed 

 

Leaving layer 1 on at all times for my border. 

 

and skip error's if a layout tab is missing. 

 

(setvar "ctab" "front elevation")(command "_.mspace")(command "vplayer" "f" "~1" "")(command "vplayer" "thaw" "e" "")
(princ))
(setvar "ctab" "rear elevation")(command "_.mspace")(command "vlayer" "f" "~1" "")(command "layer" "thaw" "er" "")
(princ))
(setvar "ctab" "right elevation")(command "_.mspace")(command "vlayer" "f" "~1" "")(command "-layer" "thaw" "es" "")
(princ))(ignore-errors)

Can anyone here help me to get started?  Thanks

 

0 Likes
1,458 Views
17 Replies
Replies (17)
Message 2 of 18

ВeekeeCZ
Consultant
Consultant

try this...

 

Spoiler
(defun c:Test nil
    
  (if (member "front elevation" (layoutlist)) ; it's case sensitive
    (progn
      (setvar "ctab" "front elevation")
      (if (= (getvar "cvport") 1) (command "_.mspace"))
      (command "_.vplayer"
	       "f" "~1" ""
	       "thaw" "e" "" "")
      (command "_.pspace")
      ))
  
  (if (member (strcase "Rear elevation") (mapcar 'strcase (layoutlist))) ; not case sensitive
    (progn
      (setvar "ctab" "rear elevation")
      (if (= (getvar "cvport") 1) (command "_.mspace"))
      (command "_.vplayer"
	       "f" "~1" ""
	       "thaw" "er" "" "")
      (command "_.pspace")
      ))
  
  (if (member "right elevation" (layoutlist))
    (progn
      (setvar "ctab" "right elevation")
      (if (= (getvar "cvport") 1) (command "_.mspace"))
      (command "_.vplayer"
	       "f" "~1" ""
	       "thaw" "es" "" "")
      (command "_.pspace")
      ))
  
  (setvar "ctab" "Model")
  
  (princ)
)

The first example is case sensitive, the second is not.

Message 3 of 18

Anonymous
Not applicable

IT seems to work well, thanks a million. this will save major time

 

(defun c:Test nil

(if (member "FRONT ELEVATION" (layoutlist)) ; it's case sensitive
(progn
(setvar "ctab" "FRONT ELEVATION")
(if (= (getvar "cvport") 1) (command "_.mspace"))
(command "_.vplayer"
"f" "~1" ""
"thaw" "e" "" "")
))

(if (member (strcase "REAR ELEVATION") (mapcar 'strcase (layoutlist))) ; not case sensitive
(progn
(setvar "ctab" "REAR ELEVATION")
(if (= (getvar "cvport") 1) (command "_.mspace"))
(command "_.vplayer"
"f" "~1" ""
"thaw" "er" "" "")
))

(if (member "RIGHT ELEVATION" (layoutlist))
(progn
(setvar "ctab" "RIGHT ELEVATION")
(if (= (getvar "cvport") 1) (command "_.mspace"))
(command "_.vplayer"
"f" "~1" ""
"thaw" "es" "" "")
))

(setvar "ctab" "COVER")

(princ)
)

 

 

I like to stay in model space, and then go back to the cover once I have all layout tabs setup.  Awesome

 

 

0 Likes
Message 4 of 18

Anonymous
Not applicable

the next question would be, how do I thaw multiple layers?

 

(defun c:Test nil

(if (member "FRONT ELEVATION" (layoutlist)) ; it's case sensitive
(progn
(setvar "ctab" "FRONT ELEVATION")
(if (= (getvar "cvport") 1) (command "_.mspace"))
(command "_.vplayer"
"f" "~1" ""
"thaw" "e" "" "")
))

(if (member (strcase "REAR ELEVATION") (mapcar 'strcase (layoutlist))) ; not case sensitive
(progn
(setvar "ctab" "REAR ELEVATION")
(if (= (getvar "cvport") 1) (command "_.mspace"))
(command "_.vplayer"
"f" "~1" ""
"thaw" "er" "" "")
))

(if (member "RIGHT ELEVATION" (layoutlist))
(progn
(setvar "ctab" "RIGHT ELEVATION")
(if (= (getvar "cvport") 1) (command "_.mspace"))
(command "_.vplayer"
"f" "~1" ""
"thaw" "es" "" "")
))

(if (member "1ST FLOOR PLAN" (layoutlist))
(progn
(setvar "ctab" "1ST FLOOR PLAN")
(if (= (getvar "cvport") 1) (command "_.mspace"))
(command "_.vplayer"
"f" "~1" ""
"thaw" "0" "" ""
"thaw" "2" "" "" )
))

(setvar "ctab" "COVER")

(princ)
)

0 Likes
Message 5 of 18

ВeekeeCZ
Consultant
Consultant

@Anonymous wrote:

the next question would be, how do I thaw multiple layers?

 

...

Use a comma as delimiter.

"0,2"

Message 6 of 18

Anonymous
Not applicable

would it be possible to add a command to unlock all layers?

(if (member "1ST FLOOR PLAN" (layoutlist))
(progn
(setvar "ctab" "1ST FLOOR PLAN")
(if (= (getvar "cvport") 1) (command "_.mspace"))
(command "_.vplayer"
"f" "~1" ""
"thaw" "0,2" "" "")
))

0 Likes
Message 7 of 18

ВeekeeCZ
Consultant
Consultant

@Anonymous wrote:

would it be possible to add a command to unlock all layers?

(if (member "1ST FLOOR PLAN" (layoutlist))
(progn
(setvar "ctab" "1ST FLOOR PLAN")
(if (= (getvar "cvport") 1) (command "_.mspace"))
(command "_.vplayer"
"f" "~1" ""
"thaw" "0,2" "" "")
))

 

(command "_.layer" "_unlock" "*" "") ; not inside of (if...) and once would be enough


It's not VP related, so use the regular layer command. You don't have to use dash in lisp even in autocad's command line you need it to evoke a command line version of a command.

 

(command "_.layer" "_unlock" "*" "")



0 Likes
Message 8 of 18

Anonymous
Not applicable

You really know your stuff.  I keep adding things to the script. 

 

(if (member "COVER" (layoutlist)) ; it's case sensitive
(progn
(setvar "ctab" "COVER")
(if (= (getvar "cvport") 1) (command "_.mspace"))
(command "_.vplayer"
"f" "~1" ""
"thaw" "COVER" "" "")
(command "-vports" "Lo" "on" "ALL" "")
(command "zoom" "e")
))

 

Would it be possible to have the left hand corner of the layout tab view at 0,0

And scale the drawing to 3/16" = 1" before I zoom extents?

0 Likes
Message 9 of 18

Anonymous
Not applicable

I'm still trying to get the lower left corner of the view port to stay at 0,0 when I zoom to scale. 

 

(if (member "COVER" (layoutlist)) ; it's case sensitive
(progn
(setvar "ctab" "COVER")
(if (= (getvar "cvport") 1) (command "_.mspace"))
(command "_.vplayer"
"f" "~1" ""
"thaw" "COVER" "" "")
(command "-vports" "Lo" "off" "ALL" "")
(command "zoom" (strcat "1/48" "" "XP")) ; = 1/4" scale viewport
(command "-vports" "Lo" "on" "ALL" "")
(command "zoom" "e")
))

0 Likes
Message 10 of 18

ВeekeeCZ
Consultant
Consultant

@Anonymous wrote:

I'm still trying to get the lower left hand corner of the view port to stay at 0,0 when I zoom to scale. 

...


Good that you figured the zoom.

 

Then use PAN command. Calculation of the lower left corner is not that simple, but I think you can manage that too. The manual you can find HERE Use some variables and little math. Or use the spoiler - but there it's not that obvious.

 

Spoiler
(command "_.PAN" '(0 0 0) (mapcar '- (getvar 'VIEWCTR) (mapcar '(lambda (x) (* (getvar 'VIEWSIZE) 0.5 x)) (list (apply '/ (getvar 'SCREENSIZE)) 1))))
Message 11 of 18

Anonymous
Not applicable

Would the vla-put-center method be easier? 

0 Likes
Message 12 of 18

ВeekeeCZ
Consultant
Consultant

@Anonymous wrote:

Would the vla-put-center method be easier? 


I doubt it. You still need to count some point. Those five steps is not difficult to follow. 

Message 13 of 18

Anonymous
Not applicable

This might take a week or two.. 🙂

 

;;VIEWSIZE = 41'-6 15/16" (read only)
;;VIEWCTR = 34'-1 1/16",21'-0 5/16",0'-0" (read only)
;;SCREENSIZE = 82'-1",51'-6" (read only)

0 Likes
Message 14 of 18

Anonymous
Not applicable

the conversion part is not explained? or is it? 

 

Capture.JPG

0 Likes
Message 15 of 18

Anonymous
Not applicable

The DCS to WCS conversion seems complicated. And Capture.JPGI think that I had some things mixed up on my spreed sheet. 

 

 

0 Likes
Message 16 of 18

ВeekeeCZ
Consultant
Consultant

@Anonymous wrote:

The DCS to WCS conversion seems complicated. And 

...


You're right, it is... matrix calculation... But, if you don't rotate your viewport, you don't need it. Actually my solution from spoiler in post #10 does not include it. But if you decide to do that, we have simple built-in function for that HERE

 

I don't do how much you're adept with basic functions... so here are some hints...

 

step 1

Spoiler
(getvar), (setq), (trans)

step 4 

Spoiler
(car) (last)

step 5

Spoiler
(list)
Message 17 of 18

Anonymous
Not applicable

Thanks again for helping me to write my routine that sets up my view ports to standard defaults. It saved me a lot of time today. I will work on the panning part of it this weekend. If I can't figure it out then that is ok too. I really don't think that I need it at this point. 

 

Peace,, Nick

 

 

0 Likes
Message 18 of 18

Anonymous
Not applicable

all man ,, you actually gave me the code.. It takes awhile to click sometimes.  lol.  Smiley Very Happy

Spoiler
 
0 Likes