Writing your own python scripts- what is your process

Hi Everyone,

When you want to write your own python script, say for example I want to write one that generates filled region colour types, what process do you use?

Do you use the API documentation or find other scripts to give you a basis point? Im very interested to know your process.

Sam

Hey just my humble notesas I’m on the same journey and apolIogies I don’t have a polished solution. I recently jumped into the Rhino.Inside Revit this morning. Was hoping to do some curtian wall magic, but I saw that section in the guides is still on “under development”.

I do a little in both C# and python and the I’m looking at the API documentation online.
It requires a little “conversion” when reading the c# documentation and trying to write a python script.
For instance in c#

var point = pointFromRevit.ToPoint3d();

would be in python:

point = Convert.Geometry.GeometryDecoder.ToPoint3d(point_from_revit)

See attached as an example where i project the grid lines in revit to 2d lines in rhino.
grid lines 2d.gh (4.5 KB)

In the API docs you can find a FilledRegion.Create:
https://apidocs.co/apps/revit/2020/ca304caa-7f95-4638-67d9-a138be609b9f.htm

public static FilledRegion Create(
	Document document,
	ElementId typeId,
	ElementId viewId,
	IList<CurveLoop> boundaries
)

And if you wanted to make a FillRegionType then I cannot find any constructor for it. So you might look into the .duplicate() on an existing FillRegionType and then change it’s properties (variables).
Take a look at them here: ApiDocs.co

For your generated filled region types you can look into the filled region and type parameters, perhaps using the Revit Lookup plugin (GitHub - jeremytammik/RevitLookup: Interactive Revit BIM database exploration tool to view and navigate element properties and relationships.).
A peak into the filled regions would look like this:

…And in case you missed:
Examples python:
https://www.rhino3d.com/inside/revit/beta/guides/rir-ghpython

Examples csharp:
https://www.rhino3d.com/inside/revit/beta/guides/rir-csharp

Revit API:
https://apidocs.co/apps/revit/2020/850ae173-379b-bfd6-7295-3950ccc229ca.htm

Maybe I confused more than it helped, in that case sorry! :slight_smile:

2 Likes

Hi @sonderskovmathias that is excellent, at the moment I am struggling more with the revit API and how I convert the C# into python? do you have a good method to do that and then also how do I know what the inputs and outputs should be?