Use Category.ByName in python

Hi. Quick question:
How do i implement Category.ByName in a python script?
And is there a place where i can figure this out myself for the future?

I’m not sure if this is the one you’re after:

Is this what you want?

The call in the Python script is simply:


Thanks for the reply!

That last line is exactly what i want!
Do i simply import it in the following manner?

import Revit

I hope you have the time to answer yet another question that is more or less related. I get an error when trying to implement referencepoint.bypointvectordistance.

I want to go from a list of initial points, along two vectors, so i end up with a set of new points
i have the following code:

import clr
from Autodesk.DesignScript.Geometry import *

import Revit

x = IN

initPoints = [(x[0][0][i].StartPoint) for i in range(len(x[0][0]))]

for i in range(len(b)):

OUT = newPoint

This should be changed to “x = IN[0]”

You are not defining “b” anywhere this causes your error. There might be other issues I have not found by a glance. :slight_smile:

To the last matter you would “initialize” like so:

import clr
import Revit
OUT = Revit.Elements.Category.ByName(IN[0])

Lastly be careful about using the subscripts such as x[0][0][0] to go through your lists as this make them very prone to errors if your level of lists change…

If you want to use core Dynamo nodes in Python you need to import them.

from DSCore import *
1 Like

Thanks again for the reply! I think my problem is that i don’t understand how the referencepoint.bypointvectordistance works. I have added a screenshot of how i think it works, hope you will spot the mistake, the error message is: “Element cannot be created in current context”

Hi @magnus

Your original question was already answered. For your second query you should mark one of the above answer as solution and start a new thread

However the error says you can’t create Reference point in Project environment, you should use this node in family environment. Does that makes Sense?

1 Like

Why are you using python code for almost all your operations? Why not stay in OOTB nodes?

Curious if there is a reason for this?

1 Like

I guess there is a couple of reasons, though i don’t know if its justified:
Most of what i do must be scalable, a lot of loops and list operations. I also don’t know any designscript yet, while I know some python. Hopefully i will learn more as i go.

An additional bonus with using python is that I use it a lot studying mechanical engineering and I need all the excercise I can get :wink:

takker så meget for all hjelpen

Det var så lidt :wink:

I understand your reasons though you might find that this forum is more keen on resolving issues, that is not directly in need of “loops”, with nodes as this is the most “dynamo-y” way.

Even using nodes you will be able to make large scale-able solutions you just need to understand lacing and list-levels. This will man times make better solutions than you coding everything up in small individual python nodes :slight_smile:

Even then you do not need any DesignScript knowledge, most can be solved using simple nodes with correct lacing and list-levels. And then finally if any “for-, if- or while-loops” are needed you can start using Python. Much of the time Dynamo is actually better at handling lists than Python will be, unless of course you’re using certain algorithm to traverse your data in Python though I doubt with the limitations of IronPython though :rofl:

Though I as a student of Architectural Engineering understand your reasons for wanting to learn Python coding on the fly :wink:

1 Like