Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

lisp code for layer properties

15 REPLIES 15
SOLVED
Reply
Message 1 of 16
E.S.7.9
5905 Views, 15 Replies

lisp code for layer properties

hi ,

 

i wanna select objects with ssget and create selection group , and after that change of this group layer properties ..

how could i change layer properties with routine?

 

could anybody write me the code ?

 

thank you

15 REPLIES 15
Message 2 of 16
hmsilva
in reply to: E.S.7.9


@E.S.7.9 wrote:

hi ,

 

i wanna select objects with ssget and create selection group , and after that change of this group layer properties ..

how could i change layer properties with routine?

 

could anybody write me the code ?

 

thank you


Hi E.S.7.9

 

"i wanna select objects with ssget and create selection group"

Do you mean "selection set"? If so, you can use

(setq ss (ssget "_:L"))

"and after that change of this group layer properties"

if you just want to change object layers to for a specific layer,  you can use

(command "_.chprop" ss "" "LA" "YourLayerName" "")

 

If you need to modify other layer or object properties, you'll have to explain better...

 

 

HTH

Henrique

EESignature

Message 3 of 16
E.S.7.9
in reply to: hmsilva

i can use your codes , but i need one more code if you can write me here ..

 

if i just want to change layer color of selected objects [[  
(setq ss (ssget "_:L"))  ]] after that  which code i have to use ?

 

thank you again

Message 4 of 16
hmsilva
in reply to: E.S.7.9


@E.S.7.9 wrote:

i can use your codes , but i need one more code if you can write me here ..

 

if i just want to change layer color of selected objects [[  
(setq ss (ssget "_:L"))  ]] after that  which code i have to use ?

 

thank you again


E.S.7.9,

 

you have to try to write your one codes, using command calls shouldn't be very difficult... Smiley Wink

 

using the "CHPROP" AutoCAD core command inside your code, You can use all the command "OPTIONS":


[Color/LAyer/LType/ltScale/LWeight/Thickness/Material/Annotative]

 

If you type at the command line chprop, then select the objects, to exit the selcting mode you'll need to press enter, then enter the propertie you need to change (i.e. Color), if you need to change more properties don't exit the command and continues to modify all necessary properties, at the end press enter to exit the command.

 

The easiest way to find out how to use an AutoCAD command in a code is entering the command at the command line, when the command finished press F2 and see all the prompts answers and enters that were needed to run this command and write your  code mimicking all the prompts answers and enters, remember that one enter at your code will be a "".

 

Using the CHPROP command:

Command: chprop
Select objects: Specify opposite corner: 2 found
Select objects:
Enter property to change
[Color/LAyer/LType/ltScale/LWeight/Thickness/Material/Annotative]: c
New color [Truecolor/COlorbook] <BYLAYER>: 3
Enter property to change
[Color/LAyer/LType/ltScale/LWeight/Thickness/Material/Annotative]:
Command:

 

In a code, and using a previous selection set stored at the variable ss, will be

 

(command "_.chprop" ss "" "Color" "3" "");;I used the color 3 (green) from the 255 AutoCAD Color Index colors.

 

In a code just to change the object colors, maybe something like this

 

(defun c:test (/ ss);; declaring the ss variable as local
  (prompt "\nSelect objects to change the color to Green: ");; prompts the user for
  (if (setq ss (ssget "_:L"));; selects and test if a valid selection set exists
    (command "_.chprop" ss "" "Color" "3" "");; if exists, runs the chprop command
  );; if a valid selection set don't exists, just end the if function
  (princ);; exits quietly
);; ends the test function

 

Hope that helps
Henrique

 

 

 

EESignature

Message 5 of 16
Kent1Cooper
in reply to: E.S.7.9


@E.S.7.9 wrote:

... i just want to change layer color of selected objects....


It's not clear to me whether you want to change the color of the selected objects themselves with a color override [as hmsilva's suggestion would do], or the color assigned to the Layer(s) on which the selected objects are drawn [as the wording above suggests to me].  If it's the latter, the routine would need to step through the objects and find their Layers, then assign the desired color to those Layers.  Then any object on any of those Layers whose color is Bylayer would appear in that color.  Is that what you're trying to do?

Kent Cooper, AIA
Message 6 of 16
hmsilva
in reply to: Kent1Cooper


@Kent1Cooper wrote:

@E.S.7.9 wrote:

... i just want to change layer color of selected objects....


It's not clear to me whether you want to change the color of the selected objects themselves with a color override [as hmsilva's suggestion would do], or the color assigned to the Layer(s) on which the selected objects are drawn [as the wording above suggests to me].  If it's the latter, the routine would need to step through the objects and find their Layers, then assign the desired color to those Layers.  Then any object on any of those Layers whose color is Bylayer would appear in that color.  Is that what you're trying to do?


Kent,

