Add color to Layer

Add color to Layer

C.Utzinger
Collaborator Collaborator
2,309 Views
20 Replies
Message 1 of 21

Add color to Layer

C.Utzinger
Collaborator
Collaborator

 

Hi

 

It's a simple thing. I just want to add a color to the Layer... How????

 

 

 

(defun c:<Test3 ()
  (tolayer (ssget "_:L") "-I-Ansicht")
  (princ)
) ;_ end of defun
(defun tolayer ( ss lay / i e )
  (repeat (setq i (sslength ss))
    (entmod
      (subst
	(cons 8 lay)
        (assoc 8 (entget (setq e (ssname ss (setq i (1- i))))))
        (entget e)
        )
      )
    )
  )

 

 

Thank you in advance...

0 Likes
Accepted solutions (3)
2,310 Views
20 Replies
Replies (20)
Message 2 of 21

ВeekeeCZ
Consultant
Consultant
Accepted solution

Like this maybe?

 

(defun c:<Test3 ()
  (tolayer (ssget "_:L") "-I-Ansicht" "2")
  (princ)
  ) ;_ end of defun
(defun tolayer ( ss lay col / i e )
  (if (tblsearch "LAYER" lay)
    (command "_.-LAYER" "_C" col lay "")
    (command "_.-LAYER" "_N" lay "_C" col lay ""))
  (repeat (setq i (sslength ss))
    (entmod
      (subst
        (cons 8 lay)
        (assoc 8 (entget (setq e (ssname ss (setq i (1- i))))))
        (entget e)
        )
      )
    )
  )
0 Likes
Message 3 of 21

C.Utzinger
Collaborator
Collaborator

Hi

 

I thought it is better without using command...?

 

 

0 Likes
Message 4 of 21

C.Utzinger
Collaborator
Collaborator

I'm just trying another Thing, but with no idea how to do it...

 

I want to have both Option, or change a previous selected object, or draw a poliline...

 

Is that possible???

 

 

(defun c:<Test3 ()

(if (ssget "_:L")(progn
  		 (tolayer (ssget "_:L") "-I-Ansicht" "6")
  		 (princ))
		 
		 (progn
  		 (command "_.-LAYER" "_m" "-I-Ansicht" "_co" "6" "-I-Ansicht" "")
		 (command "_pline" (while (> (getvar "cmdactive") 0) (command pause)))
		 (prin1))
)

) ;_ end of defun

(defun tolayer ( ss lay col / i e )
  (if (tblsearch "LAYER" lay)
    (command "_.-LAYER" "_C" col lay "")
    (command "_.-LAYER" "_N" lay "_C" col lay ""))
  (repeat (setq i (sslength ss))
    (entmod
      (subst
        (cons 8 lay)
        (assoc 8 (entget (setq e (ssname ss (setq i (1- i))))))
        (entget e)
        )
      )
    )
  )
0 Likes
Message 5 of 21

ВeekeeCZ
Consultant
Consultant
Accepted solution

Don't think so.

 

(defun c:<Test3 ()
  (tolayerwithcolor (ssget "_:L") "-I-Ansicht" 2)
  (princ)
  )

(defun tolayerwithcolor ( ss lay col / i e d)
  (if (and (tblsearch "LAYER" lay)
           (setq d (entget (tblobjname "LAYER" lay))))
    (entmod (subst (cons 62 col)
                   (assoc 62 d)
                   d))
    (entmake (list (cons 0 "LAYER")
                   (cons 100 "AcDbSymbolTableRecord")
                   (cons 100 "AcDbLayerTableRecord")
                   (cons 2 lay)
                   (cons 62 col)
                   (cons 70 0))))

  (repeat (setq i (sslength ss))
    (entmod
      (subst
        (cons 8 lay)
        (assoc 8 (entget (setq e (ssname ss (setq i (1- i))))))
        (entget e)))))
0 Likes
Message 6 of 21

ВeekeeCZ
Consultant
Consultant

@c.utzinger wrote:

I'm just trying another Thing, but with no idea how to do it...

 

I want to have both Option, or change a previous selected object, or draw a poliline...

 

Is that possible???

 


Don't have time to make it nicer, so just simple if conditions...

 

(setq ss (ssget "I"))			; pre-selection

(if (not ss)
  (setq pt (getpoint "\nDraw a polyline or <select objects to layer change>: ")))

(if (not pt)
  (setq ss (ssget)))

(layerset) 				; check layer existence, set color

(if pt
  (draw-polyline))                     ; set current lay, use pt as the first point of polyline 

(if ss
  (tolayer))

 

BTW What is do a lot for myself is that if I have something pre-selected, then it does one thing, if don't then the other. This task might fit for this.

 

Message 7 of 21

C.Utzinger
Collaborator
Collaborator

I'm so stupid

 

It was just like this:

 

 

(defun c:<Test3 ()

(if (ssget "I")(progn
  		 (tolayer (ssget "I") "-I-Ansicht" "6")
  		 (princ))
		 
		 (progn
  		 (command "_.-LAYER" "_m" "-I-Ansicht" "_co" "6" "-I-Ansicht" "")
		 (command "_pline" (while (> (getvar "cmdactive") 0) (command pause)))
		 (prin1))
)

) ;_ end of defun

(defun tolayer ( ss lay col / i e )
  (if (tblsearch "LAYER" lay)
    (command "_.-LAYER" "_C" col lay "")
    (command "_.-LAYER" "_N" lay "_C" col lay ""))
  (repeat (setq i (sslength ss))
    (entmod
      (subst
        (cons 8 lay)
        (assoc 8 (entget (setq e (ssname ss (setq i (1- i))))))
        (entget e)
        )
      )
    )
  )

 

 

Sorry... Thank you

0 Likes
Message 8 of 21

ВeekeeCZ
Consultant
Consultant

Almost.

- wrong parenthesis around PLINE part

- a routine should never change any SYSVAR without setting it BACK!!!

 

