Updating sketchup broke my (very simple) extension
-
Updating sketchup broke my (very simple) extension…
I made a very simple ruby script that would open a text file with four values (x, y, z, V). It would then draw a box of known size and color using the following technique:
case value when 5.91..1000 then face1 = entities.add_face pt1, pt2, pt3, pt4 face1.material = [255,0,0] face1.pushpull size, true
I would draw several hundred boxes doing this and when done I would use transparency effects to ‘see’ through them. I haven’t done this in a few months, but I know it was working before I updated to the newest version of 7.1 (free). I tried to today and I noticed that when I use transparency it now shows me the inside of each box and this means I can’t see any other boxes beyond the first layer. As best I can tell the default color is being applied to every ‘inner’ surface in each box, which causes my extension to be useless.
Does anyone know how to change this? (either making the default color 100% transparent, or improving how I construct the boxes to I can define the inner colors?)
I’m in need of this script and I just can’t seem to figure it out on my own.Thanks
-
SU 7.1 changed the render engine SU uses. It required some people to update their graphic card driver. Not sure if this is the case - but worth checking.
Could you post your full script?
-
Here is one of the scripts I would use (I change it based on how many things I’m importing and the amount of color I’m using. It’s pretty simple, but maybe there is a more efficient way to do this? I’ll try updating the graphic drivers I guess. Thanks.
require 'sketchup' Sketchup.send_action "showRubyPanel;" UI.menu("PlugIns").add_item("Draw boxes") { UI.messagebox("Beginning now") # Call method. draw_boxes } def draw_boxes # Get handles to model and the entities collection it contains. model = Sketchup.active_model entities = model.entities File.open('C;\Program Files\Google\Google SketchUp 7\Plugins\data.txt').each_line {|line| values = line.split(' ') x1 = values[0].to_f y1 = values[1].to_f z1 = values[2].to_f color = values[3].to_f size = 5 x2 = (x1 + 5) y2 = (y1 + 5) # Create a series of "points", each a 3-item array containing x, y, and z. pt1 = [x1, y1, z1] pt2 = [x2, y1, z1] pt3 = [x2, y2, z1] pt4 = [x1, y2, z1] case color when 5.91..1000 then face1 = entities.add_face pt1, pt2, pt3, pt4 face1.material = [255,0,0] face1.pushpull size, true when 5.71..5.90 then face2 = entities.add_face pt1, pt2, pt3, pt4 face2.material = [255,86,25] face2.pushpull size, true when 5.51..5.70 then face3 = entities.add_face pt1, pt2, pt3, pt4 face3.material = [255,220,25] face3.pushpull size, true when 5.31..5.50 then face4 = entities.add_face pt1, pt2, pt3, pt4 face4.material = [254,254,76] face4.pushpull size, true else face5 = entities.add_face pt1, pt2, pt3, pt4 face5.material = [0,0,255] face5.pushpull size, true end } end
-
When posting longer snippets like that it's best to wrap it in a Code tab to you preserve whitespace. Or just upload the .rb file.
Will have a look at it later today.
-
My mistake. I will do that next time.
Thanks for taking a look. I'm hoping this is simple solution...
-
@jackjack1234 said:
I tried to today and I noticed that when I use transparency it now shows me the inside of each box and this means I can’t see any other boxes beyond the first layer. As best I can tell the default color is being applied to every ‘inner’ surface in each box, which causes my extension to be useless.
Not sure what you are describing or what you are expecting. Can you post a screenshot?
In SU, if you paint a transparent material to a face and the other side of the face has the default material, then the other side should take on the appearance of the transparent material.
This has not changed in SU 7.1Could it be that you need to adjust the Transparency quality of the Style you're using?
I don't see anything about your code that I can relate to any of what you describe.
-
Sure I can show you what I mean. I found an old laptop with 7.0 still on it. The two figures that follow are from the side and from above.
I used the exact same script/data in both shots, so the only difference is that the new one is made with 7.1 vs 7.0. If you want to see for yourself what I think is happening try this in sketchup:
• Draw a square
• Paint the surface red
• Pull it up
• Delete a side and notice the color inside is now grey! That’s the grey I’m seeing in the second ‘bad’ image
• In the old version the color inside would be red! I think that is what’s causing all of this. I’m just not sure how to control the inside surface color in my script (as you can probably tell, I’m not the best programmer in the world).
Does that clarify my problem for you?(Also I tried updating my graphics drivers but that didn’t change anything… worth a shot though)
Since I have this laptop working now, I’m okay for the moment. But I’d rather fix this issue since it seems like it should be simple… Any ideas?
-
You could try doing it a little differently...
Make a new color -color=[r,g,b]
Then make amaterial=model.materials.add("newMaterial")
Then set its colormaterial.color=color
Then give that material some transparency -material.alpha=0.5
THEN apply that material to theface.material=material
AND thenface.back_material=material
? -
Thanks! You just solved my problem! (I didn’t copy that exactly, I actually just added in the face.back_material = [r, g, b] and defined before doing the push.pull and that solved everything (odd that it worked in 7.0).
I will work on doing it a bit more elegantly with defining materials and just calling for them because that does sound like a much better solution.
While you are solving all my problems, here is another question. I’ve always wanted to import a very large set of boxes (voxels, whatever you want to call them) using this technique. But any time I try it with more than say 15,000 using the code I gave above my computer just sits there for hours appearing like it’s doing nothing so I cancel the construction.
I asked this along time ago on this forum and someone said that it was because each time I did a push.pull action sketchup would check with EVERY piece of the geometry (built that that point) and look for intersections. So as I built more and more boxes, I increased the construction time more and more for each element.
Do you have any idea if there is a more efficient way I could do this? (or a way to disable that check). Maybe building all the faces at the same time and doing some sort of single ‘group’ push pull? Any thoughts?
-
The more geometry is in the context you add to the more time SU will spend when you add new geometry.
What you could do, is make a voxel component. Then just add component instances and apply the material to the component instance. That way there are less entities in the context you add to - and you should also see a decrease in file size. -
Also, look into
model.start_operation
. Make not of the second argument it accepts - which will disable the UI until you callmodel.commit_operation
.
Wraps the whole thing into one undo-able operation and increases the speed. -
That makes a lot of sense. I guess the real problem is I’m not very experienced with components.
Would this work:
At the start of the script create a few components representing every possible color element (so 5 colors = 5 components). Then as the script goes and reads from my file it goes through each ‘v’ value it assess it and places the correct colored component in that location (based on the x, y, z).
If that would work, do you know any simple tutorials that do this I could use to make this from? (I tend to learn best be either reverse engineering or altering a similar example). Like I said before, I’m still a pretty green programmer, but so far this has been very helpful.
I think if I can figure out how to save a component in ruby and later call and place a component I should be able to get this to work. -
You only need to create one component definition. You can apply different materials to each component instance. When you apply materials to component instances and groups the faces inside with default material will inherit the group/instance's material.
That's what makes components so great. You can model a car - do all the detailing, add material to the wheels windows etc, but leave the body with default material. So you can then place lots of instance with different materials.
something like:
` model.start_operation('Voxel Thingymajiggy', true) # wrap everything in one operation and disable the UI
voxel_def = model.definitions.add("Voxel") # create new definition
voxel_def.entities.add_face(...) # build the voxel here<loop> read file
calculate a transformation to place the instance
voxel = model.entities.add_instance(voxel_def, transformation)
voxel.material = myPrettyMaterial</loop>
model.commit_operation`
Very quick and dirty pseudo-code...
Advertisement