Material is deleted when cloning
-
Can someone explains why this happens ?
test = Sketchup.active_model.materials.current #<Sketchup;;Material;0x8a19480> test2 = test.clone #<Deleted Entity;0x8a19278>
I'd like to store a material in a class variable to use it later, if I do not clone, and the selection change, test will not contain the previous material I want, but the new one selected.
Thank you
-
I just did the following in SU2014 and got a SPLAT!
Choose a material that is not in the model.
Open console.
test = Sketchup.active_model.materials.current test.name
Choose a material that IS in the model.
test2 = Sketchup.active_model.materials.current test2.name
Everything is fine.
Now,.. try to get the name of the previous material.
test.name
-- > SPLAT -
Anyway. save the name of the material, and perhaps also it's texture filepath, if it is not yet IN the model.
Test any material reference for validity before using it. If there is no current material
nil
may be returned, which evaluates asfalse
.if matl && matl.is_a?(Sketchup;;Material) # go ahead and use the matl reference in code matl_set = Sketchup.active_model.materials if matl_set.include?(matl) # do something end end
-
The Ruby methods
clone
anddup
, do NOT yet work upon SketchUp API classes.We discussed this in previous topics:
-
Thank you, I fixed my problem by processing only materials used in the model:
aMat = Sketchup.active_model.materials.current if aMat != nil and Sketchup.active_model.materials.include?(aMat) ... end
-
@dan rathbun said:
The Ruby methods
clone
anddup
, do NOT yet work upon SketchUp API classes.We should improve this. But they would not make sense for Entity based classes as instances are persistent and have to be created via entity.add_*.
-
@dan rathbun said:
I just did the following in SU2014 and got a SPLAT!
Choose a material that is not in the model.
Open console.
test = Sketchup.active_model.materials.current test.name
Choose a material that IS in the model.
test2 = Sketchup.active_model.materials.current test2.name
Everything is fine.
Now,.. try to get the name of the previous material.
test.name
-- > SPLATI cannot reproduce this. Did you submit the splat? Did you include any info I can use to look it up?
Do you see this consistently? (Can you do a video recording?) -
I do think I sent in the Splat Report.
I do not have video capture software installed (unless it comes with Windows 7?)
This was 2 weeks ago... I haven't tried since.
-
Did you enter any details into the BugSplat? (So we can search for it.)
-
I entered the steps that caused the splat, and then copied from the splat dialog, into the above SCF report.
-
SU2014 Win?
-
Ah! Found the crash report. And I realized I'd overlooked the last step in your instructions - accessing the name of the first material after it was not current any more. It's another bug where Ruby is allowed to get a handle to a transient material. I'm logging a new issue.
-
@tt_su said:
Ah! Found the crash report. ... I'm logging a new issue.
Advertisement