Author Topic: Solid Hatch On Layer In Color... Can this made easier.?  (Read 2414 times)

0 Members and 1 Guest are viewing this topic.

MvdP

  • Guest
Solid Hatch On Layer In Color... Can this made easier.?
« on: June 03, 2010, 03:14:51 AM »
First let me explain what i want to achieve .

  • Save current layer
  • Ask to selected objects to hatch with solid on layer "Colorfill--XX" in color XX (XX= all autocad colors 1-255)
  • Send selected object to front and/ or solid hatch to back
  • Restore previous saved layer

This is what i got now and working , but this way i have to do this for every color  that means a lot defuns in the lsp and a lot off autload lines in the mnl and a lot of  lines in the vba

Is there a way to make this a lot easier and simpler.? ( Whitout the vba part..Gone in next autocad release)

Code: [Select]
(defun fill_start()
(setq cla (getvar "clayer"))
 (princ)
)

(defun fill_end ()
(setvar "clayer" cla)
 (princ)
)

(defun UniFilling (fill / b c)
  (fill_start)
  (setq a (ssget))
  (command "bhatch" "p" "solid" "s" a "" "")
  (setq c (entlast))
  (setq ed (entget c))
  (setq ed (subst (cons 8 (strcat "colorfill--" (itoa fill)))
 (assoc 8 ed)
 ed
  )
  )
  (entmod ed)
  (command "draworder" c "" "back")
  (command "draworder" a "" "Front")
  (fill_end)
  (princ)
)
; **************************************************************

(defun c:cf30 ()
  (UniFilling 30)
  (princ)
)

(defun c:cf40 ()
  (UniFilling 40)
  (princ)
)

VBA
Code: [Select]
Case "(c:cf30)"
Call  Setlayer ("Colorfill--30",30)
Case "(c:cf40)"
Call  Setlayer ("Colorfill--40",40)

MNL
Code: [Select]
(autoload "colfill" '("cf30" "cf40" ))


MvdP

  • Guest
Re: Solid Hatch On Layer In Color... Can this made easier.?
« Reply #1 on: June 09, 2010, 02:53:12 AM »
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.?

Code: [Select]
(defun fill_start()
(setq cla (getvar "clayer"))
(princ)
)

(defun fill_end ()
(setvar "clayer" cla)
(princ)
)

(defun fill ()
  (fill_start)
  (setq a (ssget))
  (setq laagdeel1 "kleurvulling--")
  (setq laagdeel3 (itoa kleur))
  (setq laagnaam (strcat laagdeel1 laagdeel3))
  (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 ()
(pick_color)
(fill)
(princ)
)

(defun pick_color ()
    (setq kleur (acad_colordlg 11 nil))
kleur
)

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Solid Hatch On Layer In Color... Can this made easier.?
« Reply #2 on: June 09, 2010, 09:31:12 AM »
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

Code: [Select]
(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

Code: [Select]
(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.
Code: [Select]
(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:
Code: [Select]
(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 ...

Code: [Select]
(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 ...
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

MvdP

  • Guest
Re: Solid Hatch On Layer In Color... Can this made easier.?
« Reply #3 on: June 09, 2010, 09:56:16 AM »
Thanks for the explanation  Keith.
If i hit the cancel button i want the program  to exit. Now it just continuous.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Solid Hatch On Layer In Color... Can this made easier.?
« Reply #4 on: June 09, 2010, 10:00:02 AM »
Thry these updated functions

Code: [Select]
(defun c:kv ()
  (if (setq kleur (pick_color 11))
    (fill kleur)
  )
(princ)
)

(defun pick_color ( defColor / kleur )
    (if (setq kleur (acad_colordlg defColor nil))
       kleur
       nil
    )
)
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

MvdP

  • Guest
Re: Solid Hatch On Layer In Color... Can this made easier.?
« Reply #5 on: June 09, 2010, 11:33:24 AM »
Thanks again Keith.
Will try that tomorrow morning when i am back at the office.
And what if i dont want a default (11) color.?

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Solid Hatch On Layer In Color... Can this made easier.?
« Reply #6 on: June 09, 2010, 11:43:59 AM »
simply change 11 to whatever you want it to be

Code: [Select]
(defun c:kv ()
  (if (setq kleur (pick_color yourcolorhere))
    (fill kleur)
  )
(princ)
)
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

MvdP

  • Guest
Re: Solid Hatch On Layer In Color... Can this made easier.?
« Reply #7 on: June 10, 2010, 01:31:51 AM »
Thanks for the help Keith.
Working great.

Willie

  • Swamp Rat
  • Posts: 958
  • Going nowhere slowly
Re: Solid Hatch On Layer In Color... Can this made easier.?
« Reply #8 on: June 10, 2010, 02:16:08 AM »
I like your Dutch variables.   :-)
Soli Deo Gloria | Qui Audet Adipiscitur
Windows 8  64-bit Enterprise | Civil 3D 2015 and 2016| ArcGIS 10.1
Yogi Berra : "I'd give my right arm to be ambidextrous."