Jump to content

Lisp to change an entity layer in a nested block without entering block


Recommended Posts

Posted

Is there a lisp that allow us to change an entity layer, in a nested block, to another predefined layer eg. defpoints. without entering the block.

 

Been bogged down by continuously going in and out of the block editor /edit block in place, 50 odd times in 1 DWG just to change the layer of a few lines is exhausting. The work is already taking too Long as it is.

 

Hoping for some help.

 

Thanks.

Posted

Can you write down the steps of the program that you want the program to proceed with?

 

Also can you list the name of the nested blocks and the target layer?

Posted (edited)
Can you write down the steps of the program that you want the program to proceed with?

 

Also can you list the name of the nested blocks and the target layer?

 

Block A

 

1) Run lisp

 

2) from modelspace, select the :-

X) entity/entities of a couple of lines/polylines/circle..... continuously (which is inside Block A)

or

Y) entity/entities of a couple of lines/polylines/circle..... continuously (which is inside Block B which is Inside A) & entity/entities of a couple of lines (inside Block C which is inside Block B which is inside Block A)

 

* in both scenarios, X & Y, the selected entity/entities will be highlighted throughout the selection process regardless of which block the entitiy/entities it is from.

(As I would not know the actually block name as it is too many & with long names & different depth levels)

 

3) After the selection, Press ENTER

 

4) Selected entity/entities in both scenario X & Y will then change to "DEFPOINTS" layer

 

Target layer is DEFPOINTS. (But can change to other layer names within the lisp code)

 

Hope this can help Tharwat

Edited by Tripledot
Posted

So you need to move lines objects in nested Blocks of the selected blocks to layer DefPoints ?

Posted
So you need to move lines objects in nested Blocks of the selected blocks to layer DefPoints ?

 

Yes, mainly the entities like lines,polylines,circle......that is within blocks or nested blocks. The layers of blocks/nested blocks remains untouch.

Posted
Yes, mainly the entities like lines,polylines,circle......that is within blocks or nested blocks. The layers of blocks/nested blocks remains untouch.

How come is that ?

 

Please specify your goal of the program very strictly and clearly.

Posted
How come is that ?

 

Please specify your goal of the program very strictly and clearly.

 

Block A

 

Block A contains line 1,2 & 3

 

Currently what i am doing:

1) Using refedit, select the Block A of the lines i want to change layer.

2) Withing the block editor of Block A, select Line 1, line 2 & line 3 & change to defpoints layer

3) Saved & exit block editor

4) Using refedit, select the Block B of the lines i want to change layer.

5) Withing the block editor of Block B, select Line 4, line 5 & line 6 & change to defpoints layer

6) Saved & exit block editor

7) Using refedit, select the Block C of the lines i want to change layer.

8 ) Withing the block editor of Block C, select Line 7, line 8 & line 9 & change to defpoints layer

9) Saved & exit block editor

 

 

What i like the Lisp to do is:

1) Run Lisp

2) Select line 1, 2, 3, 4, 5,6 ,7 ,8 & 9.

3) Enter.

4) Layer of line 1, 2, 3, 4, 5,6 ,7 ,8 & 9 change to Defpoints

Posted

Why would you be moving these entities to layer Defpoints? That layer really should be restricted to its intended use.

Posted
Why would you be moving these entities to layer Defpoints? That layer really should be restricted to its intended use.

 

I need to convert the entity/entities to a separate layer,in which case, where my office have setup to have defpoints switch off so that selected entity/entities will not be seen.

 

In actuality, not necessary defpoints but since office setup this way so I follow.

 

Hence I also indicated that target layer can be change within the lisp code to offer me a flexibility.

Posted

Just for clarification:

 

When you say nested block that means a block within a block(s) so I think in your case you are talking about regular block(s) correct?

 

With lisp you can not select entities as you are selecting entities in a layout / Model space but this should be proceed by iterating through entities within the selected block(s) then change layers, colors, lineTypes ... etc.

Posted
Just for clarification:

When you say nested block that means a block within a block(s) so I think in your case you are talking about regular block(s) correct?

 

Yes. Regular nested blocks.

 

 

With lisp you can not select entities as you are selecting entities in a layout / Model space but this should be proceed by iterating through entities within the selected block(s) then change layers, colors, lineTypes ... etc.

Not sure what you mean. With lisp it is not possible?

Posted

 

Good god. This is freaking awesome! :shock:

 

(defun c:ddd ( / doc enm)
 (setq doc (vla-get-activedocument (vlax-get-acad-object)))
 (vla-endundomark doc)
 (vla-startundomark doc)
 (while (setq enm (car (nentsel)))
   (vla-put-layer (vlax-ename->vla-object enm) "defpoints")
   (vla-regen doc acactiveviewport)
 )
 (vla-regen doc acallviewports)
 (vla-endundomark doc)
 (princ)
)

Could i trouble you to add the code in the lisp to allow for predefine Linetype & colour override.

 

Thanks Roy_043

Posted
(defun c:ddd ( / doc enm obj)
 (setq doc (vla-get-activedocument (vlax-get-acad-object)))
 (vla-endundomark doc)
 (vla-startundomark doc)
 (while (setq enm (car (nentsel)))
   (setq obj (vlax-ename->vla-object enm))
   (vla-put-layer    obj "Defpoints") ; Layer must exist.
   (vla-put-color    obj 11)
   (vla-put-linetype obj "Hidden")    ; Linetype must exist.
   (vla-regen doc acactiveviewport)
 )
 (vla-regen doc acallviewports)
 (vla-endundomark doc)
 (princ)
)

Posted
(defun c:ddd ( / doc enm obj)
 (setq doc (vla-get-activedocument (vlax-get-acad-object)))
 (vla-endundomark doc)
 (vla-startundomark doc)
 (while (setq enm (car (nentsel)))
   (setq obj (vlax-ename->vla-object enm))
   (vla-put-layer    obj "Defpoints") ; Layer must exist.
   (vla-put-color    obj 11)
   (vla-put-linetype obj "Hidden")    ; Linetype must exist.
   (vla-regen doc acactiveviewport)
 )
 (vla-regen doc acallviewports)
 (vla-endundomark doc)
 (princ)
)

 

Got an error

Command: ddd

 

Select object: ; error: Automation Error. Key not found

Posted

As I mentioned in the comments: the layer and the linetype must exist in the dwg. Most likely that is the cause of your error.

Posted
As I mentioned in the comments: the layer and the linetype must exist in the dwg. Most likely that is the cause of your error.

 

Forgot about the linetype. :oops:.

 

Working good now.

 

Thanks Roy_043

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