sketchucation logo sketchucation
    • Login
    1. Home
    2. Dan Rathbun
    3. Posts
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    ⚠️ Important | Libfredo 15.6b introduces important bugfixes for Fredo's Extensions Update
    Offline
    • Profile
    • Following 0
    • Followers 1
    • Topics 92
    • Posts 4,904
    • Groups 2

    Posts

    Recent Best Controversial
    • [API] ShadowInfo

      [API BUG] class ShadowInfo

      ShadowInfo['SunRise']
      and
      ShadowInfo['SunSet']

      The time returned (hour actually) within the Time class object for BOTH attributes are off by 1 diference to UTC (GMT).

      It appears within the code that the difference between localtime and GMT is subtracted twice instead of once.

      Example: Today, ShadowInfo['SunRise'] tells me that the Sun was supposed to rise a hour ago (at 2:07 AM local,) but I can attest that it's still dark night outside (and there's nothing on the news about the Sun burning out.)
      The "real" local SunRise time for today, here (Melbourne, FL) is 6:07 AM (we are GMT-5 normally, but GMT-4 when DaylightSavingTime is active.)

      Interestingly, the Shadow Settings dialog displays the correct SunRise and SunSet times beneath the "Time" slider

      posted in SketchUp Bug Reporting sketchup
      Dan RathbunD
      Dan Rathbun
    • RE: Download to Sketchup button

      @thomthom said:

      Also, localhost is not required.

      It's not supposed to be, and Windows will strip it out, but John (driven) reported that on the Mac it was required, or the file could not be found.
      So I am endevouring to get to a cross-platform way of doing things.

      Eric is a very new newbie. Don't confuse him (anymore than he already is.) 🤣

      Eric nevermind all this about local links, just put your plugin files in a subfolder of Sketchup/Plugins, as that's where any user would put it also.

      @ThomThom: The path is still INVALID on the PC, either in Ruby, or in a Command Shell. Apparently FireFox is doing some path substring replacement behind the scenes. (I would consider it to be a bug in FireFox for the Windows edition.)
      EDIT: I stand corrected! (Thanx to ThomThom!) I was unaware that Microsoft went and changed the standard foldernames in Vista (and later) Windows versions, to be more "Unix-like". (I and everyone I know, skipped Vista, and will be going from XP up to Win7, sometime later.)

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Download to Sketchup button

      @unknownuser said:

      I am on both the PC and the Mac. I am mostly working on a PC though.

      Well I asked because your path in this statement:
      dlg.set_url "file:///C:/Users/Eric/Documents/SketchThis/TEST2.html"
      is a mixture of a Mac path and a Windows path !

      EDIT: I stand corrected! (Thanx to ThomThom!) I was unaware that Microsoft went and changed the standard foldernames in Vista (and later) Windows versions, to be more "Unix-like". (I and everyone I know, skipped Vista, and will be going from XP up to Win7, sometime later.)

      On Windows, it should look like:
      ENV['HOME']=ENV['USERPROFILE'] if RUBY_PLATFORM.include?('mswin') ENV['USER']=ENV['USERNAME'] if RUBY_PLATFORM.include?('mswin') dlg.set_url("file://localhost/#{ENV['HOME']}/My Documents/SketchThis/TEST2.html")
      On Mac, HOME and USER are already set correctly, so path would be like:
      dlg.set_url("file://localhost#{ENV['HOME']}/Documents/SketchThis/TEST2.html")

      The difference (besides the folder names,) is that PC needs a '/' between localhost and the drive letter; the Mac path already begins with a '/'.

      So to put it together into your code, use this snippet:

      
      if RUBY_PLATFORM.downcase.include?('mswin')
        # on a PC
        ENV['HOME']=ENV['USERPROFILE'] if ENV['HOME'].nil?
        ENV['USER']=ENV['USERNAME'] if ENV['USER'].nil?
        dlg.set_url("file;//localhost/#{ENV['HOME']}/My Documents/SketchThis/TEST2.html")
      elsif RUBY_PLATFORM.downcase.include?('darwin')
        # On Mac ; HOME and USER are already set correctly
        dlg.set_url("file;//localhost#{ENV['HOME']}/Documents/SketchThis/TEST2.html")
      else
        UI.messagebox('Unsupported OS for Sketchup!',MB_OK)
      end
      
      

      Actually, your Plugin should be in a sub-directory of the Sketchup/Plugins folder.
      So this would simplify things, like:

      
      plugpath=Sketchup.find_support_file('plugins')
      if RUBY_PLATFORM.downcase.include?('mswin')
        # on a PC
        dlg.set_url("file;//localhost/#{plugpath]}/SketchTHIS/TEST2.html")
      elsif RUBY_PLATFORM.downcase.include?('darwin')
        # On Mac
        dlg.set_url("file;//localhost#{plugpath]}/SketchTHIS/TEST2.html")
      else
        UI.messagebox('Unsupported OS for Sketchup!',MB_OK)
      end
      
      

      @unknownuser said:

      So did I miss something obvious on my current situation, or will I find the answers in the users guide? 😄

      Your not understanding the very basics of Ruby. Such as if you have a block of code, and I tell you to wrap it in a module called "SketchTHIS", I expect you to do this:

      
      module SketchTHIS
       # the existing code you already have
      end # module
      
      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Download to Sketchup button

      %(#4040FF)[EDITED PREVIOUS POST
      @dlg.set_url
      changed to load a redirect page called "go_gallery.html" [see codeblock]

      @dlg.add_action_callback('download_model')
      was changed because was << (string append) would result in the BASEURL being changed, and we want to use + (string concat) here as Ruby creates a new String object (with +) that modelURL will point to, while the constant BASEURL remains unchanged.]

      code for "go_gallery.html"
      goes in the root dir of website

      <HTML>
      <HEAD>
      <BASE href="http://www.sketchthis.net/"/>
      </HEAD>
      <BODY onload="go();">
      <SCRIPT>
      function go() {
        window.location="Downloads/Gallery/gallery.html"
      }
      </SCRIPT>
      </BODY>
      </HTML>
      
      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: [Plugin] Face Sun

      So he has no knowledge on how to use the info I gave him, to write an Inputbox script for setting time, and I'm too busy with home repairs the rest of the week to help him out.

      I also have no idea if Sketchup would honor the Date class. The guy is obviously interested in ancient dates because he studies ancient architecture. I just don't know if Sketchup could handle going back 6723 years.

      posted in Plugins
      Dan RathbunD
      Dan Rathbun
    • RE: [Plugin] Face Sun

      The astronomer who requested this, replied to the post at GG complaining (about Sketchup, not you ThomThom,) that's it's not easy to change the year in the Shadow info dialog. (Actually he thinks there's no way to change the year; he must have missed those left/right tick buttons.)
      I replied, with this:

      The Sun position would be controlled by ShadowInfo class
      http://code.google.com/apis/sketchup/docs/ourdoc/shadowinfo.html

      #-- Ruby
      new_time = Time.gm(1981,"jan",1,20,15,1) model = Sketchup.active_model shadowinfo = model.shadow_info shadowinfo['ShadowTime']=new_time
      #-- end Ruby

      The Time.gm method parameters are:
      (YEAR,month,day,hour,min,sec,usec)
      The year is required, all others are optional and default to their minimum values.
      Time.gm creates a new time object based on UTC (GMT) time.
      http://www.ruby-doc.org/docs/ProgrammingRuby/html/ref_c_time.html

      Info on extended Date class:
      http://www.ruby-doc.org/docs/ProgrammingRuby/html/lib_standard.html
      Below class Complex, scroll down ...

      posted in Plugins
      Dan RathbunD
      Dan Rathbun
    • RE: Download to Sketchup button

      @unknownuser said:

      ... I checked with the ruby console, and I found an error for "invalid model url"
      Because the test your running is not how the plugin is going to run later. I made a comment in an earlier post (perhaps over at Google Groups,) about how the URL link would stay the same, EXCEPT for the skp filename. [see below]

      But for simplicity of testing on your local machine, set up the following folders starting from your root directory (and yes, Windows doesn't care if a folder is named "www.sketchthis.net"):
      C:/www.sketchthis.net/Downloads/Gallery/catagory
      put test.skp in the catagory folder, along with it's test.png thumbnail
      put the gallery.html (now called TEST2.html) webpage in the Gallery folder
      the plugin ruby script should be in the Sketchup Plugins folder (for testing, later it can go in a subfolder called Plugins/SketchTHIS.)
      Below, when you read the webbased URLs, for testing, replace "http://" with "file://C:/"

      @unknownuser said:

      I had the model in the same directory as the web page, and I assumed that is where it would be looked for.
      No. Ruby always looks in the current Ruby working directory. Ruby does not use the Windows PATH environment variable.
      Webpages are easiest if you use a <BASE> url tag, then they will start a file search from that. So plan on using a <BASE> tag in your Gallery webpage, and a Ruby Constant named BASEURL in your module, so it does not need to be passed back and forth. It CAN be passed once (so you have the option of moving things around on your website, without needing to redistribute the plugin.)

      @unknownuser said:

      ... However, it also occured to me that it might need to go in the same folder as the plugin, so I tried that, and still no dice...
      No the plugin is client-side. The models will be in a Gallery subfolder on your website.

      @unknownuser said:

      ... Here is the link I am using to try to send my model into Sketchup (the one that generates the "invalid model URL error):

      <a href="#" onclick="window.location='skp:download_model@test.skp'">Download Model</a>
      OK the problem is, you will have 3 (three) parts to the URL: BASEURL, Catagory (a Gallery subfolder name,) and skp filename.

      In your HTML <HEAD> section, you'd have this:
      <BASE id='baseURL' href="http://www.sketchthis.net/Downloads/Gallery/"/>
      In your HTML <BODY> tag, you'd have this:
      <BODY id='body' onload="init();">
      After your BODY end tag:
      %(#804000)[</BODY>
      <SCRIPT>]
      %(#8000BF)[function init() {
      window.location='skp:set_baseURL@'+document.getElementById('baseURL').href;
      // any other init tasks
      }]
      %(#804000)[</SCRIPT>
      </HTML>]
      So the links (which will likely be thumbnail images rather than text <A> links,) would look like this:
      <IMG href="catagory/test.png" onclick="window.location='skp:download_model@'+'catagory/test.skp'">Download Model test.skp</a>
      It's also likely you'd want these IMG links to be auto generated by Javascript or PHP tags, from whatever model files are in a given catagory subfolder.

      Then in your Ruby WebDialog SketchTHIS.create_dialog method:
      You'd change the set_url:
      EDIT: Change the entry point for the Gallery, for future freedom of changing website folder heirarchy, without needing to redistribute the plugin. The entry page is a small redirect page, which we'll call "go_gallery.html" that loads whatever the Gallery page is, from whatever it's current location is within the website. (Was hardcoded to a specific URL to "gallery.html")
      @dlg.set_url('http://www.sketchthis.net/go_gallery.html')
      You'd add another callback:
      @dlg.add_action_callback('set_baseURL') { |dlg, args| SketchTHIS::BASEURL=args }
      and change this callback:
      EDIT: + (string concat) was << (string append), in error
      @dlg.add_action_callback('download_model') { |dlg, args| modelURL = SketchTHIS::BASEURL + args Sketchup.active_model.definitions.load_from_url(modelURL) }

      @unknownuser said:

      To Dan... Yes, I did copy the file locations right out of Firefox. Those URL's are going to actually be on my webserver. They do work, why, I am not sure, but they do.
      Well, FireFox has nothing to do with Sketchup WebDialogs (they use MSIE on PC, and Safari on Mac.) Client-side-like pathnames may not be best for server-side folder heirarchy. You already have a "Downloads" folder which can be the Gallery "top" folder, or as in the example above you can have a "Gallery" sub-folder of "Downloads", and in that the gallery.html webpage that gets loaded into the Sketchup WebDialog. Beneath that folder, can be catagorical folders holding skp models and their png thumbnails. The user would click on catagory buttons to see the image lists from the subfolders.

      @unknownuser said:

      Also, about the module situation, after doing some more reading, I think I am starting to understand the benefit of making this into a module. I am not going to go there just yet because I just need to get this thing working, then I can worry about making it "neater".
      As far as putting the plugin in a special directory, I want to do that, I am just trying to tackle one thing at a time.
      It's not about 'neatness' Eric, these things are fundamental, they need to be done at the start, not later, so you don't paint yourself in a corner, or have problems like your having.
      As far as where the client-side plugin goes, you don't really have a choice because of how Sketchup works. It looks in the Plugins heirarchy for plugins. Users will NOT want you installing them anywhere else, most especially not in their User/Documents folder heirarchy.
      So you WILL have a plugin registration script in the Plugins folder, that (if turned on by the user,) loads your plugin from the Plugins/SketchTHIS folder.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: HELP setting up a SU code editor

      @chrisglasier said:

      Can anyone tell me why this happens:

      @unknownuser said:

      Access to restricted URI denied

      I suspect what's happening, is MSIE copies the code into the "Temporary Internet Files" folder, which is usually a Restricted Sites Zone (security-wise.) I've tried (in the past,) to add a specific local folder to my "Trusted Sites Zone" but MSIE refuses.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Download to Sketchup button

      @thomthom said:

      here, the variable dlg is your reference to the webdialog. This is what you must use to refer to the dialog.

      True what Thomas says, but dlg is a local reference so when the method ends, Ruby may dispose of the object.

      Eric, wrap your code in a module block as I showed you, AND rename all occurances of dlg to @dlg as Jim suggested. Then the object will persist, because it's an instance reference of module SketchTHIS.

      The other issue you have is each time the menu or toolbar is used your calling SketchTHIS.create_dialog. You can add a nil test:
      Inside the module:

      def dlg
        (defined? @dlg).nil? ? nil ; @dlg
      end
      

      Then at the bottom of your code, where you define your UI::Command object, change the code between the curly braces from:
      create_dialog
      to:

      if SketchTHIS.dlg.nil?
        SketchTHIS.create_dialog
      else
        SketchTHIS.dlg.show
      end
      

      Then move the menu separator and menu add item statements down below the statements for the toolbar (ie: after your UI::Command is defined,) and change the statement in the menu_add_item curly braces to cmd
      That way both toolbar and menu item use the same code in the UI::Command object.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: HELP setting up a SU code editor

      Firebug page(s) to bookmark:
      http://getfirebug.com/wiki/index.php/Main_Page

      http://getfirebug.com/wiki/index.php/Firebug_Lite

      Forum - Google Groups [EDIT-Added]
      http://groups.google.com/group/firebug

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: HELP setting up a SU code editor

      @Chris: In your webpage for nset, it would easier if you assign an ID to the SCRIPT element(s) that load the external javascript files.

      %(#804000)[<SCRIPT ID='nset_core_js' LINK='..path../core.js'>]

      Then in Firebug Lite, try inspecting by ID. Enter the ID name in the inspect control box. If that doesn't work, try entering:
      document.getElementById('nset_core_js')

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: HELP setting up a SU code editor

      @Chris: Do you have nsetWebDialog.set_full_security= true or false ??
      (It defaults to false if you don't explicitly set it.)

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Download to Sketchup button

      @unknownuser said:

      As far as wrapping stuff up in modules, I think I understand the concept of that, but at this point, I think its way over my head...

      Ok.. homework assignment time. Your homework is to go and read this tutorial:
      Ruby User's Guide

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Download to Sketchup button

      Eric, on you on a PC or a Mac?

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Download to Sketchup button

      @unknownuser said:

      I am having an issue with the Ruby code I think... I haven't seen any Ruby code with an "@" symbol in front of it, so I tried it with, and without, and I still not getting any results.

      Well, Jim doesn't realize how much your a spankin'-newbie at Ruby.

      In Jim's example the '@dialog' refers to YOUR WebDialog instance reference name, whatever it is you chose to name it in the constructor statement (example):
      @dialog = UI::WebDialog.new( ..*parameters*.. )

      IF you named it "SketchTHISdlg", then your constructor statement should look something like ( with proper parameters, of course.):
      SketchTHISdlg = UI::WebDialog.new( ..*parameters*.. )
      then the block to create the callback method, would be (like):
      # Then in the SketchTHIS Ruby plug-in: SketchTHISdlg.add_action_callback("download_model") { |dlg, args| Sketchup.active_model.definitions.load_from_url(args) }

      Both Jim and I are hoping you have wrapped your plugin within a module, and this is why Jim used an instance type reference (' @dialog'); my example uses a module constant (' SketchTHISdlg'); both can work, or you can use a module/class reference that begins with @@, as in ' @@mydialogname'.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: HELP setting up a SU code editor

      That IS interesting John.

      But it's only for coding and testing WebDialogs (not Ruby.)

      By running in Alex's Code Editor, only Alex's Code Editor is being debugged.

      But it may have promise.

      @ThomThom: You may find this interesting, Firebug extension for jQuery development: http://firequery.binaryage.com/

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Open URL on local disk

      @martinrinehart said:

      I've set single click to open. An HTM opens in Chrome.

      Hey Martin, what's the fullpath to the Chrome executable on your PC ??

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Untrapped Error

      @martinrinehart said:

      
      > 64  rescue => e
      > 65    rslt += e.to_s().chomp()
      > 66  end
      > 
      

      Your local reference e receives a pointer to an Exception object from the rescue clause, not a String object.

      You should use the instance method Exception.message to get the exception's string, like this:
      65 rslt << e.message.chomp()

      (As a side-note on Optimization, generally speaking, + and += String concatenation, require Ruby to create at least one extra String object than String append <<. Ruby internally converts a+=b to a=a+b, OR a+='literal' to a=a+'literal', so using += doesn't gain you anything over <<, and may be twice as slow or more, in a loop.)

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Open URL on local disk

      @martinrinehart said:

      Now if only I can figure out how to specify both program and file ...

      Something like this (needs work for Mac, and can be wrapped in a method.)

      filename='somefile.html'
      path='C;/dir/dir'
      filepath=File.join(path,filename)
      
      if RUBY_PLATFORM.include?('mswin')
      #
      if Kernel.test(?d,"#{ENV['SystemRoot']}/ie9")
        browser="#{ENV['SystemRoot']}/ie9/iexplore.exe")
      elsif Kernel.test(?d,"#{ENV['SystemRoot']}/ie8")
        browser="#{ENV['SystemRoot']}/ie8/iexplore.exe")
      elsif Kernel.test(?d,"#{ENV['SystemRoot']}/ie7")
        browser="#{ENV['SystemRoot']}/ie7/iexplore.exe")
      elsif Kernel.test(?d,"#{ENV['SystemRoot']}/ie6")
        browser="#{ENV['SystemRoot']}/ie6/iexplore.exe")
      elsif Kernel.test(?d,"#{ENV['SystemRoot']}/ie5")
        browser="#{ENV['SystemRoot']}/ie5/iexplore.exe")
      else
        raise(Errno;;ENOENT,filepath)
      end
      #
      else # Mac
        # browser = ???
      end
      
      # open specific file in broswer
      f = IO.popen("#{browser} #{filepath}")
      

      EDIT: It looks like the PC browser location (for all versions) can be simplified to:
      browser = "#{ENV['ProgramFiles']}"<<'/Internet Explorer/iexplore.exe'
      It may be that the hidden system folder "Windows/ieX" is a install folder.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Open URL on local disk

      @martinrinehart said:

      Folder Options has disabled what I need:
      I gave the user admin privileges, but that didn't help.

      You can try going to Control Panel and right-click "Folder Options" and choose "Run As...", then pick an Administrative account to run this one applet as. (This is called running with "Elevated Privileges" in 'MS MicroSpeak'; and is more secure than having a user account always running with Administrative rights. Those slimeballs who write Trojans love people who always run with Administrative rights, especially when when connected to the Internet.)

      Also there is a wizard for controlling browser setings called "Set Program Access and Defaults", if you can find it on the Start Menu, you can also right-click it's icon and "Run As..."
      (It's actually a sub-routine of "Add/Remove Programs" and appears as the bottom button in it's left toolcolumn.) The program to run, if you have to actually right-click the file, in order to "Run As...", is:
      %SystemRoot%\system32\appwiz.cpl
      The shortcut command (in case you can't find it in your menus, and want to make a shourtcut,) is:
      %SystemRoot%\system32\control.exe appwiz.cpl,,3

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • 1
    • 2
    • 229
    • 230
    • 231
    • 232
    • 233
    • 245
    • 246
    • 231 / 246