Jump to content

How to extract the selection set for w block and modify it


Recommended Posts

Posted

hi,

 

LISP ROUTINE

 

i am working on block i want my blocks to change their color as per the user defenition

 

like a block with if users option is 5 10 15 20 25

i need to assign the colour red ----5 green------10 blue---15 and so on for the same block which i assigned

 

how can i do this i am woking on lisp rotines

  • Replies 29
  • Created
  • Last Reply

Top Posters In This Topic

  • alanjt

    9

  • raj

    8

  • NHM

    6

  • Tharwat

    5

Top Posters In This Topic

Posted

raj: Please do not double post. We heard you the first time. Try to have a little patience.

 

Double posting wastes space and can be confusing as people respond to the same question is both posts. That just makes it more difficult to follow the course of the conversation.

 

Thanks you.

Posted
hi,

 

LISP ROUTINE

 

i am working on block i want my blocks to change their color as per the user defenition

 

like a block with if users option is 5 10 15 20 25

i need to assign the colour red ----5 green------10 blue---15 and so on for the same block which i assigned

 

how can i do this i am woking on lisp rotines

 

 

The Block on which you are working needs to be assigned BYBLOCK Color.... Only then can one apply the color codes to the said blocks even through a LISP Routine

Posted

Here is mine ......

(defun c:THcool (/ TH:CAD ss obj Bs)
 ;Tharwat Nov .09.2010
 (vl-load-com)
 (if (and (setq ss (car (entsel "\n Select Block :")))
   (eq (cdr (assoc 0 (entget ss))) "INSERT")
   )
    (progn
        (setq TH:CAD (vla-get-activedocument (vlax-get-acad-object)))
         (setq obj (vlax-ename->vla-object ss))
           (vlax-for Bs (vla-get-Blocks TH:CAD)
              (vlax-for Obj Bs
                  (vlax-property-available-p Obj 'Color)
                  (vla-put-Color Obj 1)
                )
            )
      )
   (princ (strcat "\n *** Select a BLOCK not a :"(cdr (assoc 0 (entget ss))) " *** "))
   )
 (princ)
 )

 

Tharwat

Posted

Tharwat, Your program works great.... I tried and tested it... The only problem as I see it that Raj wants the color to be inputted at the prompt and the color which he assigns for e.g. 1 i.e. red to selected block entities they should transform their color to red...

 

This is my interpretation of the matter posted by Raj....

Posted

i would like to ask my user for a colour and then change the color

Posted

But you did not reply to the question asked earlier.... whether your blocks whose color transformation you intend to do are assigned BYBLOCK or some other color... This is some necessary inputs required from your end for me to enable me to write a code accordingly

Posted

they are assigned by block

my need : i have a bolt and for different size i need different colors to b added as per the users input of size so they can be sorted

can u please addon some comment to the code for my understanding

Posted

So each size has a defined color? If so, you need to have a list of sizes with corresponding color.

Posted

Here it is . But you should know that the routine would change the color of all Blocks that you have within your dwg.


   
(defun c:THcool (/ss n TH:CAD obj Bs)
 ;Tharwat Nov .09.2010
 (vl-load-com)
 (if (and (setq ss (car (entsel "\n Select Block :")))
   (eq (cdr (assoc 0 (entget ss))) "INSERT")
   (setq n (getint "\n Enter Number of Color between [1 - 255]: "))
   )
    (progn
        (setq TH:CAD (vla-get-activedocument (vlax-get-acad-object)))
         (setq obj (vlax-ename->vla-object ss))
           (vlax-for Bs (vla-get-Blocks TH:CAD)
              (vlax-for Obj Bs
                  (vlax-property-available-p Obj 'Color)
                  (vla-put-Color Obj n)
                )
            )
      )
   (princ (strcat "\n *** Select a BLOCK not a :"(cdr (assoc 0 (entget ss))) " *** "))
   )
 (princ)
 )

 

Good luck

 

Tharwat

Posted

I would try it to change only the color of the selected Block . But I think I would be in need of a HINT .

 

Have you got it ?

 

Thanks

Posted
(defun c:ToColor (/ ss clr)
 (if (and (setq ss (ssget "_:L" '((0 . "INSERT"))))
          (setq clr (acad_colordlg 256 T))
     )
   ((lambda (i / e d a)
      (while (setq e (ssname ss (setq i (1+ i))))
        (entupd (cdr (assoc -1
                            (entmod
                              (if (setq a (assoc 62 (setq d (entget e))))
                                (subst (cons 62 clr) a d)
                                (append d (list (cons 62 clr)))
                              )
                            )
                     )
                )
        )
      )
    )
     -1
   )
 )
 (princ)
)

Posted
Here it is . But you should know that the routine would change the color of all Blocks that you have within your dwg.


      
(defun c:THcool (/ss n TH:CAD obj Bs)
 ;Tharwat Nov .09.2010
 (vl-load-com)
 (if (and (setq ss (car (entsel "\n Select Block :")))
      (eq (cdr (assoc 0 (entget ss))) "INSERT")
      (setq n (getint "\n Enter Number of Color between [1 - 255]: "))
      )
    (progn
        (setq TH:CAD (vla-get-activedocument (vlax-get-acad-object)))
         (setq obj (vlax-ename->vla-object ss))
           (vlax-for Bs (vla-get-Blocks TH:CAD)
              (vlax-for Obj Bs
  [color=red]                (vlax-property-available-p Obj 'Color)[/color]
                  (vla-put-Color Obj n)
                )
            )
      )
   (princ (strcat "\n *** Select a BLOCK not a :"(cdr (assoc 0 (entget ss))) " *** "))
   )
 (princ)
 )

Good luck

 

Tharwat

BTW, (vlax-property-available-p Obj 'Color) does nothing for you. It's intended as a check (T or nil return). You need to put it with an if or and statement. If avail, then put color.
Posted

Know that you can easily change the color with the color pulldown (select the object, then select the color), the CHANGE command or the CHPROP command.

Posted

the color is not changing how ever the color is asked but the block color is not changed

can u give me a hint how to extract the block color as i am a beginner to lisp

Posted
the color is not changing how ever the color is asked but the block color is not changed

can u give me a hint how to extract the block color as i am a beginner to lisp

Are you wanting to make the changes on a primary object level (just change the color of the block) or are you attempting to change all items within the block to a specified color?

 

I'm not sure if you are referring to my routine, but it works fine (barring that objects within block have color set to "ByBlock" instead of "ByLayer" - the only way to accomplish primary object level color change for blocks.

Posted

Alanjt , Your routine would change the color in Layer's list but it wont effect at the selected Block at all.

 

Thanks

Posted

alanjt thanks man this indeed solves my problem i am go on writing a rotine for this

 

thank

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