Found it...
it's the RUBY_VERSION const!
cheers
Found it...
it's the RUBY_VERSION const!
cheers
Hi
I've been trying "ruby -v" in console but doesn't work (on SU2013 at least)
I can get the Sketchup version with Sketchup.version and .version_number but then I would have to know wich build use wich ruby...
I remember I could get that info in SU ruby console one time but I can't find it by googling! I just find "ruby -v".
thx
ako
Bug posted in the GitHub Issues field!
I never did that but will learn how to.
Glad to participate...
I'm trying to save all the .visible? .caption(for lbls) and .value(for inputs) for now.
I would like to create a window where there's a "add item" on the window that add a SKUI_group on the window corresponding to the new item...
My object have only two instance variables for now, the number of items(an int) and the SKUI window.
For the non customisable plugin I could save the .visible? .caption and .value by listing them manualy in my Save method but with a customizable window it would probably be painful...
thanks for your answers
AND THANKS A LOT FOR SKUI (sorry for shouting but i really mean it)
P.S. I noticed a little bug: I have to initialise myself the .visible of each visible unmodified SKUI items before saving them because it was returning nil with the .visible? method if .visible= was never used.
Hi
Is it possible to prevent the closing of a Webdialog window (or even better with SKUI) in order to get the famous "File has not been saved: /cancel/save/quit anyway/" window.
This while quiting the webdialog window and/or while quiting SU with that window still open.
thanks
ako
I tried to save an object containing an SKUI window object (using marshal) and had a bad type error... I suppose it's not possible to save an SKUI window with marshal due to it's limitations:
*Marshal can't dump following objects:
anonymous Class/Module.
objects which related to its system (ex: Dir, File::Stat, IO, File, Socket and so on)
an instance of MatchData, Data, Method, UnboundMethod, Proc, Thread, ThreadGroup, Continuation
objects which defines singleton methods*
I did it manualy this time but wonder if there's something similar to Marshal with what I would be able to save objects containing SKUI windows for later use.
I remeber i saw somthing with a name looking like "yalm"..
Would Pstore do it?
Many Thanks
ako
Hi
I decided to use Marshal as I suppose I won't do better! (though it's version dependent and has some security issues)
I found some code examples modified and ran it... cool stuff. But there are two things I don't understand in the code I copied!
class MyObject
def initialize(value)
@value = value
@arr= [4,5,6]
end
attr_accessor ;value, ;arr
def incr
@value=@value+1
end
end
obj=MyObject.new(99)
file_name=UI.savepanel("Save","",".oob")
File.open(file_name, 'w+') do |f|
Marshal.dump(obj, f)
end
File.open(file_name) do |f|
@obj2 = Marshal.load(f)
end
obj3=@obj2.clone
obj3.incr
puts obj3.value,obj3.arr
Why must I use @ or $ for my obj2?
And why the code below doesn't close the file in comparaison to the one above. Is that the "block form" advised in Dan's post? I miss the mechanics of that "do ||" statement, I tought it was just a looping tool. ---> I read this now: http://blog.rubybestpractices.com/posts/gregory/009-beautiful-blocks.html
f=File.open(file_name, 'w+')
puts f
Marshal.dump(obj, f)
#need f.close!
Thanks a lot for your answers!
ako
Hi
I realised my own_objects and basic objects like strings are not referenced the same way!
class MyObject
attr_accessor ;value
def initialize(value)
@value = value
end
end
obj1=MyObject.new('hip')
obj2=obj1
obj2.value='hop'
puts obj1.value # ==> return 'hop'
puts obj1.object_id,obj2.object_id # ==> they have the same id! (pointer?)
a='hip'
b=a
b='hop'
puts a # ==> return 'hip'
puts a.object_id,b.object_id # ==> they have a different id! (reference?)
How can i know the type of object I use will automaticaly clone when a copy is modified ?
Can I force ruby to act the same with all objects (clone any copied object using = without the need to use the .clone method)?
Thanks
ako
Thank you very much!
This helped me a lot and I have ALL the infos I needed!
ako
Hi
I wonder if i can create functions that load/saves all the instance variables of an object in a convenient way that could be used after for any object... (or/and if it has been done already (couldn't find it on Google..))
I've just started to use .each and other ruby nice stuffs so i'm a bit confused and don't know what is actualy possible.
Saving
def Save_Obj_Inst_Vars(FILENAME,object)
fileout = File.open FILENAME, "w+"
fileout.puts object.class #write the class type to check compatibility when loading
object.instance_variables.each do |the_var|
fileout.puts the_var.class
fileout.puts the_var
end
fileout.close
end
Loading
def Load_Obj_Inst_Var(FILENAME,object)
filein = File.open FILENAME, "r"
filein.rewind #needed if file was not closed?
class_type=filein.gets
if class_type==object.class
object.instance_variables.each do |the_var|
typ=filein.gets
val=filein.gets
case typ
when 'int'
val=val.to_i
when 'float'
val=val.to_f
when 'bool'
val=val.to_b
when 'string'
# already string? do nothing?
end
the_var=val
end
else
puts 'bad type!'
end
filein.close
end
Do I have a chance to get something like that working? will the instance_variables array be in the same order all the time with the ".instance_variables" method so I can load it safely? What would be a classy ruby code style to do this? Can I differentiate public and private instance variable (the ones with att_accessor)?
many thanks
ako
I'm using SKUI and stopped the pain of webdialog learning... you do a lot of things with it!
http://www.thomthom.net/thoughts/2013/07/skui-a-gui-framework-for-sketchup/
Hi,
Is there a way to ensure aspect is the same with win and mac (maybe a common standart font?). Has anybody achieved this?
Is it possible to use a backround picture? (that's why i would need same aspect..)
thx
Great!
i know understand! i'll need to redefine my points and vectors with arrays of double floats if i want to reach machine epsilon accuracy!or use sketchup's ones but with sketchup precision.
What i still don't understand is why it wouldn't round when calling .to_i (so may be getting the difference with math.round will be solution to keep working with the Geom module).
thx a lot for the time you spend on my problem Aerilius!
ako
@aerilius said:
What are you trying to do? If a "split" gives a value near an integer (or a difference near zero), then it is usually not relevant for SketchUp geometry. You can't create edges of such short lengths. What are you trying to split?
it's in a part of the code where sketchup visible geomtery is not used. it's pure applied analytical geometry (no edges or faces exists at that time, eveything is vector and points and lenght(but not edge.length !)). it evaluates how many steps of lenght "l" are in a segment of lenght "L" and that evaluation is an integer. if for example 4*"l" is 10^-15 to "L" i must have 4 steps as a result. if 4*"l" is 10^-15 past "L" the result should be 3. It is not probable at all that - x is an integer and x"l"=="L"* - and if it is the case the result should be 4 in my example. A wront number of evaluated steps will result in buggsy result.
sorry for my english..
thx
@aerilius said:
I cannot reproduce this in SketchUp 7.1 (Ruby 1.8.0) to SketchUp 2013 (1.8.6) and Ruby 2.0.0. But I remember I once had an example that gave 0.999β¦ or 1.0 depending on the order of operants. I can't get it to work again on my 64bit processor (maybe it gives a different result on a 32bit).
Did you select these numbers to invoke this problem for testing, or does this really occur in practice in your plugin? If so, wouldn't it be better to use
Math.round
instead of truncating withto_i
?As for workarounds, precision is usually not a problem I need to care about, especially since SketchUp has its own tolerance where unprecise floats still fit in. If you really deal with big numbers or need highest precision, you could use
BigNum
orRational
.
Otherwise it often helps to rearrange your calculation to avoid adding big and small numbers (or using offsets).
It happens in the plugin. The a,b,c values you see are values calculated in the plugin 100+ code lines from last inputbox.
The Math.round
is not an option as i need to know how much is left from splits and some times the split is near the edge of the step so it gives a value near to an integer (my problem) but is actually not an integer. I'll check with Rational
as 64+bit numbers still have a machine epsilon anyway.
thx
PS: i had two questions in the first post:
how do you people usualy manage that kind of ".to_i" problem when operated after a division?
and how can i "puts" the real float that's in memory and not a rounded one?
@aerilius said:
That's possible.
Can you give a reduced example that includes the values of delta_t4, lstep, reste, and with readable variables like a, b, c.Also
to_i
truncates (rounds towards 0), and does not round to the nearer full number.
puts
turns the input into a string, so it is a good idea to test withto_s
(orinspect
) to exclude the case that the problem is in the numeric to string conversion.
here is an ouput console with readable var names:
a
60.7869946176981
b
12.7368848825351
c
0.772516606556568
result of (a/b)-c (auto string conversion)
4.0
result.to_s
4.0
result.to_i
3
if i make the calculation (a/b)-c using the values shown on the console with a "simple" calculator i get 4.000000000000003.
thx
ako
hi and thanks for all the good things you do here and that helped me a lot already!
i have a problem with debugging a variable. when i use puts i get inconsistent values
the following code:
puts nb_temp=(delta*1.0/step*1.0)-(rest*1.0) puts nb_i=nb_march_temp.to_i
prints to the console:
4.0
3
i multiplied all numbers with 1.0 because it saved me several times. But this time in order to get my models correctly drawn i have to add:
puts nb_temp=0.000000000000001+(delta*1.0/step*1.0)-(rest*1.0)
What is ugly code to me. This code will print:
4.0
4
if i add 0.00000000000001 ( so 10^-14 instead of 10^-15) it puts:
4.00000000000001
4
i suppose it's a "machine epsilon" problem... http://en.wikipedia.org/wiki/Machine_epsilon
how do you people usualy manage that kind of ".to_i" problem when operated after a division? and how can i "puts" the real float that's in memory and not a rounded one?
thx
ako
Hi and thx for being here!
I have started a plugin with several inputbox following each other and i realised the width of the input box varies mainly with the first line but not really...
Some lines have partially hidden text. But the same line of text will be ok in a box and not in the following. I could not find any official syntax about it.
So i wondered if anyone has a tip to get those inputbox wider, the widest...?
grtz
ako
thanks! but this is vector to angle...
what i'm looking for is a method that ouputs a normalized Vector3d..
the arguments would be it's projection angle on xy plane and xz plane (with x axis).. actualy i already made a method with cos/sin myself but i'm afraid it will slowdown calculations when in loops and suppose a method from ruby/sketchup stds would be faster as i suppose it is in a lower level...
grtz
abakobo