raj Posted November 9, 2010 Posted November 9, 2010 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 Quote
ReMark Posted November 9, 2010 Posted November 9, 2010 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. Quote
NHM Posted November 9, 2010 Posted November 9, 2010 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 Quote
Tharwat Posted November 9, 2010 Posted November 9, 2010 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 Quote
NHM Posted November 9, 2010 Posted November 9, 2010 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.... Quote
raj Posted November 9, 2010 Author Posted November 9, 2010 i would like to ask my user for a colour and then change the color Quote
NHM Posted November 9, 2010 Posted November 9, 2010 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 Quote
raj Posted November 9, 2010 Author Posted November 9, 2010 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 Quote
alanjt Posted November 9, 2010 Posted November 9, 2010 So each size has a defined color? If so, you need to have a list of sizes with corresponding color. Quote
Tharwat Posted November 9, 2010 Posted November 9, 2010 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 Quote
Tharwat Posted November 9, 2010 Posted November 9, 2010 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 Quote
alanjt Posted November 9, 2010 Posted November 9, 2010 (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) ) Quote
alanjt Posted November 9, 2010 Posted November 9, 2010 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. Quote
alanjt Posted November 9, 2010 Posted November 9, 2010 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. Quote
raj Posted November 9, 2010 Author Posted November 9, 2010 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 Quote
alanjt Posted November 9, 2010 Posted November 9, 2010 the color is not changing how ever the color is asked but the block color is not changedcan 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. Quote
Tharwat Posted November 9, 2010 Posted November 9, 2010 Alanjt , Your routine would change the color in Layer's list but it wont effect at the selected Block at all. Thanks Quote
raj Posted November 9, 2010 Author Posted November 9, 2010 alanjt thanks man this indeed solves my problem i am go on writing a rotine for this thank Quote
raj Posted November 9, 2010 Author Posted November 9, 2010 tharwat313 : thank u too i have learned some thing out of ur code thank u for ur thread Quote
Recommended Posts
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.