Drawingelement.material and face.back_material? [SOLVED]
-
I just did some tests on a simple face with 4 edges.
If I use this command (select=the face):
status=select[0].material="Material1" (drawingelement class)
then the back side of the face gets material 1and if i use this command:
status=select.back_material="Material1" (face class)
then the front side of the face gets material 1Why is this? And why are these commands seperated over 2 classes?
And is there any possibility to give a complete selection a certain material at once? (wether it is a combination of lines and faces or a group)Thx again.
Regards -
I've never had that happen. What code are you using to set "select"? Why are you using select[0] in the first case, and select in the second case? I did a similar test with a 4-edged face, and face.material= always set the front face, and face.back_material= always set the back face.
Explanation about the different classes:
An edge is a drawingelement, but it is not a face. It can receive a material, but it cannot receive a back material, having no back. This is the same for curves, text, instances, and groups - they can receive a material, but not a back material.
A face is a drawingelement as well, and thus inherits the .material= method. However, it does have a back, and can receive a back material. Thus, it has a unique method for that purpose.
Rather than creating a .material= method for each subclass to drawingelement, it made more sense to create it for drawingelement and let each subclass inherit that method, then add the requisite .back_material= method only for the face subclass.
Hope that helps,
-
This is how i do it:
I create a face with 4 edges. I select the face
Ruby console:
model=Sketchup.active_model
select=model.selectionIf i then execute the command:
status=select.material="Material1"
Error: #<NoMethodError: (eval):149: undefined methodmaterial=' for #<Sketchup::Selection:0x474fe88>> (eval):149* if I do this command: *status=select[0].back_material="Material1" Material1 **--> SO THIS IS OK** status=select[1].back_material="Material1" Error: #<NoMethodError: (eval):149: undefined method
back_material=' for nil:NilClass>
(eval):149Now today when i try this command:
status=select.back_material="Material1"
Error: #<NoMethodError: (eval):149: undefined method `back_material=' for #Sketchup::Selection:0x474fe88>
(eval):149I don't get it anymore
How can i give all selected objects a certain color/material? -
Sketchup.active_model.selection.each do |ent| ent.material = "Material1" if ent.respond_to? ;material end
- always verify if the receiver supports that (respond_to? :symbol)
- dont use [0], [1], ... on a selection - sometime you receive a face, sometime an edge, sometime nil
- you can do the same for back_material
-
thank you very much
Advertisement