Change your current layer lisp

Change your current layer lisp

Jrooker06
Collaborator Collaborator
2,047 Views
9 Replies
Message 1 of 10

Change your current layer lisp

Jrooker06
Collaborator
Collaborator
I am trying to create a lisp where when i bring in a block on a certain layer it will change my layer after I insert the block to the layer i want to draw my lines on. For example when i bring in my receptical I have it come in on layer E-Power Devices, after i place this device i want my layer to change to E-Power Circuiting. This is the code i was working with from an old lisp that we had in the office.

;;Layers
; (setq LAY (substr LAY 1 6))
(cond
((= LAY "E-Power Devices") (setvar "CLAYER" (car (flx "E-Power Circuiting"))))
)
)

I have all my layers that pull from a DFS file so when i type in the command MAKE it will bring in all my files. Any suggets or Lisp on how to have my layer change after i insert a block?
0 Likes
2,048 Views
9 Replies
Replies (9)
Message 2 of 10

Kent1Cooper
Consultant
Consultant

Not knowing what your (flx) function does, nor how the LAY variable is set, I could suggest the "usual" way of doing something like this.  But first:

That looks like it's for getting circuiting linework on the appropriate Layer depending on what the current Layer is, presumably meaning what kind of thing has been most recently Inserted.  Do you always want to go directly and immediately from a Block insertion to adding its associated linework?  If so, you can build both into one routine, including setting the Layer for each part, which means no check on the current Layer would be needed.  Or might you sometimes Insert multiple such Blocks, without linework in between, and then call up the linework part only when you're done with those Blocks, in a separate routine?  Would you need any kind of "safeguard" against starting the linework routine at any other time, i.e. if the current Layer might not be one of those accounted for in its Layer-checking (cond) function?

 

