Jump to content

Nest Blocks and Entity color loop


Apache2k

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

:(

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 4 weeks later...

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?

Link to comment
Share on other sites

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

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