by Chris88 » Mon Dec 05, 2011 12:06 pm
Hi all, i need some help on a specific problem, when i start sketchup with my code by loading my script from the plugin folder or with the command "-Rubystartup" in the cmd, the cuboid will be drawn, but not colored. What i'm doing wrong?
require 'sketchup.rb'
def create_box model = Sketchup.active_model model.start_operation $exStrings.GetString("Create Box") entities = model.active_entities group = entities.add_group entitites = group.entities width = 70 # 70 depth = 60 # 60 height = 25 # 25 color = Sketchup::Color.new(255,240,187) pts = [] pts[0] = [0, 0, 0] pts[1] = [width, 0, 0] pts[2] = [width, depth, 0] pts[3] = [0, depth, 0] base = entities.add_face pts height = -height area = base.area base.material = color base.back_material = color base.pushpull(height) model.commit_operation end
create_box Thanks for help.
P.S. when i execute my script(the same code) in RDE with the Sketchup-Bridge, the color is drawn.
-
Chris88
-
- Posts: 29
- Joined: Wed Nov 02, 2011 5:11 pm
by Dan Rathbun » Mon Dec 05, 2011 2:00 pm
Chris88 wrote:What i'm doing wrong?
SIMPLEYour ignoring what I told you to do before (in previous posts.) ALL YOUR code should be wrapped within your 'author' namespace ( module Chris88, or whatever is unique to you,) to protect it from other code. If the Examples are loading after your code, Examples/box.rb will redefine Object.create_box(), and if the Tools/make_pano_pm.rb is also loading, it will again redefine Object.create_box(). Both of these Google supplied scripts, are examples of POORLY written code.
-

Dan Rathbun
- Top SketchUcator
-
- Posts: 4074
- Joined: Tue Oct 06, 2009 3:06 am
- Location: Florida, USA
- Name: Dan Rathbun
- Operating system: Windows
- SketchUp version: 8
- License type: Pro
- SketchUp use: education
- Level of SketchUp: Advanced
by TIG » Mon Dec 05, 2011 2:50 pm
Apart from sloppy coding you are muddling up 'color' and 'material'. You make a color and then try to assign it to a face as if it were a material - that won't work Make a material. Give that material a color. Add the material to the face. mat=model.materials.add("MyLovelyMaterial") mat.color=[255,240,187] face.material=mat etc etc
TIG
-

TIG
- Global Moderator
-
- Posts: 13980
- Joined: Mon Nov 12, 2007 7:24 pm
- Location: Northumbria UK
- Name: TIG
- Operating system: Windows
- SketchUp version: 8
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
by Chris88 » Mon Dec 05, 2011 3:10 pm
@ Dan: well unfortunately this doesn't help, i have only one file with the aforementioned code. And if i wrapped it in a namespace, the problem isn't fixed. The cuboid is drawn colorlessly. Only the sketchup-bridge in RDE draw it with color, but it should do that from the plungins folder.
-
Chris88
-
- Posts: 29
- Joined: Wed Nov 02, 2011 5:11 pm
by thomthom » Mon Dec 05, 2011 3:32 pm
Chris88 wrote:@ Dan: well unfortunately this doesn't help, i have only one file with the aforementioned code. And if i wrapped it in a namespace, the problem isn't fixed. The cuboid is drawn colorlessly. Only the sketchup-bridge in RDE draw it with color, but it should do that from the plungins folder.
Maybe you can't create geometry like that immediacy as SU starts? What happens if you call your command from the Ruby Console, or activate it from a menu? Just a thought since your file calls your method as it loads with SU - maybe SU isn't ready.
-

thomthom
- Global Moderator
-
- Posts: 17603
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: thomthom
- Operating system: Windows
- SketchUp version: 8
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
-
by TIG » Mon Dec 05, 2011 3:43 pm
You are wrongly applying a color as if it were a material, if you'd reread my post!
On the question of it not working at startup why not add a test loop at the very start of your def, along the lines of unless Sketchup.active_model;until Sketchup.active_model.active_entities;end;end so it waits until there IS an active entities object to add geometry to ???
TIG
-

