• Login
sketchucation logo sketchucation
  • Login
ℹ️ GoFundMe | Our friend Gus Robatto needs some help in a challenging time Learn More

Make SketchUp API to recognize System PATH

Scheduled Pinned Locked Moved Developers' Forum
3 Posts 2 Posters 446 Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    gmolina1
    last edited by 12 May 2015, 20:45

    Hello everyone,

    I have been developing a SketchUp extension for a while, but I am not really a programmer... please be patient, haha. I am trying to call Radiance, a lighting analysis toolbox... its calculations take a while, and the programs are meant to be run in the terminal. My idea is to create some scripts for enabling the non-expert users to perform simulations.

    As a start, I managed make systems calls using "popen3", which allow me to diference the stout from the stderr, etc. That is cool.

    The problem now is that the programs in my PATH are not recognized. I tried to write the whole directory, but some of the programs call, internally, more programs... so I get the "program not found" (does not say exactly that) error.

    Is there any way of telling SketchUp too register some directories as part of the PATH? As a second option, I thought on creating a JAVA app that is opened from SketchUp to manage the simulations? Is this possible/advisable? Whould the same happen here? A JAVA app would actually give me the advantage of porting it to Linux, where calculations take shorter times (bigger computers, haha).

    Another fact to consider is that I do not want SketchUp to be paralized while calculating.

    There are a few things to consider in the blender... if you could help me with the mess in my head, it would be awesome.

    Best,

    1 Reply Last reply Reply Quote 0
    • D Offline
      Dan Rathbun
      last edited by 13 May 2015, 14:15

      !

      (1) Variables like the %(#8000FF)[PATH] are part of the system Environment. From a system shell you access them using % delimiters, like so: %(#8000FF)[%PATH%]. You can list them all using the %(#8000FF)[set] command.


      (2) Each application than runs, gets a COPY of the Environment (variables) so that if other programs change them, then it will not effect all programs.

      So.. this leads to your question ...

      @gmolina1 said:

      Is there any way of telling SketchUp too register some directories as part of the PATH?

      Inside SketchUp, you can access, change and add variables of SketchUp's copy of the environment, via the Hash-like construct ENV.

      To list it, load Pretty Print:
      require "pp"

      Then "pp" the ENV hash in the Console:
      pp ENV

      But be aware that inspect and pp both escape back-slash characters in their output. (The Strings do not really have doubled back-slashes.)

      So you can convert these to Ruby/Unix-like path strings:
      path = ENV["PATH"].gsub(/\\\\|\\/,'/')

      You can add a helper method in your plugin module, like:

      def rubyize_path(p)
        p.gsub(/\\\\|\\/,'/')
      end
      
      

      SO...
      progpath = rubyize_path(ENV["ProgramFiles"]) old_path = ENV["PATH"] ENV["PATH"]= "#{progpath}/some/extra/new/path;" << old_path

      When your done, reset ENV["PATH"], thus:
      ENV["PATH"]= old_path

      But changing the SketchUp ENV["PATH"] variable, only affects things that run from SketchUp's process. Shell scripts may not be able to see it. SO TEST, & test again.


      (3) Temporarily changing the working directory.

      
      work_dir = rubyize_path(ENV["ProgramFiles"]) << "/Radiance"
      
      Dir;;chdir(work_dir) {
      
        # Things to do in the work dir
      
      }
      # The previous directory (whatever it is...)
      #   is automatically restored outside the block !
      
      

      (4) Executing shell commands.

      The %x construct can execute shell commands with cmd.exe on Windows.
      You may use ANY delimiter character (or matched bracket or brace characters.)
      ver_text = %x{ver} pp ver_txt

      I chose curly braces, but you could use dollar signs, or square brackets, whatever.


      That should give some food for thought.

      ~

      I'm not here much anymore.

      1 Reply Last reply Reply Quote 0
      • G Offline
        gmolina1
        last edited by 13 May 2015, 15:24

        Thanks, Dan! Your answer does give A LOT of food for thought. I will try someof these and let you know.

        Regards

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        1 / 1
        • First post
          1/3
          Last post
        Buy SketchPlus
        Buy SUbD
        Buy WrapR
        Buy eBook
        Buy Modelur
        Buy Vertex Tools
        Buy SketchCuisine
        Buy FormFonts

        Advertisement