PDA

View Full Version : Add Optional Status to any layer


trythefly
2007-03-08, 03:03 PM
I would really like to have a LISP that will add a Optional Status to any layer you click on.

I need one to change items to Demo:
M-Duct-Std-Supp
Becomes
MD-Duct-Std-Supp

And have another that will change items to Existing:
M-Duct-Std-Supp
becomes
ME-Duct-Std-Supp

I have posted this on the Autodesk LISP forums as well as ours here.

jwanstaett
2007-03-08, 04:03 PM
this code will do the Demo layer
load it
use the command Demolayer the object you select will be put on the demolayer
if the demo layer not in the drawing it will make the layer
if the Layer dose have a "M-" in it the layer will not change
if the layer name is m-layer the new layer will be name MD-LAYER
if the demo layer is in the drawing the case will not change
if Demolayer return nil the layer was not change

Note: You need to add in some error check code
you get a error if you do not select a object


(defun C:DemoLayer()
(setq ed (entget(car (entsel))))
(setq layer (assoc 8 ed))

(setq newlayer (cons 8 (vl-string-subst "MD-" "M-" (strcase (cdr layer)))))
(entmod (subst newlayer layer ed))
)

Opie
2007-03-08, 04:13 PM
this code will do the Demo layer
load it
use the command Demolayer the object you select will be put on the demolayer
if the demo layer not in the drawing it will make the layer
if the Layer dose have a "M-" in it the layer will not change
if the layer name is m-layer the new layer will be name MD-LAYER
if the demo layer is in the drawing the case will not change
if Demolayer return nil the layer was not change

Note: You need to add in some error check code
you get a error if you do not select a object


(defun C:DemoLayer()
(setq ed (entget(car (entsel))))
(setq layer (assoc 8 ed))

(setq newlayer (cons 8 (vl-string-subst "MD-" "M-" (strcase (cdr layer)))))
(entmod (subst newlayer layer ed))
)

When creating the new layer, your routine does not duplicate the original layer properties of the entity's original layer. I do not know if that is desired, though. It would be for me.

trythefly
2007-03-08, 04:23 PM
Try to get it to do this:
If you are selecting an item that already has an optional status can it work so it forces it to have the D. Example ME- to MD-

Can we make it select multiple objects at once or work off a selection set that the user has already picked?

I tested it out on a few different layers, if the layer is already defined in the drawing it will work. If it is not defined it puts it on layer 0.

trythefly
2007-03-08, 04:34 PM
Try to get it to do this:
If you are selecting an item that already has an optional status can it work so it forces it to have the D. Example ME- to MD-

Can we make it select multiple objects at once or work off a selection set that the user has already picked?

I tested it out on a few different layers, if the layer is already defined in the drawing it will work. If it is not defined it puts it on layer 0.

Also the M was just an example. I need this to add D in the second digit to any layer.
Examples:
M-
becomes: MD-
ME-
becomes: MD-
P-
becomes: PD-
PE-
becomes: PD-
G-
becomes: GD-
GE-
becomes: GD-
etc etc

trythefly
2007-03-08, 06:49 PM
This is almost what I am looking for:

(defun c:change_demo (/ LayItem LayStart LayChange)
(setq
LayItem (entsel "Select item to move to Demolition Layer: ")
LayStart (cdr (assoc 8 (entget (car LayItem))))
); setq
(if (= (substr LayStart 2 1) "-") ;;if it's on a Layer with a single-letter beginning before a hyphen
(setq LayChange (strcat (substr LayStart 1 1) "D" (substr LayStart 2)))
;;Layer name with D added as second character
(setq LayChange (strcat (substr LayStart 1 1) "D" (substr LayStart 3)))
;;Layer name with second character changed to D
); if(command "_.layer" "_m" LayChange "_l" "demo2" "")
(command "_.chprop" LayItem "" "_la" LayChange "")
); defun


The only thing I need it to do now is color & lineweight to remain the same.

Anyone have any input on how to do this?

--==Thanks==--

Opie
2007-03-08, 06:54 PM
One thing you need to watch for is someone not selecting an entity. Trying to extract the layer name without an entity will cause an error.

Searching the layer table for the proposed layer name will tell you if it exists or not. If it does not exist, then copy the layer properties from the current layer. You can then use these properties to adjust the new layer.