rereading the OP seems to me that I missed that part of the post, I understood that yhe OP wanted to change the object colors...

 

Henrique

EESignature

Message 7 of 16
pbejse
in reply to: hmsilva


@hmsilva wrote:

rereading the OP seems to me that I missed that part of the post, I understood that yhe OP wanted to change the object colors...

 

Henrique


That appears to be the case as the thread title imply Henrique --->> "lisp code for layer properties"

 

But as Kent pointed out, the E.S.7.9s' intent is still not clear.

Message 8 of 16
hmsilva
in reply to: pbejse

E.S.7.9 wrote:

 

"if i just want to change layer color of selected objects"

 

But I must have read:

 

"if i just want to change color of selected objects"

 

I need to buy new glasses...Smiley Happy

 

Cheers pBejse
Henrique

EESignature

Message 9 of 16
pbejse
in reply to: hmsilva


@hmsilva wrote:

@E.S.7.9 wrote:

 

"if i just want to change layer color of selected objects"

 

But I must have read:

 

"if i just want to change color of selected objects"

 

I need to buy new glasses...Smiley Happy

 

Cheers pBejse
Henrique


 

Just can't tell these days really, you may be right for all we know Smiley Happy

 

Anyhoo.. here's a demo code for E.S.7.9

 

(defun c:demo ( / ss laylist i ent lay laydata);;; pBe Jan2014;;;
      (if (and (setq ss (ssget "_:L"))
               (setq laylist nil color (Acad_colordlg 7 nil))
               )
          (repeat (setq i (sslength ss))
                	(if (not (member (setq lay  (cdr (assoc 8 (setq ent (entget
                            (ssname ss (setq i (1- i)))))))) laylist))
                            (progn
                            	(setq laylist (cons lay laylist)
                                      laydata (entget (tblobjname "Layer" Lay)))
                                  (entmod (subst (cons 62 color)(assoc 62 laydata) laydata))
                                  (entmod (append ent '((62 . 256))))
                                )
                            )
                )
          )
      (princ)
      )

 

HTH

Message 10 of 16
saross622
in reply to: pbejse

This lisp works pretty good.  Can it be expanded to include other Layer Properties like Linetype and Plot?

 

And how can the selection method be changed to allow for selecting Nested objects such as Xref Layers?

 

Thanks,

 

Scott

Message 11 of 16
m_rogoff
in reply to: E.S.7.9

how can the selection method be changed to allow for selecting Nested objects such as Xref Layers?

Thanks!

 

bump

Message 12 of 16
Kent1Cooper
in reply to: m_rogoff


@m_rogoff wrote:

how can the selection method be changed to allow for selecting Nested objects such as Xref Layers?

...


If you mean to change properties of the Xref-dependent Layers of only some nested objects inside Xrefs, I think that would require selection using (nentsel) rather than (ssget).  If you mean perhaps to change properties of all nested Layers in a selected Xref [such as to "gray out" a background drawing], that should be doable using (ssget), because selecting it could be on anything in it or by window, etc., and having the Xref as a whole in the selection would allow access to all its dependent Layers.  [Neither approach would overcome any override colors assigned to individual nested objects.]

Kent Cooper, AIA
Message 13 of 16
m_rogoff
in reply to: m_rogoff

You're Exactly right, I want a Grey'd out background, from an Xref. 

 

I need 2 options, 1) Color; 252, or 2) Color 2, linetype Hidden 4.

Perhaps run with a  Command: _refedit (Xref edit in-place) /

Run the previous code to change all colors to ByLayer

Command: _refclose

Run your code "to change properties of all nested Layers in a selected Xref" to options 1) and 2) above

 

 

 

This would be very helpful and much appreciated, thank you 

Message 14 of 16
m_rogoff
in reply to: m_rogoff

Actually, I think I changed my mind. Instead of changing layers in the actual Xref.dwg, I want to change the layer properties in the file containing the xref to one of the 2 options mentioned in previous post. In this case, the base xref file should maintain it's layer information, but would be Grey'd out in the working file. This should be easier, right?

Message 15 of 16
saross622
in reply to: Kent1Cooper

Hi Kent, 

 

I tried replacing (ssget) with (nentsel) but it ended up erroring out and not changing the layer's color.  I am looking to adjust the Layer Properties of a selected object within an xref (I am working with non-English original document, so layer naming is unfamiliar).  

 

As far as "greying out" all the xref layers, I would just apply a layer filter for that xref and modify all the layers to the grey color of my choice.

 

Thank you for your insight,

 

Scott

Message 16 of 16
Shneuph
in reply to: saross622

I haven't read every post in this thread so I don't know if it has already been mentioned but if you start changing xref layer properties in your drawing be sure to check the visretain variable or all of your layer property overrides will go away if the xref is reloaded.

 

VISRETAIN Help

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost