yes it can be made easier.This is what i created now.
But i have one question about this.
How can i make the cancel button in acad_colordlg work.?
It really depends on what you want to happen after the cancel button is pressed.
(acad_colordlg 11 nil) will return nil if the user presses cancel, since you send the color 11, you would presumably want to not change the default color (i.e. 11) ... therefore
(defun pick_color ()
(if (setq kleur (acad_colordlg 11 nil))
kleur
11
)
)
Now, lets expand on that a bit, presume you don't always want to use 11 as the color you could easily expand the function
(defun pick_color ( defColor )
(if (setq kleur (acad_colordlg defColor nil))
kleur
defColor
)
)
In this manner, you would send the value to the function i.e.
(pick_color 11)
I did notice that you have failed to get the return values of 'kleur' and instead rely on it being a global variable. This will not work without additional code and could run into conflict with other functions if not properly written.
This would be the better:
(defun pick_color ( defColor / kleur )
(if (setq kleur (acad_colordlg defColor nil))
kleur
defColor
)
)
Now to prepare the remaining code, you need to save the return value of the function ...
(defun fill_start()
(setq cla (getvar "clayer"))
(princ)
)
(defun fill_end ()
(setvar "clayer" cla)
(princ)
)
(defun fill (kleur)
(fill_start)
(setq a (ssget))
(setq laagnaam (strcat "kleurvulling--" (itoa kleur)))
(command "-layer" "make" laagnaam "color" kleur laagnaam "")
(command "bhatch" "p" "solid" "s" a "" "")
(setq c (entlast))
(command "change" c "" "p" "la" laagnaam "")
(command "draworder" c "" "back")
(command "draworder" a "" "Front")
(fill_end)
(princ)
)
; **************************************************************
(defun c:kv ()
(fill (pick_color 11))
(princ)
)
(defun pick_color ( defColor / kleur )
(if (setq kleur (acad_colordlg defColor nil))
kleur
defColor
)
)
You might also want to clean up some of the command calls by using native lisp and vlisp functions and turn off cmdecho ...