@jim said:
A dumb question, I think. Of course "Meter" is always "Meter" in any language.
Actually not, it's 'metre' in French (and I think most of the EU uses that spelling.) But it's still the same unit.
@jim said:
A dumb question, I think. Of course "Meter" is always "Meter" in any language.
Actually not, it's 'metre' in French (and I think most of the EU uses that spelling.) But it's still the same unit.
I would say this is a bug, as I would have tried using view.drawing_color=
@jim said:
And if so, how do I access them in a language-independent way?
Update - Ah, by index number?
YES.
model = Sketchup.active_model
manager = model.options
provider = manager['UnitsOptions']
see:
class OptionsManager
http://code.google.com/apis/sketchup/docs/ourdoc/optionsmanager.html
class OptionsProvider
http://code.google.com/apis/sketchup/docs/ourdoc/optionsprovider.html
interface OptionsProviderObserver
http://code.google.com/apis/sketchup/docs/ourdoc/optionsproviderobserver.html
iterating the members of 'UnitsOptions' gives:
UnitsOptions Provider
LengthPrecision ; 4
LengthFormat ; 1
LengthUnit ; 0
LengthSnapEnabled ; true
LengthSnapLength ; 0.0625
AnglePrecision ; 1
AngleSnapEnabled ; true
SnapAngle ; 15.0
SuppressUnitsDisplay ; false
ForceInchDisplay ; false
Notice how there are 10 options, and 10 controls in the dialog.
Also, important, often you must call UI.refresh_inspectors after changing options via Ruby, in order to see the changes reflected in the dialogs. (This is true of the Styles dialog, at least.)
@unknownuser said:
I want my "download to model" button work just like the 3D Warehouse button works..?
see...
@unknownuser said:
http://code.google.com/apis/sketchup/docs/releases.html
What's new in SketchUp 7.0 M1
Load Definitions from the Web, or Save to Disk
- Ability to download a definition from URL
model.definitions.load_from_url(url, download_handler)
- Ability to Save components to disk from the API
my_definition.save_as(path)
For more info on DefinitionList.load_from_url (including a prototype download_handler,) see:
http://code.google.com/apis/sketchup/docs/ourdoc/definitionlist.html#load_from_url
For info on ComponentDefinition.save_as, see:
http://code.google.com/apis/sketchup/docs/ourdoc/componentdefinition.html#save_as
.
@thomthom said:
This does not update the Edge colour in the viewport. But
Sketchup.active_model.rendering_options['ForegroundColor']value is still updated.
@ThomThom - I get an immediate change in the displayed edge color when I change rendering_options['ForegroundColor'].
You didn't turn of your DCs again did ya?
EDIT - Oh never mind, you mean within a Tool.
@thomthom said:
Typing
Sketchup.active_model.rendering_options['ForegroundColor'] = 'pink'into the ruby console changes the edge colours to pink.
How does this differ from view.drawing_color="pink" ??
@ThomThom, ... last week when I was playing with the RenderingOptions, the controls in the SU dialogs did not reflect my changes until I called UI.refresh_inspectors. (I recall we had a discussion with TIG in the Observers thread, about whether these changes were temporary or permanent; I didn't realize at that time, that the dialogs needed to be refreshed.)
Regarding view draw changes, remember that ver 7.1 added View.refresh
.. what's that old saying?
"Believe nothing that you read, and half of what you see!"
@jim said:
Would a kind Mac user (or 2) open the Ruby Console, and give the result from entering:
**$DEBUG**
The 'Pick-Axe' book says falseis the default.
@jim said:
**$VERBOSE**[alias]**$-w**
The 'Pick-Axe' book says falseis the default and known as 'medium mode'.
When set to nil, it is 'silent mode'; when set to true, it is 'verbose mode'.
The reason for the $-w alias 'flag', is that $VERBOSE is [supposed to be] the conditional argument used by warnings. But, something's fishy..
(from Ruby.h, ver 1.8.6, line 562..564, Language="C" )
%(#008B8B)[void rb_warning __((const char*, ...)); /* reports if-w' specified /
void rb_sys_warning __((const char, ...)); /* reports if -w' specified */ void rb_warn __((const char*, ...)); /* reports always */]
So.. rb_warn is NOT supposed to check $VERBOSE, and rb_warning IS.
What's weird is that the Ruby method Kernel.warn is documented as if it calls rb_warning, instead of rb_warn; and the Core RDoc actually gives two internal examples, one in Pure Ruby (see it) and one in C (see it) that are written to act like rb_warning is supposed to act. (Note, the C example is really named 'rb_warn_m'.)
But in practice... I find that Kernel.warn acts like rb_warn is supposed to act, and it does not matter what $VERBOSE is set to. The message is always sent to $stderr.
This has forced me to make my 'warn' calls work the way they should, by doing this:
# Send warning only if in Verbose mode
warn('My Informational Message') if $VERBOSE
# Send warning unless in Silent mode
warn('My Important Message') unless $VERBOSE.nil?
# Send warning no matter what Verbose mode
warn('My Critical Message that MUST be displayed!')
BUT.. I'm sick of doing this workaround!
I want to make three warn methods, that work the way they should.
Firstly, the current warn needs to be renamed old_warn (or something else.)
And define a replacement warn! that has typechecking, and returns true if no IO error occurs. (The original just returned nil.)
Then define a new warn, that displays (returns true,) unless in Silent mode (returns false.)
Third define a new warn?, that checks and only displays if $VERBOSE is true (and returns true, otherwise returns false.)
(If there's any problem with the $stderr IO object, an Exception should be raised by the object itself.)
Example Ruby override code: ### under REVISION to a Mix-In Module ###
# file warn_ovr.rb
# Make Warnings work the way they should.
#
# by; Dan Rathbun - 16 MAR 2010 - Palm Bay, FL, USA
#
# TERMS; Public Domain
module Kernel ##<<----<<< this will change in next Revision
### under REVISION to a Mix-In Module with a different module name
# alias the old warn method
alias_method(;old_warn,;warn)
# warn! will always send to $stderr
# regardless of $VERBOSE setting
def warn!(msg)
unless msg.is_a?(String)
raise(TypeError,'String argument expected.',caller(1))
end
$stderr.write(msg + "\n")
return true # no IO error occured
end
# warn will now send to $stderr
# ONLY if $VERBOSE is not Silent mode (nil)
def warn(msg)
unless msg.is_a?(String)
raise(TypeError,'String argument expected.',caller(1))
end
unless $VERBOSE.nil?
$stderr.write(msg + "\n")
return true
else
return false
end
end
# warn? will send to $stderr
# ONLY if $VERBOSE is in Verbose mode (true)
def warn?(msg)
unless msg.is_a?(String)
raise(TypeError,'String argument expected.',caller(1))
end
if $VERBOSE
$stderr.write(msg + "\n")
return true
else
# We return false if $VERBOSE is nil or false
return false
end
end
end # Kernel
EDIT: Code changed.
@driven said:
@Dan #!ruby warn_ovr.rb returns nil
john
@John..
The first line is a boo-boo, should have taken out all of the unix-like load directive. (The file is not meant to run from the command line anyway. It was meant to be a 'require' script.)
I'm rewriting that now as a Mix-In Module, rather than an override to module Kernel. (Backward compability issues, and so forth.) It would be 'forever' before we would hope to see any changes or additions to the Kernel module anyway, with all the other things they need to fix. (I had to laugh when I saw that Ruby 2.0 was due, or estimated to be complete 01/19/2038.)
@jim said:
The
forloop in Ruby really uses the.eachmethod behind the scenes. ... Although, I can't recall where I learned that.
In a normal MSIE browser window, if an error occurs (and you have Internet Options > "Advanced" (tab) > "Browsing" (group) > "Display a notification about every script error" unchecked,) you will not see a Error Popup, but there wil be an error icon in the lower left corner on the Status bar. Clicking this icon will bringup the Error Popup dialog. If you have Visual Studio installed it will likely ask if you wish to Debug in VS.
@martinrinehart said:
"Local Settings" is hidden. Neither your Open File dialog nor Windows Explorer will show it...
Yes they will. Open Windows Explorer, any folder.
MENU: Tools > Folder Options
Choose the View tab.
Choose 'Show hidden files and folders' under 'Hidden files and folders'
Other things I do (because I want to see EVERYTHING!)
I choose:
check 'Display the contents of system folders'
check 'Display the full path in the titlebar'
uncheck 'Hide extensions for known filetypes'
uncheck 'Hide protected operating system files'
I can't help it, used PC since DOS first released, and could always see everything... don't like hidden things...
.. but then I might be a control freak.. 
Actually Martin.. that example was quick and dirty.
It CAN be cleaned up. I was thinking it would be better to break out of the iteration when the proper match was found, rather then keep iterating, though how many paths do most people have in their $: anyway?
You'd likely run a method and set a constant (perhaps Integer index into $LOAD_PATH) and then use that reference from then onward. So it should be a one time, startup type thangy...
One thing I do is actually put set ENV['SUpath']
@jim said:
Mac use .exe?
Well.. the point I need to make is.. That Sketchup.find_support_file works best if it has a file to find. In the old days we could not give directories names with .extensions, so we could find dirs with '*.' wildcard. That's not true anymore with 32-bit filesystems.
He can put a string reference into the method call, and set the reference using a platform conditional statement; sketchup.exe for PC, and whatever it is for Mac.
@jim said:
How about using $LOAD_PATH[0]? Is it reliable?
Not if the user has moved their paths around.
However.. hmmm... you could always iterate the $LOAD_PATH array, check each element if it includes 'plugins'
` target=''
$LOAD_PATH.each {|e| target=e.dup if e.downcase.include?('plugins')}
if (not target.empty?) and File.basename(target).downcase=='plugins'
end`
EDIT: put ( ) around not target.empty? just in case...
(1) Only use double-quoted Strings if your:
To find the Sketchup folder(directory) try:
File.dirname(Sketchup.find_support_file('sketchup.exe'))
Plugins folder, is empty when SU is first installed, so can't test for a file, but, you can append 'plugins' to the above, using File.join which uses File::SEPARATOR between arguments:
File.join(File.dirname(Sketchup.find_support_file('sketchup.exe')),'plugins')
Note: Sketchup.find_support_files (plural) on PC returns escaped backslash pathnames, and sometimes returns arrays of pathnames. It's a pain in the butt.
Most people (who run Su on PC,) already have a copy of Win32API.so where their $LOAD_PATH array can find it, so you should only need to:
require 'Win32API'
if it's already loaded, require will skip reloading it.
You can even get more fancy, by first checking if it's loaded, because it defines the class Win32API, and classnames are constants ie:
unless (defined? Win32API)=='constant' %(#F0F0F0)[__]require 'Win32API' end
Also.. I think you must unload those DLLs when your plugin is done with them. Perhaps you might need to use a custom AppObserver implementing the onQuit callback, with your plugin.
By the way.. we have no control over C-implemented Ruby objects, that incorrectly call the wrong C 'warn'/'warning' function, ie: don't respond to the setting of $VERBOSE ( called ruby_verbose in C.)
If you find one, it would need to be reported on RubyForge.net
Likely Sketchup calls a Safari instance (which uses WebKit.) Can you get Safari to use a particular WebKit build (other than what was released with the last Safari version) ??
There is also an extra parameter mac_only_use_nswindow, to the WebDialog.new constructor for the Mac ONLY. (I don't know what it's supposed to be about, not having a Mac, other than nswindow is a base window class in Carbon or Cocoa. [Can't remember which.])
@unknownuser said:
If you check if your plugin has already been loaded with:
file_loaded?(File.basename(__FILE__))
from inside of a rbs file - the FILE value == '(eval)' !
Sounds like File.basename(FILE) is getting set to part of an eval error string.
I wonder if eval error strings are put to the $! message global?