Sunday, February 16, 2014

[Revit API] Binding a project parameter to all categories

In a recent project I had the need to create a new project parameter, and then set the value of it on certain elements. This post has great information on creating project parameters, however that post along with much of the Autodesk documentation add certain parameters to the CategorySet for the InstanceBinding method, what I wanted to do was add all of them. Unfortunately adding all categories in document.Settings.Categories throws an error as not all categories can have parameters bound.

There is a simple solution to this, only add categories to the CategorySet if they have their AllowsBoundParameters property set to true. It’s an obvious solution once you know this flag is available.

CategorySet categories = app.Application.Create.NewCategorySet();

foreach (Category category in doc.Settings.Categories)
{
    if (category.AllowsBoundParameters)
    {
        categories.Insert(category);
    }
}

Saturday, January 4, 2014

Setting up node-postgres with a new PostgreSQL installation on OSX

I was getting a PostgreSQL installation setup with NodeJS today on my computer and ran into some difficulty that I thought I'd write a post about in case someone else comes across the issue.

I started off by downloading the PostgreSQL installer from the PostgreSQL website (I had also tried Postgres.app) and running through the installer with mostly default settings.

Once that was done I went to install the node-postgres module in my node project via 'npm install pg', this threw the following error:

gyp: Call to 'pg_config --libdir' returned exit status 127. while trying to load binding.gyp

After some searching I found this Github issue which pointed me to the solution. The problem is that the installer did not add the PostgreSQL binary folder to my PATH. To get around this, I updated my ~/.bash_profile (vim ~/.bash_profile is the easiest way to do this) to add the following line:

export PATH=/Library/PostgreSQL/9.3/bin:$PATH

(be sure to use the version of PostgreSQL you installed. Also, if you already have that line, you should just add '/Library/PostgreSQL/9.3/bin:' after PATH=)

Save that file, restart terminal and you should be able to type pg_config and get some output on your screen. Once you've done that, reinstall the node-postgres module and you should not see the error anymore.

Hope this helps!