Calling FamilyInstance.ByPoint from Python

I get this error when trying to create familyinstance by point in python

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference('DSCoreNodes')
import DSCore
from DSCore import *

dataEnteringNode = IN

point = IN[0]

familytype = IN[1]

try:

x = DSCore.FamilyInstance.ByPoint(familytype,point);

except Exception as e:

s = str(e)

OUT = s

You’re not passing any familytype or point to your script? :slight_smile:

1 Like

For a moment there i doubted myself :sweat_smile:

Capture

I would be creating 100s of families for a check, so i want to do it in code as a for loop and create/del one instance it per loop.

Hah! I justed noticed it on your screenshot :D.
I’m not familiar with the DSCore method, so I cant help you further :slight_smile:

1 Like

Hi,

You don’t have to import DSCore but rather RevitNodes.

import clr
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)

point = IN[0]
familytype = IN[1]

try:
	x = Revit.Elements.FamilyInstance.ByPoint(familytype,point)

except Exception as e:
	s = str(e)

OUT = x

4 Likes

Hi Alban,

Why don’t we need a transaction or to convert the point to Revit type? :smiley:

Cheers,

Mark

This is because the script calls the Dynamo node in python and doesn’t use the Revit API.
There is no need to unwrap the FamilyType, convert the dynamo point and use transactions.

The Revit API method is doc.Create.NewFamilyInstance(XYZ,FamilySymbol,StructuralType)

3 Likes

Hi Alban,

When trying to run the python script, this is the warning that shows up. Do you know why it is saying that x is not defined?

Thanks,Capture

Hi,

Check your code, you may have an indentation problem.
The try and except lines are not essential and can be removed.

ByPoint

What do you mean by remove? Like all of lines 9 and 12?

When I place just one point, it works great, but when I have multiple points, it won’t run.

@callbowen: it’s probaly because your IN[0] becomes a list of points instead of just one point :).
To correct this, you need to loop through your points with a for loop:

“for p in points”:
x = Revit.Elements.FamilyInstance.ByPoint(familytype,p)

Edit:
You might find this thread useful regarding passing a list or not a list to your python script. :slight_smile:

2 Likes