The doesn’t always tell the whole tale. Many things you discover as you go along.
![Sketchup Produces Bug Splat All The Time Sketchup Produces Bug Splat All The Time](https://sjc1.discourse-cdn.com/sketchup/uploads/default/original/2X/8/8417fe19988a5ecd301a77736afffb7da9aa6c1e.jpg)
I’ve collected what I have come found out so far. Materials Collection has Secret ItemsGiven a model that contains two materials and an Image element you would think that model.materials.length returns 2. But instead it returns 3 – this reveals that Image entities contribute to the internal material list in a model. Not so surprising when you discover that.The curiosity is that when you iterate the collection with #each you do not get any of the materials that belongs to Image entities.
Image Opacity Removing MaterialsBefore there was no API method to remove a material from a model. The only workaround way was to ensure all other materials was assigned to some entity and purge the materials collection., which M1 introduced, had some unexpected behaviour.
Sketchup Virtual Builder Light plugin makes it possible to add Planning-Scheduling information to any Sketchup model and see the model being constructed in time, in Sketchup. Sketchup Virtual Builder Light plugin can be used in any project as a way to determine and analyze an initial scheduling in an early phase.
The material was only removed from the material list, but not from the entities in the model. So the result of using it is a model with invalid materials assigned to its entities. If you use the Fix Problems function in SketchUp it will complain about these invalid materials and remove it from the front side of faces – but not from the backside. To avoid a corrupted model you need to manually remove the material from all entities before using Materials.remove(material).The is that the method exposed a low level C function – which didn’t clean up the model as one would expect. Hopefully it will be updated in the future as the current implementation is very prone cause some annoying model corruption.I wrote a method to safely remove materials from a model. (Example is extracted and adapted from my.).
041424344module MaterialsEx# Safely removes a material from a model. # # @param Sketchup::Material material # @param Sketchup::Model model # # @return Boolean def self. Remove ( material, model = Sketchup. Activemodel ) # SketchUp 8.0M1 introduced model.materials.remove, which turned out to be # bugged. It didn't remove the material from the entities in the model - # leaving the model with rouge invalid materials.
# To work around this all entities are processed before the method is called. # The workaround for older versions also require this to be done. For e in model. Material = nil if e. (:material ) && e. Material materiale. Backmaterial = nil if e.
![Sketchup Produces Bug Splat All The Time Sketchup Produces Bug Splat All The Time](/uploads/1/2/5/5/125584885/209785848.jpg)
(:backmaterial ) && e. Backmaterial materialend for d in model. Definitions next if d. Image?for e in d. Material = nil if e. (:material ) && e. Material materiale.
Backmaterial = nil if e. (:backmaterial ) && e.
Backmaterial materialend endmaterials = model. Materials if materials. (:remove )materials. Remove ( material ) else # Workaround for SketchUp versions older than 8.0M1. Add all materials # except the one to be removed to temporary groups and purge the materials.tempgroup = model. Addgroup for m in model. Materials next if m materialg = tempgroup.
Material = materialendmaterials. Erase!true end end end # module. Module MaterialsEx# Safely removes a material from a model.## @param Sketchup::Material material# @param Sketchup::Model model## @return Booleandef self.remove( material, model = Sketchup.activemodel )# SketchUp 8.0M1 introduced model.materials.remove, which turned out to be# bugged. Face.material = mat1face.material = 'red'face.material = 0xff0000Note the hexadecimal notation, it would indicate from the line before it that it produces a red material – as would people familiar with from HTML and CSS. But the reality is that it produces a blue material. The format SketchUp expects is 0xBBGGRR. Material.alpha vs Color.alphaIf you use a Color object, or array, to assign a material then you might expect that the #alpha value in the Color object transfers to the Material object.
Instead the #alpha value is ignored and you need to make the material transparent you must use Material.alpha= – which takes a float value between 0.0 and 1.0 as oppose to Color that take an integer 0-255If you question the point of Color.alpha – as of SU8 you can use View.draw with transparent colours. Though you can wonder what the purpose was before that. Bug with Materials and Color Alpha ChannelWhile making the graphics for this article I came across a Material bug related to the alpha channel in Color.As seen in the screenshot, the shadow cast from the colour swatch appear as though the swatch colours are transparent. The material’s alpha channel is opaque. But material.color.alpha is 0. I used the “Match Color on Screen” feature to pick a colour from a PNG image in an Image entity.If the material’s alpha property is changed it overrides the color’s alpha, but the effect is restored when the material alpha is restored to fully opaque.When any of the HSL properties is adjusted in the material editor the color’s alpha channel is corrected to be opaque.It is possible to recreate the bug, via the Ruby API, by assigning the material with a color where the alpha channel is zero. This bug can be seen in SketchUp 6, 7 and 8.
(No other versions tested.) Current Material BugSplat WarningWhen you use model.materials.current there is a possibility of causing BugSplats. If the user has selected a material from the Material Library instead of picking a material that is already in the model and you try to apply that to an entity in SketchUp it will quickly BugSplat.To avoid that you always need to check if model.material.current is a material in the model before using it.
Like so: materials.include?( materials.current )An alternative is to attempt to re-create the current material – effectively adding it to the model yourself. The problem arise when the material contains a texture.
If that material doesn’t refer to the texture with a path that is on the current computer the material needs to be extracted – and you cannot do that with the current API without the material being applied to some entity.I wrote a method that will add the current material to the model if it doesn’t exist. It does have a caveat though, so read all the comments. 5969798module MaterialsEx# @note Do not use within a startoperation block. This method uses a temporary # operation which will break any already initiated operations. # # @return Sketchup::Material def self.
Safelygetcurrentmaterial ( )model = Sketchup. Activemodelmaterials = model. Materialsm = materials. Current return m if m. Nil?# Check if material already exists. If it does - reuse it.name = m.
Name if x = materials name if x. Alpha # No texture applied. Current = xreturn xendxbasename = File.
Basename ( x. Filename )mbasename = File. Basename ( m. Filename ) if mbasename m. Filename # If the texture only have a filename - not a path. If xbasename m.
Filename &&x. Current = xreturn xend else # If the texture only have a filename with full path. Filename m. Filename &&x. Current = xreturn xend end else end end # Transfer name and colour.newmaterial = materials. Add ( name )newmaterial. Alpha # Any textures require special attention.
If the filename contains a valid # path to an existing file nothing special needs to be done. # # But if the filename refers to a non-existing file it needs to be written # out to a temp file. This is where things become a bit risky and hacky. # Because TextureWriter doesn't accept Material objects the orphan material # needs to be temporarily applied to the model (risky). # # Materials from SketchUp's default library only contains the name of the file # without any paths. This is because the texture is located only within the #.skm.
Texturefilename = m. Filename if File. ( filename )newmaterial.
Texture = filenameelse # Create temp file to write the texture to.temppath = File. Expandpath ( ENV 'TMPDIR' ENV 'TMP' ENV 'TEMP' )tempfolder = File.
Join ( temppath, 'sutmpmtl' )tempfilename = File. Basename ( filename )tempfile = File. Join ( tempfolder, tempfilename ) unless File. ( tempfolder ) Dir. Mkdir ( tempfolder ) end # Create temp group with the orphan material and write it out. # # Wrap within startoperation and clean up with abortoperation so it # doesn't end up in the undo stack.
# # (!) This means this method should not occur within any other # startoperation blocks - as operations cannot be nested.tw = Sketchup. Startoperation ( 'Extract Material from Limbo' ) beging = model. Material = mtw. Load ( g )tw. Write ( g, tempfile ) ensuremodel. Abortoperation end # Load texture to material and clean up.newmaterial.
Texture = tempfileFile. Delete ( tempfile ) endnewmaterial. Height endmaterials. Current = newmaterialnewmaterialend end # module.
Module MaterialsEx# @note Do not use within a startoperation block. This method uses a temporary# operation which will break any already initiated operations.## @return Sketchup::Materialdef self.safelygetcurrentmaterialmodel = Sketchup.activemodelmaterials = model.materialsm = materials.currentreturn m if m.nil?# Check if material already exists. If it does - reuse it.name = m.nameif x = materials name if x.color.toi m.color.toi && x.alpha m.alpha# No texture applied.if x.texture.nil? I created and uploaded some kitchen furniture models using SU6. At the the time, the models were in fact photo-realistic, clear and an exact match to my own furnishings. Wanting to show the table and chairs to a friend, to promote SketchUp and explain the concept and importance of components vs. Groups, I open the file and found the texture quality had gone to hell.
It looks like a haze covers the whole and, before you ask, my “fog” option is not activated.Does SU8 handle textures differently that SU6 or SU7? I had a pro license for the 6 and 7 versions but am now using the SU8 free.
Though I haven’t tried since wiping out my system and installing OS X 10.7.3 on my iMac, I suspect that neither Pro 6 nor Pro 7 will work properly.I am illiterate when it comes to using Terminal or creating or even understanding scripts/plug-ins.In laymen terms, is this aforementioned information providing a fix for my issue? Is it possible that my own display is the cause of this “issue”?