PDA

View Full Version : Changing color of circles in Blocks only



Michaels
19th Feb 2011, 09:06 am
hello .

I wonder why these codes are changing all circles in my dwg to color 1 and not only these in blocks , although that I included them within the Block definition only ?



(vlax-for blocks (vla-get-blocks (setq M:cad (vla-get-activedocument (vlax-get-acad-object))))
(vlax-for o blocks
(if (wcmatch (vla-get-objectname o) "AcDbCircle")
(vla-put-color o 1))
)
)
(vla-regen M:cad acActiveViewport)
Thanks in Advance.

pBe
19th Feb 2011, 11:08 am
hello .

I wonder why these codes are changing all circles in my dwg to color 1 and not only these in blocks , although that I included them within the Block definition only ?



(vlax-for blocks (vla-get-blocks (setq M:cad (vla-get-activedocument (vlax-get-acad-object))))
(vlax-for o blocks
(if (wcmatch (vla-get-objectname o) "AcDbCircle")
(vla-put-color o 1))
)
)
(vla-regen M:cad acActiveViewport)
Thanks in Advance.

This is included in the process:

#<VLA-OBJECT IAcadPaperSpace2 20a13134> <----- all objects on paperspace
#<VLA-OBJECT IAcadModelSpace2 20a16d34> <------all objects on modelspace


Try something like this




(vlax-for blocks (vla-get-blocks (setq M:cad (vla-get-activedocument (vlax-get-acad-object))))
(if (not (wcmatch (vla-get-name blocks) "*Paper*,*Model*"))
(vlax-for o blocks
(if (wcmatch (vla-get-objectname o) "AcDbCircle")
(vla-put-color o 1))
)
)
)

:)

Lee Mac
19th Feb 2011, 03:34 pm
Another way to check would be:


(vlax-for block
(vla-get-blocks
(vla-get-activedocument
(vlax-get-acad-object)
)
)
(if
(and
(eq :vlax-false (vla-get-isLayout block))
(eq :vlax-false (vla-get-isXref block))
)
(vlax-for obj block
(if (eq "AcDbCircle" (vla-get-objectname obj))
(vla-put-color obj 1)
)
)
)
)

Michaels
19th Feb 2011, 04:21 pm
So nice , Thank you pBe and Lee .:)

So I should have excluded the paper and Model spaces while trying to change the entities in block's definitions only. Right ?

Appreciated.

Lee Mac
19th Feb 2011, 04:38 pm
So I should have excluded the paper and Model spaces while trying to change the entities in block's definitions only. Right ?

Correct (I would also exclude Xrefs too).

The ModelSpace/PaperSpace objects are also included in the Blocks collection, containing all the objects in Model space and Paper space respectively, hence by iterating through these block definitions you are iterating through all the objects in Model and Paper space.

Lee

pBe
20th Feb 2011, 04:38 am
Correct (I would also exclude Xrefs too).

The ModelSpace/PaperSpace objects are also included in the Blocks collection, containing all the objects in Model space and Paper space respectively, hence by iterating through these block definitions you are iterating through all the objects in Model and Paper space.

Lee

Thats right, learned that the hard way too :)

Lee Mac
20th Feb 2011, 02:17 pm
Thats right, learned that the hard way too :)

At least you'll never forget it now :wink: