Posted by: Peter Quirk | January 16, 2009

Building Sketchup plug-ins the right way for Vista

When I made some small modifications to the original Ogre Mesh Exporter plug-in developed by Fabrizio Nunnari from an earlier work by Kojack, I never anticipated how much more work would be involved in doing it right, and how few Sketchup plug-ins are designed to work with Vista’s improved security model. I was running on Windows XP when I published the plug-in, and like most users was content to edit the configuration parameters within the plugins folder, which resides within the Program Files folder. Jules Vos commented that it was a pain to configure the plug-in under Vista due to the tightened security. Recently I upgraded my Windows XP system to Vista (32-bit) and then Vista (64-bit), so I got a chance to eat my own dog food!

As in Windows XP, the Program Files folder in Windows Vista requires elevated privileges to install software. But Vista goes further in that it virtualizes per-user files in another folder. If you or your software application attempts to modify settings in a plug-in, the modified file will be written to C:\Users\{user}\AppData\Local\VirtualStore\Program Files (x86)\Google\Google Sketchup 7\Plugins. The idea is to protect each user from the other by ensuring that they see either the original version of the file, or their personal version if they have modified it. Of course, to modify a file in the Plugins directory, you have to invoke Notepad or another editor with the “Run As Administrator” option before you open the file.

The first thing that needs to change is where we store the plug-ins if they need to be modified by the user. We should store them in the user’s data area, either in AppdataRoaming or in the Documents hierarchy and call them from a stub script in the Plugins folder. This approach allows the user to customize the script without elevated privileges.

The second things that needs attention is the use of installer scripts for plug-ins. It has been many years since I built an installer script and a lot has changed such as the introduction of separate folders for 64-bit and 32-bit programs, new file locations in Vista, etc. I don’t have access to the full Visual Studio development suite anymore either. So I looked at free and open source installers. After examining the NullSoft installer and Microsoft’s Wix, I opted for Wix since it didn’t require me to learn another scripting language and I didn’t have cross-platform requirements that NullSoft’s installer addresses.

After a lot of work learning Wix and dealing with the lack of accurate documentation on system-related APIs in the Sketchup Ruby documentation, I have created a workable installer for the Ogre Mesh Exporter plug-in discussed previously. The installer is presently optimized for Vista (32-bit and 64-bit). A more complete implementation with support for XP is coming soon. (I’m waiting for an answer on how to determine from a Sketchup plug-in which OS platform we’re running on.)

The installer places the three Ruby scripts (the export script, the configuration file and backfaces.rb) into the standard Plugins directory. On first use of the exporter, if it can’t find the C:\Users\{user}\Documents\Sketchup Plugins directory, it creates one, copies the  config file to it, then loads it. You may happily edit the config file in your Sketchup Plugins folder without needing any elevated privileges. As with the initial release, the code assumes the existence of a “My Models” folder in Documents. Each exported model will be stored in a separated directory in My Models. Unique ids are no longer attached to the materials, but you can set $g_ogre_append_unique_prefix to true of you want this behavior.

You can fetch the new installer from here. Just click on the link to run .msi file and install the add-in.

Notes:

1. Google Sketchup 7 must be installed before the plugin is installed
2. DocumentsMy Models directory must exist before running the add-in from the Sketchup Tools menu.
3. If you want to store the models somewhere other than My Models, edit the ogre_export_config.rb file after running the exporter once.
3. You can uninstall the plugin from the Control Panel.

Advertisements

Responses

  1. Doesnt work in latest Sketchup7 in Windows 7 ;) Some sort of error with the paths it tries to export to.^^ Just thought I should let you know.

  2. Thanks for the heads-up. I’ve been putting off installing Windows 7, but I guess it’s time to try it.

  3. I would appreciate it if you let me know when you sort the issue out or update the wiki entry that I made on http://www.ogre3d.org/wiki/index.php/OGRE_Exporters

    keep up the good work

    Jubei^^

  4. Peter; Thanks for all the hard work.

    I have had a hell of a time for the past day.

    1. I am using XP not Vista, so I needed to change a few things in the cfg file you created (instructions and two versions of the config file would be nice)

    2. It was not clear were to find the rexexporttools_0.3.zip from your latest tutorial post (this one) or the comments you left in the previous post since one was truncated when you were about to say were the zip could be found.

    Only after going back to realXtend’s wiki and then http://www.realxtend.org/page.php?pg=downloads as well. I discovered the full instructions but you had branched away and the suggested folder names and config entries are different.

    Well all said and done. I installed everything and created folders.

    but DAMN

    I could not get it to work at all with Sketchup 7.0.10247.0 I selected Export Selection to Ogre Mesh in Tools, Just nothing. Dead…..

    Pulled my hair out after checking everything over and over.

    Then I copied the files to Plugins for Skecthup 6.0.312.0 Pro….

    MAGIC it worked fine with Skecthup 6 Pro.

    I have no idea why the ruby scripts fail without any error in the newest Sketchup 7 (free edition) under XP but you and your readers may find the same issues. I hope this helps a few following here.

    I would like to upgrade Sketchup Pro 7 soon myself but will hold off now. since I will wait for Windows 7 service pack 1or2 and skip Vista were everything appears to work for you.

    Thanks again.
    JR

  5. I am having the same problem as JeanRicard Broek.

    I’m on XP SP2 and also using 7.0.10247.0, the latest version available.

    I’ve changed things in the config file, made sure all the required folders exist, etc.

    Nothing seems to work. When I click on the menu item, nothing happens. There are no errors, no logs, certainly no exported meshes, nothing.

    Kojack’s original script (the other one listed on the Ogre wiki) is working.

    I also tried the latest version of SketchUp 7 Pro, but that didn’t work either.

    I could just use Kojack’s script but this appears to be a new and improved version of that, so I would like to use your script if possible. I don’t really want to have to downgrade to SketchUp 6, either.

    If you could investigate and possibly find a solution that would be great!

    Thanks.

  6. I found the solution to the XP problem after diggin around in the actual exporting script for a bit. JeanRichard, I have no idea why the script would work in SketchUp 6, because based on what I found, it shouldn’t.

    Anyway, the problem is specific to XP users or before and is a path issue in ogre_export_1_2_1_for_rex.rb.

    Go to line 510 in ogre_export_1_2_1_for_rex.rb:
    targetfolderpath = ENV[‘USERPROFILE’] + “\\Documents\\” + targetfolder

    The “Documents” folder in Windows Vista is called “My Documents” in Windows XP. Change “Documents” to “My Documents” and you’re half way there.

    The same issue occurs at line 529:
    load ENV[‘USERPROFILE’]+”\\Documents\\Sketchup Plugins\\ogre_export_config.rb”

    Again change “Documents” to “My Documents” and you’re set. Restart SketchUp (this is important as SketchUp loads the script when it starts) and you should be good to go.

    If it’s still not working at this point then I don’t know what the problem is. Check ogre_export_config.rb and make sure you have all the paths and settings correct.

    Hopefully this will help a lot of people out and Peter, hopefully you can either revise the files or edit the post to inform people about what they need to change, because right now the script is pretty much broken out of the box for ALL XP users.

    Thanks for the script. :)


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: