Jump to content

Change the object layer of block to on which the block is inserted


symoin

Recommended Posts

Hai all,

 

I have a drawing that has many blocks, the problem is that the layer of objects contained inside the blocks are different from the layer on which the block is inserted. is there any lisp that can change the object layer to the block insertion layer.

 

attach is the drawing for reference.

Thanks in advance.

block-layers.dwg

Link to comment
Share on other sites

I have a drawing that has many blocks, the problem is that the layer of objects contained inside the blocks are different from the layer on which the block is inserted. is there any lisp that can change the object layer to the block insertion layer.

 

Sounds like you would rather want to change all objects within the block to layer "0" so that they may inherit whatever layer the block is placed.

Link to comment
Share on other sites

Consider this function perhaps:

 

[color=#990099];;---------------=={ Apply to Block Objects }==---------------;;[/color]
[color=#990099];;                                                            ;;[/color]
[color=#990099];;  Applies a supplied function to all objects in a block     ;;[/color]
[color=#990099];;  definition.                                               ;;[/color]
[color=#990099];;------------------------------------------------------------;;[/color]
[color=#990099];;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;[/color]
[color=#990099];;------------------------------------------------------------;;[/color]
[color=#990099];;  Arguments:                                                ;;[/color]
[color=#990099];;  _blockname - name of block to apply function              ;;[/color]
[color=#990099];;  _function  - function to apply to all objects in block    ;;[/color]
[color=#990099];;------------------------------------------------------------;;[/color]
[color=#990099];;  Returns:  T if block is found, else nil                   ;;[/color]
[color=#990099];;------------------------------------------------------------;;[/color]

[color=RED]([/color][color=BLUE]defun[/color] [color=black]LM:ApplytoBlockObjects[/color] [color=RED]([/color] _blockname _function [color=RED])[/color]
 [color=RED]([/color][color=BLUE]vl-load-com[/color][color=RED])[/color]
 [color=#990099];; © Lee Mac 2010[/color]
 [color=RED]([/color]
   [color=RED]([/color][color=BLUE]lambda[/color] [color=RED]([/color] _function [color=BLUE]/[/color] def [color=RED])[/color]  
     [color=RED]([/color][color=BLUE]if[/color]
       [color=RED]([/color][color=BLUE]not[/color]
         [color=RED]([/color][color=BLUE]vl-catch-all-error-p[/color]
           [color=RED]([/color][color=BLUE]setq[/color] def
             [color=RED]([/color][color=BLUE]vl-catch-all-apply[/color] [color=DARKRED]'[/color][color=BLUE]vla-item[/color]
               [color=RED]([/color][color=BLUE]list[/color]
                 [color=RED]([/color][color=BLUE]vla-get-blocks[/color]
                   [color=RED]([/color][color=BLUE]vla-get-ActiveDocument[/color] [color=RED]([/color][color=BLUE]vlax-get-acad-object[/color][color=RED]))[/color]
                 [color=RED])[/color]
                 _blockname
               [color=RED])[/color]
             [color=RED])[/color]
           [color=RED])[/color]
         [color=RED])[/color]
       [color=RED])[/color]
       [color=RED]([/color][color=BLUE]vlax-for[/color] obj def [color=RED]([/color]_function obj[color=RED]))[/color]
     [color=RED])[/color]
   [color=RED])[/color]
   [color=RED]([/color][color=BLUE]eval[/color] _function[color=RED])[/color]
 [color=RED])[/color]
[color=RED])[/color]


[color=#990099];; Test Function to Move all Objects in a Block to Layer "0"[/color]

[color=RED]([/color][color=BLUE]defun[/color] [color=black]c:test[/color] [color=RED]([/color] [color=BLUE]/[/color] ss l [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]"_+.:E:S"[/color] [color=DARKRED]'[/color][color=RED](([/color][color=#009900]0[/color] [color=DARKRED].[/color] [color=#a52a2a]"INSERT"[/color][color=RED]))))[/color]
   [color=RED]([/color][color=BLUE]progn[/color]    
     [color=RED]([/color][color=black]LM:ApplytoBlockObjects[/color] [color=RED]([/color][color=BLUE]cdr[/color] [color=RED]([/color][color=BLUE]assoc[/color] [color=#009900]2[/color] [color=RED]([/color][color=BLUE]setq[/color] l [color=RED]([/color][color=BLUE]entget[/color] [color=RED]([/color][color=BLUE]ssname[/color] ss [color=#009900]0[/color][color=RED])))))[/color]
       [color=RED]([/color][color=BLUE]function[/color]
         [color=RED]([/color][color=BLUE]lambda[/color] [color=RED]([/color] obj [color=RED])[/color] [color=RED]([/color][color=BLUE]vla-put-Layer[/color] obj [color=#a52a2a]"0"[/color][color=RED]))[/color]
       [color=RED])[/color]
     [color=RED])[/color]
     [color=RED]([/color][color=BLUE]if[/color] [color=RED]([/color][color=BLUE]=[/color] [color=#009900]1[/color] [color=RED]([/color][color=BLUE]cdr[/color] [color=RED]([/color][color=BLUE]assoc[/color] [color=#009900]66[/color] l[color=RED])))[/color]
       [color=RED]([/color][color=BLUE]vl-cmdf[/color] [color=#a52a2a]"_.attsync"[/color] [color=#a52a2a]"_N"[/color] [color=RED]([/color][color=BLUE]cdr[/color] [color=RED]([/color][color=BLUE]assoc[/color] [color=#009900]2[/color] l[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]

Link to comment
Share on other sites

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