Thursday, February 25, 2010

Extracting music from Mac formatted iPod in Windows XP

I used these tools to extract the music from my iPod (Mac formatted) under windows:

HFSExplorer lets you extract data from an HFS file system hooked up to your PC. In this case my iPod. After loading the filesystem from a device (see file menue), navigate to the folder /iPod_Control/Music and extract it to your PCs filesystem, e.g. your Desktop.

The music shows up as a lot of funny folders and files (F00, F01, ...). This is where Mp3tag comes in: One of the functions of this tool is to read the meta information from your music files and create a directory structure from them, with proper file names, folder names for the albums etc. Sweet!

How to create a 3D wireframe with X3D

All I wanted to do was display some lines in a 3D coordinate system to make sure everything was as it should be. That can't be hard, can it?

Well, it seems it is hard. At least, it's hard to figure out how to do it, because there aren't that many tools that will show you a 3D scene from a file you generate by hand/script.

I quickly found out about the VRML/X3D stuff. It looked ancient. Rotten. Neglected. All sad. A bunch of tutorials made me sure that I didn't want to go that route: None of the tutorials talked about how to display a line in a 3D scene. Instead, it seemed VRML was all about showing shapes: Boxes, cylinders, spheres and stuff like that.

Ugh! Ok. I guess I could just draw really thin boxes and call them lines. But it just gets worse: All shapes are defined in distinces from an origin - so your sphere has a radius. That's it. It is stuck at [0, 0, 0]. But you then translate your shape to where you want it to go. Move it around, rotate it. Etc.

Argh! I had all these nice 3D coordinates for my lines ready. But the docs said I would have to transform them all into this complicated scheme. Which, I am sure makes a lot of sense for 3D modelling. It's just for simple wireframe output that it seems a little bloated.

Well, It's not really that bad: X3D has an element called LineSet that lets you specify... lines! You just write a list of 3D points to the file and off you go!

So, if you are the next person to try creating a simple wireframe with X3D, you might want to have a look at this stub file:

<?xml version="1.0" encoding="UTF-8"?>
<X3D profile="Immersive" >

        <LineSet vertexCount="5">
            <Coordinate point="1 0 0
                               1 1 0
                               0 1 0
                               0 0 0
                               1 0 0"
        <LineSet vertexCount="5">
            <Coordinate point="1 0 1
                               1 1 1
                               0 1 1
                               0 0 1
                               1 0 1"
        <LineSet vertexCount="5">
            <Coordinate point="0 0 1
                               1 0 1
                               1 0 0
                               0 0 0
                               0 0 1"
        <LineSet vertexCount="5">
            <Coordinate point="0 1 1
                               1 1 1
                               1 1 0
                               0 1 0
                               0 1 1"

This will create a simple 1x1x1 cube. You can view this with an X3D browser. I used FreeWRL. It is supposed to be only for OSX and Linux, but they do have a windows binary that sort of works. At least for my purposes it is really enough. The other browsers out there (ones that also act as web browser plugins) seem scammy. They let you download a "test" version. What does that meen? Is this a trial version? Do I have to buy it? Where? How much?

So, here is a screenshot of FreeWRL rendering the X3D file above:
I rotated the cube a bit (this is the nice thing about having a dedicated browser - try writing your own!) to make it more recognizable.

Friday, February 5, 2010

Where are all the posts I promised?

Why oh why have I not delivered on my promise to post neat stuff you can do with RevitPythonShell? Well, what exactly would you want to do with it? I use this tool to scratch an itch - automate a plugin I am writing. I mainly use the Interactive button and type away at the prompt. I also have some canned scripts I like to use, but I'm not sure if posting them here would make a lot of sense: They are very specific to the plugin. But I'll show a little bit, just for the curious among you:

Python 2.5.0 () on cli
Type "help", "copyright", "credits" or "license" for more information.
>>> apps = [a for a in __revit__.LoadedApplications if 'DpvApplication' in str(a)]
>>> dpv = apps[0]
>>> dir(dpv)
['ActiveDocument', 'Calculators', 'GetHistory', 'OnShutdown', 'OnStartup', 'Result', 'TakeSnapshot', '__class__', '__delattr__', '__doc__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__']
>>> dpv.TakeSnapshot()
>>> snapshot = dpv.GetHistory(dpv.ActiveDocument).CurrentSnapshot
>>> for room in snapshot.Rooms:
...    print room.Area, room.Name
163.14989375 Raum 1

Right after the banner, I create a reference to my plugin. This uses the LoadedApplications collection on Autodesk.Revit.Application. As you can see, I then proceed to exercise the plugin, calling its methods (TakeSnapshot, GetHistory, ActiveDocument) etc. You can call any public methods defined in your plugin this way!

But working in the interactive shell for some period has shown some of its weaknesses. I'm busy trying to fix that, but this might still take a while - the last couple of revisions have gone in that direction (but there is no new release yet).

Since this is a tool to make exploring your (C#) plugins easier, it makes sense to customize it a bit. I have configured RevitPythonShell.xml like this:

<?xml version="1.0" encoding="UTF-8"?>
    <!-- a list of paths to add to the engines search path -->
    <SearchPath name="C:\Python25\Lib"/>
    <SearchPath name="C:\RevitPythonShell"/>
    <!-- a list of preconfigured commands -->
    <Command name="dumpdpvfolder" src="C:\RevitPythonShell\Commands\"/>
    <Command name="read model" src="C:\RevitPythonShell\Commands\"/>
    <Command name="Report" src="C:\RevitPythonShell\Commands\"/>
    <Command name="Interactive" src="C:\RevitPythonShell\Commands\"/>
# type in a python script to run here and click "Execute"
# you can access the Autodesk.Revit.Application object with the variable __revit__
# the default script (shown below) opens up an interactive interpreter

import code
code.interact(None, None,
    '__name__' : '__console__',
    '__doc__'  : None,
    '__revit__': __revit__

Notice the Commands section: These are shortcuts to stuff I execute often. Conserved scripts that use the technique explained above to exercise the DesignPerformanceViewer plugin.