@doaiena wrote:
I think this should do the job. Test it and tell me if it works for you.
(defun c:test ( / ss acadDoc layers ctr obj )
(if (setq ss (ssget "X" '((410 . "Model"))))
(progn
(setq acadDoc (vla-get-activedocument (vlax-get-acad-object)))
(setq layers (vla-get-Layers acadDoc))
(setq ctr 0)
(repeat (sslength ss)
(setq obj (vlax-ename->vla-object (ssname ss ctr)))
(if (and (vlax-property-available-p obj 'Color T)
(vlax-property-available-p obj 'LineType T)
(vlax-property-available-p obj 'LineWeight T)
(vlax-property-available-p obj 'LineTypeScale T)
)
(progn
(vlax-put-property obj 'Color (vla-get-Color (vla-item layers (vlax-get-property obj 'Layer))))
(vlax-put-property obj 'Linetype (vla-get-Linetype (vla-item layers (vlax-get-property obj 'Layer))))
(vlax-put-property obj 'LineWeight acLnWtByLayer)
(vlax-put-property obj 'LineTypeScale 1.0)
));if prop available
(setq ctr (1+ ctr))
);repeat
));if ss
);defun
Thanks man! That's worked perfectly! I've forgot to mention those cases when the objects already have some specific color or linetype assigned to them. Could you add a step in your routine to keep intact only those objects that already have color and linetype assigned to them as it is? In other hand, every object that has Color, Linetype setted to ByLayer should take the Color and the Linetype from the layer.
Imagine that my intention is to keep everything intact, just how it looks like on the screen by incorporating the properties to every element, like color and linetypes, for example. It will come from layers, in cases in which the property of the object is setted "ByLayer" or already inside each element (in case the objects have already color and linetype inside their properties), so then I can move all those objects to a same layer keeping visual integrity.
Hope I made myself clear enough. Thanks a lot great sir! 🙂