TIG
- Global Moderator
-
- Posts: 13980
- Joined: Mon Nov 12, 2007 7:24 pm
- Location: Northumbria UK
- Name: TIG
- Operating system: Windows
- SketchUp version: 8
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
by thomthom » Mon Dec 05, 2011 3:53 pm
TIG wrote:On the question of it not working at startup why not add a test loop at the very start of your def, along the lines of unless Sketchup.active_model;until Sketchup.active_model.active_entities;end;end so it waits until there IS an active entities object to add geometry to ???
That that doesn't block the processing queue? 
-

thomthom
- Global Moderator
-
- Posts: 17603
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: thomthom
- Operating system: Windows
- SketchUp version: 8
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
-
by TIG » Mon Dec 05, 2011 3:56 pm
Haven't tried it... He could also try a timer to kick in after a few seconds from loading the code ?
TIG
-

TIG
- Global Moderator
-
- Posts: 13980
- Joined: Mon Nov 12, 2007 7:24 pm
- Location: Northumbria UK
- Name: TIG
- Operating system: Windows
- SketchUp version: 8
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
by thomthom » Mon Dec 05, 2011 4:15 pm
Maybe.
But maybe there's another way around this...
I think we need to step back and figure out the purpose of this exercise, and not get caught up in an issue that could be a non-issue if there are better alternatives.
Why is the method called upon startup? Is it to perform testing? Do you (Chris88) restart SU when you change your code? If you do - then there is an alternative. Just type into the Ruby Console: load 'myrubyfile.rb' to reload the code without restarting SU.
-

thomthom
- Global Moderator
-
- Posts: 17603
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: thomthom
- Operating system: Windows
- SketchUp version: 8
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
-
by Dan Rathbun » Mon Dec 05, 2011 11:19 pm
Chris88 wrote:@ Dan: well unfortunately this doesn't help, i have only one file with the aforementioned code.
Sorry.. wrong issue. I saw create_box() and assumed.. shame on me. Quitting smoking and working on the dirty underside of my car males me grumpy, but I should not have "snipped" at you. My apologies. Chris88 wrote:And if i wrapped it in a namespace, the problem isn't fixed.
True.. but you still need to write code in your own namespace. Chris88 wrote:@ Dan: well unfortunately this doesn't help, I have only one file with the aforementioned code.
Google installs the other two files.. which conflict with each other. You would best chose another method name, if your going to define that method in the global Objectspace. 
-

Dan Rathbun
- Top SketchUcator
-
- Posts: 4074
- Joined: Tue Oct 06, 2009 3:06 am
- Location: Florida, USA
- Name: Dan Rathbun
- Operating system: Windows
- SketchUp version: 8
- License type: Pro
- SketchUp use: education
- Level of SketchUp: Advanced
by Chris88 » Thu Dec 08, 2011 9:52 am
Sorry i wasn't online the last days. First of all thanks for your suggestions. I don't prefer the method with the timer, because i have to close and open SU many times in a row. But i like the method "load rubyscript.rb" i will test it. And thanks to TIG, your help me a lot. @Dan It's ok 
-
Chris88
-
- Posts: 29
- Joined: Wed Nov 02, 2011 5:11 pm
by Chris88 » Thu Dec 08, 2011 10:15 am
This unless Sketchup.active_model;until Sketchup.active_model.active_entities;end;end and this load 'myrubyfile.rb' are the solutions for my problem, well it's really so, that SU isn't ready to load the color. Thanks again.
Can anyone say how to make the material transparent, please?
-
Chris88
-
- Posts: 29
- Joined: Wed Nov 02, 2011 5:11 pm
by thomthom » Thu Dec 08, 2011 10:35 am
Chris88 wrote:Can anyone say how to make the material transparent, please? http://code.google.com/apis/sketchup/do ... tml#alpha=Note that the Material object doesn't use the alpha channel of the Color object. - Code: Select all
m = Sketchup.active_model.materials.add( 'MyMaterial' ) m.color = [255,128,0] m.alpha = 0.5
-

thomthom
- Global Moderator
-
- Posts: 17603
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: thomthom
- Operating system: Windows
- SketchUp version: 8
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
-
by Chris88 » Thu Dec 08, 2011 10:42 am
Great! Thank you, i like this forum more and more.
Merry Christmas and happy holidays to all!
-
Chris88
-
- Posts: 29
- Joined: Wed Nov 02, 2011 5:11 pm
Return to Developers' Forum
|