Another thing people sometimes have Block-Insertion routines do is to Insert the Block on whatever the current Layer happens to be, and include changing its Layer immediately afterwards to the appropriate one.  That eliminates the saving of the current Layer first, setting of it to the Layer for the Block, and resetting of it afterwards [if you feel the need to do that -- it's considered good practice but depends on your way of working].  That may serve you well for the Blocks, but maybe not for the linework, if that would involve an indeterminate number of Lines/Arcs/Polylines/etc., maybe also circuit designations of some kind -- for such a situation, presumably you would want to set the Layer current first.

Kent Cooper, AIA
0 Likes
Message 3 of 10

Jrooker06
Collaborator
Collaborator

If i understand you correctly i want to go directly and immediately from a Block insertion to adding its associated linework.

 

so the recepticale lives in our library with a DFS file called power that tells it what layer, rotation, dimscale i want it to be on. The DFS file named BNACAD is the file that pulls in the all our colors and layers. we use a coomand called SS to bring up our Symbol Library that will allow us to pick a block from to use.

 

(defun C:SS ( / ) (symbol_library nil 0 "Symbols"))

 

What is FLX(?)?

0 Likes
Message 4 of 10

Jrooker06
Collaborator
Collaborator

In your third paragraph kent1cooper you talked about inserting the block on the current layer and saving it the changing the layer after. "Insert the Block on whatever the current Layer happens to be, and include changing its Layer immediately afterwards to the appropriate one". how do i achieve this?

 

 

my flx command is

 

;;Find Layer List Definition.
(defun FLX ( LAYER / FIN LIB )
  (foreach N (make_list "C:BNA LAYERS") (if (= (car N) LAYER) (setq LIB "C:BNA LAYERS")))
  (foreach N (make_list LIB) (if (= (car N) LAYER) (setq FIN N)))
  (if FIN
    (progn
      (make_layer FIN)
      FIN
    )
    (alert "Layer does not exist in database")
  )
)
0 Likes
Message 5 of 10

Kent1Cooper
Consultant
Consultant

@Jrooker06 wrote:

In your third paragraph kent1cooper you talked about .... "Insert the Block on whatever the current Layer happens to be, and include changing its Layer immediately afterwards to the appropriate one". how do i achieve this?

.... 


Something like:

 

(command

  "_.insert" "YourBlockName" pause "" "" pause

  "_.chprop" "_last" "" "_layer" "YourLayerName" ""

); command

 

That assumes you want the User to designate the insertion point and rotation in the process [the pauses], scale factors of 1, and no Attributes.  You can replace the pauses with variables if appropriate, and the scale factors with something like (getvar 'dimscale), and/or use just one, depending on how the Blocks are defined.

 

To get the full picture, we would also like to see the definitions of your (make_list) and (make_layer) functions, though I can sort of imagine what they do.

Kent Cooper, AIA
0 Likes
Message 6 of 10

Jrooker06
Collaborator
Collaborator

Would i have to create this for every block that i use? what do you mean by command?

 

This is the lisp that i use for my make command that brings in my layers.

 

;;Make BNA LAYERS Layers.
(defun C:MAKE ( / )
  (foreach N (make_list "C:BNA LAYERS") (make_layer N))
  (princ)
)

and this is the DFS file with all of the layer

 

C:BNA LAYERS
Layer,Color,Linetype,
0,7,CONTINUOUS,
DEFPOINTS,157,CONTINUOUS,
E-1LINE,93,CONTINUOUS,
E-1NOTE,152,CONTINUOUS,
E-1LINE (EXISTING),210,CONTINUOUS,
E-1NOTE (EXISTING),211,CONTINUOUS,
E-BNA-LOGO,192,CONTINUOUS,
E-COMMUNICATION,212,CONTINUOUS,
E-COMMUNICATION CIRCUIT,212,CONTINUOUS,
E-CONTROL PANEL,12,CONTINUOUS,
E-DETAIL,172,CONTINUOUS,
E-DIMENSIONS,52,CONTINUOUS,
E-EXIT SIGNS,153,CONTINUOUS,
E-FIRE ALARM DEVICES,132,CONTINUOUS,
E-FIRE ALARM CIRCUIT,4,CONTINUOUS,
E-GRID,50,CENTER,
E-KEYNOTE,212,CONTINUOUS,
E-LIGHTING CIRCUIT,172,CONTINUOUS,
E-LIGHTING DEVICES,153,CONTINUOUS,
E-LIGHTING SITE,153,CONTINUOUS,
E-LIGHTNING,13,CONTINUOUS,
E-MATCH LINE,174,PHANTOM,
E-MECHANICAL UNIT,192,HIDDEN,
E-NOTE,152,CONTINUOUS,
E-POWER CABLE TRAY,232,CONTINUOUS,
E-POWER CIRCUIT,12,CONTINUOUS,
E-POWER DEVICES,232,CONTINUOUS,
E-POWER PANEL,233,CONTINUOUS,
E-REV 1 CLOUD,53,CONTINUOUS,
E-REV 1 DELTA,232,CONTINUOUS,
E-REV 2 CLOUD,53,CONTINUOUS,
E-REV 2 DELTA,232,CONTINUOUS,
E-ROOM NAME,31,CONTINUOUS,
E-SCHEDULES,152,CONTINUOUS,
E-SECURITY DEVICES,92,CONTINUOUS,
E-SECURITY CIRCUIT,112,CONTINUOUS,
E-SOUND DEVICES,32,CONTINUOUS,
E-SOUND CIRCUIT,52,CONTINUOUS,
E-TITLE BLOCK,12,CONTINUOUS,
E-TITLE TEXT,152,CONTINUOUS,
.

C:SD
Scale,Dimscale,Linetype,Text,Zoom,
 , , , , ,
1/2,24,12,2,0.0417XP,
3/8,32,16,2.7,0.0313XP,
1/4,48,24,4,0.02084XP,
3/16,64,32,5.3,0.0156XP,
1/8,96,48,8,0.0104166XP,
3/32,128,64,10.7,0.0078125XP,
1/16,192,96,16,0.0052083XP,
10,120,60,10,0.0083333XP,
20,240,120,20,0.004160XP,
30,360,180,30,0.0027777XP,
40,480,240,40,0.0020833XP,
50,600,300,50,0.0016666XP,
60,720,360,60,0.0013888XP,
100,1200,600,100,0.0008333XP,
1-line,1,0.5,100,0.0008333XP,
.

C:SYM
Librarys,
New Folder,
Kmart,
ModelBox,
Dfcm,
Bna,
Symbols,
NPS,
.

I really dont understand the C:SD and the C:SYM part of it or why there is a period at the bottom of all three



0 Likes
Message 7 of 10

Kent1Cooper
Consultant
Consultant

@Jrooker06 wrote:

Would i have to create this for every block that i use? what do you mean by command?

....


The Block name and Layer could also be in variables, which could be fed into a single routine.  There are several ways you could handle the relationship [ask the User for both, or ask for the Block name and have a list that associates Block names with appropriate Layers, make Tool Palette items or other menu items or even a dialog box for them, probably some others].

 

The first instance of the word 'command' is the calling of the AutoLisp function to do the Insertion and Layer change, and the second is just a comment indicating what function the right parenthesis before it is closing [not necessary, and not very important in a short function like this, but sometimes helpful when a function stretches out over a lot more lines of code].

Kent Cooper, AIA
0 Likes
Message 8 of 10

Jrooker06
Collaborator
Collaborator

we use a command called SS to pull up a window that shorts and displays our symbols and we can just click on the iteam that we want. would this be our tool platte?

 

;;Symbol Library
(defun C:SS    ( / ) (symbol_library nil 0 "Symbols"))
(defun C:CIR   ( / ) (symbol_library "0" 0 "Symbols"))
(defun C:WIR   ( / ) (symbol_library "1" 0 "Symbols"))
(defun C:LIT   ( / ) (symbol_library "2" 0 "Symbols"))
(defun C:PWR   ( / ) (symbol_library "3" 0 "Symbols"))
(defun C:SND   ( / ) (symbol_library "4" 0 "Symbols"))
(defun C:FA    ( / ) (symbol_library "5" 0 "Symbols"))
(defun C:SEC   ( / ) (symbol_library "6" 0 "Symbols"))
(defun C:COM   ( / ) (symbol_library "7" 0 "Symbols"))
(defun C:PLS   ( / ) (symbol_library "8" 0 "Symbols"))
(defun C:1L    ( / ) (symbol_library "9" 0 "Symbols"))
(defun C:ARCH  ( / ) (symbol_library "10" 0 "Symbols"))
(defun C:MIS   ( / ) (symbol_library "11" 0 "Symbols"))
(defun C:OLT   ( / ) (symbol_library "12" 0 "Symbols"))
(defun C:CP    ( / ) (symbol_library "13" 0 "Symbols"))
(defun C:STP   ( / ) (symbol_library "14" 0 "Symbols"))
(defun C:JSD   ( / ) (symbol_library "15" 0 "Symbols"))
(defun C:WIND  ( / ) (symbol_library "16" 0 "Symbols"))
(defun C:TLX   ( / ) (symbol_library "17" 0 "Symbols"))
(defun C:OSND  ( / ) (symbol_library "18" 0 "Symbols"))

and that command pulls from a folder on our network drive mapped Symbols/Symbols/Power (using the power for example). Where it finds another DFS file called power.

 

name,layer,rotation,dim,xref,att1,att2,att3,
RECEPT,e-power devices,nil,nil,insert,
GFI-RECP,e-power devices,nil,nil,insert,
4-PLEX,e-power devices,nil,nil,insert,
GFI-4PLX,e-power devices,nil,nil,insert,
RECPT-SW,e-power devices,nil,nil,insert,
RECP-ISO,e-power devices,nil,nil,insert,
RCPT-SNGL,e-power devices,nil,nil,insert,
TVSS,e-power devices,nil,nil,insert,
Recept-Control,e-power devices,nil,nil,insert,
SPECL-PR,e-power devices,nil,nil,insert,
TV,e-power devices,nil,nil,insert,
CORDDRP1,e-power devices,0,nil,insert,
CORDDRP2,e-power devices,nil,nil,insert,
FLOOROUT,e-power devices,0,nil,insert,
FloorCombo01,e-power devices,nil,nil,insert,
FLRBOX4,e-power devices,nil,nil,insert,
PUSHBTN1,e-power devices,nil,nil,insert,
PWR-POLE,e-power devices,nil,nil,insert,
DISC,e-power devices,nil,nil,insert,
DISC-COM,e-power devices,nil,nil,insert,
DISC-BRK,e-power devices,nil,nil,insert,
DISC-F1,e-power devices,nil,nil,insert,
MOTOR01,e-power devices,nil,nil,insert,
MOTORRF01,e-power devices,nil,nil,insert,
MOTOR,e-power devices,0,nil,insert,
MOTOR1,e-power devices,0,nil,insert,
LV-XFMR,e-power devices,nil,nil,insert,
J-BOX-SQ,e-power devices,nil,nil,insert,
TIME-CLK,e-power devices,nil,nil,insert,
VFD,e-power devices,nil,nil,insert,
RECPSTM,e-power devices,nil,nil,insert,
Recept_com01,e-power devices,nil,nil,insert,
UNITHTR,e-power devices,nil,0,insert,
ProMnt,e-power devices,0,0,insert,J,
CLOCK,e-power devices,nil,nil,insert,C,
CLOCK-WALL,e-power devices,nil,nil,insert,C,
 ,
 ,
 ,

so would i use this to ask for the Block name and the second list would show the associate Block names with appropriate Layers?

0 Likes
Message 9 of 10

Kent1Cooper
Consultant
Consultant

Dialog-box functions and DFS files are beyond my experience.  I hope someone else will chime in to tell you how to put it together, but I'm sure the ingredients are all there.

Kent Cooper, AIA
0 Likes
Message 10 of 10

Jrooker06
Collaborator
Collaborator

where would i insert this code at in my lisp exactly?

 

(command
"_.insert" "YourBlockName" pause "" "" pause
 "_.chprop" "_last" "" "_layer" "YourLayerName" ""
); command

and thank you?

 

0 Likes