Jump to content
Apache2k

Nest Blocks and Entity color loop

Recommended Posts

Apache2k

Hi folks.

Have been trying to make s lisp code for a simple task but turned out that it might not be so easy. I found lots of information but not this one.

 

So i'm asking if this is even possible to do.

 

I have a block and it has many entities. The block has a name but all the (2-3) entities have different color.

 

I'm trying to change the entity color without exploding the block and change the entity name. This part is ok and i even found a good solution for this.

However the problem is that i have to rename also the main block regarding the selected color for the entity.

 

I have 5-10 options for color. (112=blue, 113=red etc.) So the final block name should turn out as 123456-112.

 

I know how to find the block name and change but when i go deep into entities then i dont have the DXF code for the original block name.

 

So here i am in an endless loop. Can someone assist or show me some directions how to manage with this?

 

Thanks.

Share this post


Link to post
Share on other sites
Lee Mac

When you modify a block definition, the changes will affect all references of the block in the drawing.

 

From your description, it sounds as though you are looking to rename individual references of a single block definition - this is not possible without duplicating the block definition for every new block name that you wish to create, however, if you do wish to pursue this route, my Copy or Rename Block Reference program will show you how.

 

Alternatively, I would suggest changing the colour of the components in your block definition to ByBlock, and then changing the colour of each block reference to suit.

Share this post


Link to post
Share on other sites
Apache2k

Thank you Lee for helping.

Not sure if i got this right.

 

The function i need will be used to modify existing blocks that are on the right location.

 

My problem is that i can change the block by using rename but i must first be able to change the entity color and then rename the block as selected block name xxxxx-112

 

Our blocks are nested but don't have a names. Parts are modeled by using component colors.

 

Also the block definition modify should change all the same blocks as mentioned. In my case the copy and rename is not needed. If i have five of these blocks in adwg and the color has been changed then its ok that all of the same blocks are renamed.

sssss.jpg

Edited by Apache2k

Share this post


Link to post
Share on other sites
Apache2k

Now i came so far that i am able to change the entity colors but how can i find out the entity main block name while using nentsel?

Any tips?

Share this post


Link to post
Share on other sites
hmsilva

Try

(vl-load-com)
(defun c:demo (/ nsel l ll)
   (if (and (princ "\nSelect a block entity: ")
            (setq nsel (nentsel))
            (setq l (last nsel))
            (setq ll (last l))
            (= (type ll) 'ENAME)
       )
       (progn
           (setq obj  (vlax-ename->vla-object ll)
                 name (vla-get-effectivename obj)
           )
           (princ (strcat "\nThe block name is: " name))
       )
       (princ "\nThe selected object was not from a block...")
   )
   (princ)
)

 

I hope this helps.

Henrique

Share this post


Link to post
Share on other sites
Apache2k

Thank you thank you hmsilva :) works perfect.

 

Well got just another question. I have found a function that is calling "(setq color (acad_colordlg 256))"

However i have build a dcl where i give only 4-7 options to the color. what would be the preferred way to replace the dialog box?

 

Now i got these:

 

Changed (setq color (acad_colordlg 256)) to (setq color (def_function))

 

 

(setq width (dimx_tile "im1")

height (dimy_tile "im1")

)

(start_image "im1")

(fill_image 0 0 width height 20)

(end_image)

 

 

and

 

(action_tile "im1" "(setq la (itoa 20))")

 

 

This gives me the error message:

Command: ; error: bad argument type: stringp 20

 

:(

Share this post


Link to post
Share on other sites
hmsilva
Thank you thank you hmsilva :) works perfect.

You're welcome,Apache2k!

Well got just another question. I have found a function that is calling "(setq color (acad_colordlg 256))"

However i have build a dcl where i give only 4-7 options to the color. what would be the preferred way to replace the dialog box?

...

This gives me the error message:

Command: ; error: bad argument type: stringp 20

 

The error means 'the function expects a 'string' and is receiving a 20.

But in that piece of code, i can't see what may be causing that error...

 

Henrique

Share this post


Link to post
Share on other sites
Apache2k

Figured out the problem. I was calling the wrong function from the wrong place. And sorry for the bad information, i did notice that it wont help anyone. I'll try next time be more specific. :)

Share this post


Link to post
Share on other sites
hmsilva

Glad you got it to work.

 

 

Henrique

Share this post


Link to post
Share on other sites
Apache2k

One more question from the same project.

 

((1.0 0.0 0.0) (0.0 1.0 0.0) (0.0 0.0 1.0) (5400.0 -1800.0 0.0))(6571.82 -607.697 0.0)

 

How can i force the lisp to select this only (6571.82 -607.697 0.0) from the list on top?

Share this post


Link to post
Share on other sites
hmsilva
One more question from the same project.

((1.0 0.0 0.0) (0.0 1.0 0.0) (0.0 0.0 1.0) (5400.0 -1800.0 0.0))(6571.82 -607.697 0.0)

How can i force the lisp to select this only (6571.82 -607.697 0.0) from the list on top?

perhaps something like this...

(setq sel (nentselp (last '((1.0 0.0 0.0) (0.0 1.0 0.0) (0.0 0.0 1.0) (5400.0 -1800.0 0.0) (6571.82 -607.697 0.0)))))

 

Henrique

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×