Geometry conversion in PyRevit?

Hi All,
I am selecting one pipe with one open end and running the below code to get location of connector which is not connected . I am getting the out as shown below

(-10.047988955, -32.450827899, 9.022309711)

Location is not shown as an xyz point object. Do I need to do any geometry conversion in pyrevit (Like UnwrapElement or ToPoint()) to get the ouput as revit XYZ point object?

ElementIds = uidoc.Selection.GetElementIds()
for el in ElementIds:
    Selected_Pipe = doc.GetElement(el)
conn = Selected_Pipe.ConnectorManager.Connectors
first_Point = None
for c in conn:
    if not c.IsConnected:
        first_Point = c.Origin


Hi @JobinSunny,

first_Point = c.Origin

to

first_Point = DB.Point(c.Origin)

you may need to import DB like so

from pyRevit import DB

and if you need to return X, Y or Z

first_Point.X
first_Point.Y
first_Point.Z

I am getting an error which says cannot create instances of point because it has no public constructors.
here is my code.

from pyrevit import revit # revit library can be used to get the active revit document
from pyrevit import forms,script,EXEC_PARAMS,UI #forms contains lot of user interface options ,scrpt is used to stop running the script ,EXEC_PARAMS for checking click modes
from Autodesk.Revit.UI.Selection import *
import clr
import sys
import math
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager 
from RevitServices.Transactions import TransactionManager 

clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
from pyrevit.revit.db.query import get_location


import collections
clr.AddReference('DSCoreNodes')
from DSCore.List import Flatten

clr.AddReference('RevitAPI')


from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Electrical import*
from Autodesk.Revit.DB.Mechanical import*
from Autodesk.Revit.DB.Architecture import *
from Autodesk.Revit.DB.Analysis import *
from Autodesk.Revit.DB.Structure import *
from Autodesk.Revit.DB import Transaction

from collections import defaultdict
from pyrevit import DB

uiapp = __revit__
uidoc = uiapp.ActiveUIDocument
doc = uiapp.ActiveUIDocument.Document
TestJ = []
ElementIds = uidoc.Selection.GetElementIds()

for el in ElementIds:
    Selected_Pipe = doc.GetElement(el)

#Getting the first point
conn = Selected_Pipe.ConnectorManager.Connectors
first_Point = None
for c in conn:
    if not c.IsConnected:
        first_Point = DB.Point(c.Origin)
 




print(first_Point)

My bad, I was too quick on the keys:

DB.XYZ(c.Origin)

1 Like

@JobinSunny
Unless I’m missing something your original code is fine. What you are getting out is an XYZ object.

When you print out an object it will convert the object to a string using ToString() method which returns a string formatted like what you described.

Here a snippet from RevitPythonShell to demonstrate.

>>> a = XYZ(-10.047988955, -32.450827899, 9.022309711)
>>> a
<Autodesk.Revit.DB.XYZ object at 0x0000000000000032 [(-10.047988955, -32.450827899, 9.022309711)]>
>>> a.ToString()
'(-10.047988955, -32.450827899, 9.022309711)'
>>> print(a)
(-10.047988955, -32.450827899, 9.022309711)
>>> 
2 Likes

Correct. We need to provide 3 arguments(X,Y,Z).

Yes.You are correct.