(defun c:<Test3 ( / *error* olay :tolayer)
  
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
      (princ (strcat "\nError: " errmsg)))
    (setvar 'CLAYER olay)
    (princ))
  
  (defun :tolayer ( ss lay col / i e )
    (if (tblsearch "LAYER" lay)
      (command "_.-LAYER" "_C" col lay "")
      (command "_.-LAYER" "_N" lay "_C" col lay ""))
    (repeat (setq i (sslength ss))
      (entmod (subst (cons 8 lay)
                     (assoc 8 (entget (setq e (ssname ss (setq i (1- i))))))
                     (entget e)))))
  
  ; ---------------------------------------------------------------------------------
  
  (setq olay (getvar 'CLAYER))
  
  (if (ssget "_I")
    (:tolayer (ssget "_I") "-I-Ansicht" "6")
    (progn
      (command "_.-LAYER" "_m" "-I-Ansicht" "_co" "6" "-I-Ansicht" "")
      (command "_.PLINE")
      (while (> (getvar 'CMDACTIVE) 0) (command PAUSE))))
  (setvar 'CLAYER olay)
  (princ)
)
Message 9 of 21

C.Utzinger
Collaborator
Collaborator
Accepted solution

HI

 

Thank you about the wrong parenthesis around PLINE part...

 

Just in this case I want to change the layer to -I-Ansicht.

 

This is my finished version...

 

Tell me please if something is wrong...

 

Kind regards.

 

 

(defun c:<Test3 ( / *error* cmd)

  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
      (princ (strcat "\nError: " errmsg)))
    (setvar 'CMDECHO cmd)
    (command-s "_.undo" "_end")
    (princ))

  (defun tolayer ( ss lay col / i e )
    (if (tblsearch "LAYER" lay)
      (command "_.-LAYER" "_C" col lay "")
      (command "_.-LAYER" "_N" lay "_C" col lay ""))
    (repeat (setq i (sslength ss))
      (entmod
        (subst
          (cons 8 lay)
          (assoc 8 (entget (setq e (ssname ss (setq i (1- i))))))
          (entget e)))))

;-----------------------------------------------------------------------------

(setq cmd (getvar 'CMDECHO))

	(if (ssget "I")(progn
  		 (tolayer (ssget "I") "-I-Ansicht" "6")
		 (prompt "\nObjekt/e auf Layer -I-Ansicht gewechselt!")	
  		 (princ))
		 
		 (progn
		 (command "_.undo" "_begin") 	
  		 (command "_.-LAYER" "_m" "-I-Ansicht" "_co" "6" "-I-Ansicht" "")
		 (setvar 'CMDECHO 1)
		 (command "_.pline") 
		 (while (> (getvar "cmdactive") 0) (command pause))
		 (setvar 'CMDECHO cmd)
		 (command "_.undo" "_end")
		 (prin1))
	)
) ;_ end of defun
0 Likes
Message 10 of 21

ВeekeeCZ
Consultant
Consultant
We usually use the CMDECHO in the other way around. We presume that the most people have it ON and we turn it off if we need it.
But I thing it's good to go... Cheers!
Message 11 of 21

C.Utzinger
Collaborator
Collaborator

Yeah!

 

The Problem is when CMDECHO is off, then PLINE dos not show the options in the command line (pick first Point, pick next point, etc.)

 

Or is there another way to show these Options?

 

Thank you again...Smiley Happy

 

Kind regards.

0 Likes
Message 12 of 21

ВeekeeCZ
Consultant
Consultant
The question is why it is OFF? It should be ON by default.

I presume that the answer is because of some other routine which was not finished (and written) correctly, so it left CMDECHO off. You should fix the other routines...

No better way - just make sure that your have it in *error* function.
Message 13 of 21

Kent1Cooper
Consultant
Consultant

@c.utzinger wrote:

... 

This is my finished version...  Tell me please if something is wrong...

....


I would suggest you add tolayer to the localized variables list.

 

Also, consider adding a saving of the current Layer at the beginning, and resetting of it at the end and in the *error* handler.

 

In case you care, that entire (repeat) function that makes up the bulk of the (tolayer) function could be replaced by this, eliminating the need to step through the selection and change each object's layer separately:

 

(command "_.chprop" ss "" "_layer" lay "")

Kent Cooper, AIA
Message 14 of 21

C.Utzinger
Collaborator
Collaborator

Hi

 

I have a Little fight with AutoCAD. The CMDECHO is always off, i can Close it with "1" and when i open a empty drawing it is "0" again.

 

What can i do...?

0 Likes
Message 15 of 21

ВeekeeCZ
Consultant
Consultant

Use acaddoc.lsp, see HERE, find it using (file "acaddoc.lsp") or create one, save it on search path...

 

At the end of it add the line...

(setvar 'CMDECHO 1)

 

You can use SYSVARMONITOR to help you with finding which routine changes that setting.

0 Likes
Message 16 of 21

C.Utzinger
Collaborator
Collaborator

 

Do you remember the stupid program? This Change it to "0"!!!!!!!!

 

I'm so f.....g angry!!!!!!!!!!!!

 

I will write them again!

 

 

Thank you for your help... 

 

 

0 Likes
Message 17 of 21

C.Utzinger
Collaborator
Collaborator

I just found a Problem with the Routine.

 

When someone has turned of PICKFIRST, then it doesn't work.

 

I can not (or don't know how) put (setvar 'PICKFIRST 1) before the Routine starts, it don´t work... The selection gets away I think.

 

What can I do?

 

 

0 Likes
Message 18 of 21

ВeekeeCZ
Consultant
Consultant

Nothing you can do about it. Go back to my post #6 and allow <select object to layer change>

Message 19 of 21

C.Utzinger
Collaborator
Collaborator

Hi

 

One more question.

 

If the layer exists and it is off, then I don't want it on, it should just stay off.

 

Can you help me with that?

 

I tried something with this, but got nothing:

 

(<(cdr (assoc 62 (entget (tblobjname "layer" "LayerNameHere"))))0)

 

 

Thank you in advance...

0 Likes
Message 20 of 21

Kent1Cooper
Consultant
Consultant

@c.utzinger wrote:

.... 

If the layer exists and it is off, then I don't want it on, it should just stay off.

....


If I'm looking at the right code, it looks to me as though the only thing that would turn on a Layer that's off is the Layer command with the Make option in it [anything that sets a Layer current in a Layer command -- Set or Make options -- turns it on if it's off].  Just after that you draw a Polyline, which it is possible to do on a Layer that's off, but that makes no sense to me.  So if the Layer exists and is off, should the routine not only leave it off but also not go into the Pline command?  Or am I misunderstanding something?

Kent Cooper, AIA
0 Likes