Jump to content

How to change block on the correct later?


Recommended Posts

Posted

I'm new on autocad and no lisp knowledge what so ever.

 

Here is my problem. "M-duct" layer is my default drawing layer. Each time I inserted a block it obviously inserted the block on that layer. I just want a lisp routine to put my inserted thermostat block to "M-Thermostat" layer. All entities on that block are on the "M-Thermostat" layer. I don't need it instantly to change the block on the right layer. Perhaps run the routine before I close and save the the drawing. i'm tired on isolating layers eg. thermostat, diffusers, text etc.. and putting them on the right layer. Any help would be appreciated. Thank you.

Posted

Heres a couple of ways to do it

 

If you have a limited number of blocks you could have a menu or a toolbar with these blocks on it the command behind the menu would be something like

^c^c-la s M-thermostat insert M-thermostat

 

We use a slide menu system and pick by name or picture again the command as above

 

The current method being pushed is to use tool palletes

 

Also if a small number of blocks they could be commands say mt1 which would set layer and insert thermostat block 1 this would be a bit of lisp code

(defun c:mt1 ()
(command "layer" "S" "m-thermostat "" "insert" "M-thermostat")) 

Posted

Maybe all you need to do is in your thermostat.dwg to make sure all the entities are on the right layer then when you bring it in it will automatically be on that layer. eg the block will not but the entities behind the block will be. So you will be able to view the layer and this block will show up. Then hopefully no lisp will be required.

 

If this is not what you want you really need to create/ be in that layer and then insert the block - for both manually and by lisp.

Posted

I don't use palettes or toolbar it just slows me down especially when the palette is not dock, my autocad become sluggies. I use around 800 different blocks in my drawing so putting them in a palette is not an option.

 

Grant,

 

I avoid exploding or bursting blocks it just make my working file bigger. When I exploded all my blocks in my drawing the file size jumps from 7mb to 16mb. All person xrefing my drawing file wanted to kill me.

Posted

I suppose you *could* write a lisp that would automatially select all of the blocks in your file then process through each one getting the block's name and layer before comparing the block's name with a "lookup table" (saying what layer each block should be on) and changing the layer if necessary.

 

Obviously not the easiest programme to write (especially as this is your first lisp - sure beats "hello world"!!) but like all programming is about reducing it to baby steps. Of course you'd need that list of 800 blocks and their layer.

 

dJE

 

I would add that tool pallettes are quicker than one might think, once you get used to them. Certainly no slower than INSERT.BROWSE..OK.OK...

Posted

Perhaps something simple along these lines to get you started:

 

[color=RED]([/color][color=BLUE]defun[/color] c:test [color=RED]([/color] [color=BLUE]/[/color] block layer ss i [color=RED])[/color]

 [color=#990099];; Example by Lee Mac 2011  -  www.lee-mac.com[/color]

 [color=RED]([/color][color=BLUE]setq[/color] block [color=#a52a2a]"test"[/color]   [color=#990099];; Block Name[/color]
       layer [color=#a52a2a]"layer"[/color]  [color=#990099];; Layer Name (will be created if non-existent)[/color]
 [color=RED])[/color]

 [color=RED]([/color][color=BLUE]if[/color]
   [color=RED]([/color][color=BLUE]setq[/color] ss
     [color=RED]([/color][color=BLUE]ssget[/color] [color=#a52a2a]"_X"[/color]
       [color=RED]([/color][color=BLUE]list[/color] [color=RED]([/color][color=BLUE]cons[/color] [color=#009900]0[/color] [color=#a52a2a]"INSERT"[/color][color=RED])[/color] [color=RED]([/color][color=BLUE]cons[/color] [color=#009900]2[/color] block[color=RED])[/color] [color=RED]([/color][color=BLUE]cons[/color] [color=#009900]8[/color] [color=RED]([/color][color=BLUE]strcat[/color] [color=#a52a2a]"~"[/color] layer[color=RED])))[/color]
     [color=RED])[/color]
   [color=RED])[/color]
   [color=RED]([/color][color=BLUE]repeat[/color] [color=RED]([/color][color=BLUE]setq[/color] i [color=RED]([/color][color=BLUE]sslength[/color] ss[color=RED]))[/color]
     [color=RED]([/color]
       [color=RED]([/color][color=BLUE]lambda[/color] [color=RED]([/color] elist [color=RED])[/color]
         [color=RED]([/color][color=BLUE]entupd[/color]
           [color=RED]([/color][color=BLUE]cdr[/color]
             [color=RED]([/color][color=BLUE]assoc[/color] [color=#009900]-1[/color]
               [color=RED]([/color][color=BLUE]entmod[/color]
                 [color=RED]([/color][color=BLUE]subst[/color] [color=RED]([/color][color=BLUE]cons[/color] [color=#009900]8[/color] layer[color=RED])[/color] [color=RED]([/color][color=BLUE]assoc[/color] [color=#009900]8[/color] elist[color=RED])[/color] elist[color=RED])[/color]
               [color=RED])[/color]
             [color=RED])[/color]
           [color=RED])[/color]
         [color=RED])[/color]
       [color=RED])[/color]
       [color=RED]([/color][color=BLUE]entget[/color] [color=RED]([/color][color=BLUE]ssname[/color] ss [color=RED]([/color][color=BLUE]setq[/color] i [color=RED]([/color][color=BLUE]1-[/color] i[color=RED]))))[/color]
     [color=RED])[/color]
   [color=RED])[/color]
 [color=RED])[/color]

 [color=RED]([/color][color=BLUE]princ[/color][color=RED])[/color]
[color=RED])[/color]

 

Change the block/layer name at the top to suit.

Posted

Thanks Lee. that works! but it only change one block(name) on the layer. Let say I have 6 diffuser/blocks, all lines in those blocks are on Layer "M-diffuser". I want all those blocks to be put on "m-diffuser" layer.

Posted
... but it only change one block(name) on the layer.

 

something simple along these lines to get you started

 

Let say I have 6 diffuser/blocks, all lines in those blocks are on Layer "M-diffuser". I want all those blocks to be put on "m-diffuser" layer.

 

Change the block name to "block1,block2,block3"

 

You can also use wildcards, hence "block#" or maybe "block*"

Posted

Or try my BlockLayers.LSP. You set it up using the BlockLayers command - this saves the block-&-layer combinations to registry. Then you need to StartBlockLayer. After which if you insert any block in any way, it will update that block to the preset layer (if such was set in the BlockLayer command).

 

The easiest way to setup is to use a template with all your blocks already on the correct layers. Then use BlockLayer's Select option and select across all the blocks.

 

Note, for it to work all the time you need to have it loaded for each DWG and StartBlockLayer called as well. To do this you could add the following to your AcadDoc.LSP file:

(load "BlockLayer" nil)
(c:StartBlockLayer)

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...