How to move a point along a vector in python?

image
I tried this designscript in python.

Its giving me the following error.
Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 81, in
AttributeError: ‘Autodesk’ object has no attribute ‘Geometry’

following is the code.

Enable Python support and load DesignScript library

import clr
import sys
clr.AddReference(‘RevitAPI’)
from Autodesk.Revit.DB import *

clr.AddReference(“RevitNodes”)
import Revit
clr.ImportExtensions(Revit.Elements)
clr.AddReference(‘DSCoreNodes’)
from DSCore.List import Flatten
from Autodesk.Revit.DB.Electrical import*

clr.AddReference(‘ProtoGeometry’)

from Autodesk.DesignScript.Geometry import *

import sys
pyt_path = r’C:\Program Files (x86)\IronPython 2.7\Lib’
sys.path.append(pyt_path)
import System

clr.AddReference(“RevitServices”)
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

clr.AddReference(“RevitAPI”)
import Autodesk
from Autodesk.Revit.DB import *

clr.AddReference(“RevitNodes”)
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

import collections

def ToInternalUnits(number, unittype = None):
if unittype == None:
unittype = UnitType.UT_Length
currentType = doc.GetUnits().GetFormatOptions(unittype).DisplayUnits
return UnitUtils.ConvertToInternalUnits(float(number), currentType)

UIunit = Document.GetUnits(doc).GetFormatOptions(UnitType.UT_Length).DisplayUnits

The inputs to this node will be stored as a list in the IN variables.

Door = UnwrapElement(IN[0])
Height_Offset = IN[1]
Offset_From_Wall = IN[2]

Place your code below this line

Location_Point = Door.Location.Point
Door_TypeId = Door.GetTypeId()
Door_Type = doc.GetElement(Door_TypeId)

Para_Width = Door_Type.LookupParameter(“Width”)
Para_WidthValue = Para_Width.AsDouble()
Para_WidthValueInmm = Para_WidthValue*304.8
Width_Half = Para_WidthValueInmm/2

HostWall = Door.Host
Location_Curve = HostWall.Location.Curve
Vector_ = Location_Curve.Direction.ToVector()

NewPoint = XYZ(Location_Point.X,Location_Point.Y,Location_Point.Z+ (Height_Offset/304.8))

pt_Dyn = Autodesk.DesignScript.Geometry.Point.ByCoordinates(UnitUtils.ConvertFromInternalUnits(NewPoint.X,UIunit),UnitUtils.ConvertFromInternalUnits(NewPoint.Y,UIunit),UnitUtils.ConvertFromInternalUnits(NewPoint.Z,UIunit))

Total_Offset = Width_Half + Offset_From_Wall

Translated_geometry = Autodesk.Geometry.Translate(NewPoint, Vector_, Total_Offset)

Assign your output to the OUT variable.

OUT = Translated_geometry

so get your code more handsome with </>

import clr
import sys
clr.AddReference(‘RevitAPI’)
from Autodesk.Revit.DB import *

clr.AddReference(“RevitNodes”)
import Revit
clr.ImportExtensions(Revit.Elements)
clr.AddReference(‘DSCoreNodes’)
from DSCore.List import Flatten
from Autodesk.Revit.DB.Electrical import*

clr.AddReference(‘ProtoGeometry’)

from Autodesk.DesignScript.Geometry import *

import sys
pyt_path = r’C:\Program Files (x86)\IronPython 2.7\Lib’
sys.path.append(pyt_path)
import System

clr.AddReference(“RevitServices”)
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

clr.AddReference(“RevitAPI”)
import Autodesk
from Autodesk.Revit.DB import *

clr.AddReference(“RevitNodes”)
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

import collections

def ToInternalUnits(number, unittype = None):
if unittype == None:
unittype = UnitType.UT_Length
currentType = doc.GetUnits().GetFormatOptions(unittype).DisplayUnits
return UnitUtils.ConvertToInternalUnits(float(number), currentType)

UIunit = Document.GetUnits(doc).GetFormatOptions(UnitType.UT_Length).DisplayUnits
#The inputs to this node will be stored as a list in the IN variables.

Door = UnwrapElement(IN[0])
Height_Offset = IN[1]
Offset_From_Wall = IN[2]
#Place your code below this line

Location_Point = Door.Location.Point
Door_TypeId = Door.GetTypeId()
Door_Type = doc.GetElement(Door_TypeId)

Para_Width = Door_Type.LookupParameter(“Width”)
Para_WidthValue = Para_Width.AsDouble()
Para_WidthValueInmm = Para_WidthValue*304.8
Width_Half = Para_WidthValueInmm/2

HostWall = Door.Host
Location_Curve = HostWall.Location.Curve
Vector_ = Location_Curve.Direction.ToVector()

NewPoint = XYZ(Location_Point.X,Location_Point.Y,Location_Point.Z+ (Height_Offset/304.8))

pt_Dyn = Autodesk.DesignScript.Geometry.Point.ByCoordinates(UnitUtils.ConvertFromInternalUnits(NewPoint.X,UIunit),UnitUtils.ConvertFromInternalUnits(NewPoint.Y,UIunit),UnitUtils.ConvertFromInternalUnits(NewPoint.Z,UIunit))

Total_Offset = Width_Half + Offset_From_Wall

Translated_geometry = Autodesk.Geometry.Translate(NewPoint, Vector_, Total_Offset)
#Assign your output to the OUT variable.

OUT = Translated_geometry
2 Likes

I presume this problem is this line?

Translated_geometry = Autodesk.Geometry.Translate(NewPoint, Vector_, Total_Offset)

Should it perhaps be

Translated_geometry = Autodesk.DesignScript.Geometry.Translate(NewPoint, Vector_, Total_Offset)

?

Hope that helps…

Mark

1 Like

Python is an object-oriented programming language, if the object inherits from the desired method you do not need to call static methods (or Unbound Method).
Here, a Point is a Geometry object

2 Likes

Correct me if I’m wrong… :slight_smile:

But given that the OP is calling quite a few libraries, they might need to specify which library the method is coming from? Perhaps this would be a neat way to go…

from Autodesk.DesignScript import Geometry as geom


Translated_geometry = geom.Translate(NewPoint, Vector_, Total_Offset)

Hopefully that is interesting!

Mark

1 Like

Not necessary, Translate is not a static method, it applies to the instance (this or self).

The method have only 2 parameters
newGeomObject = oldGeomObject.Translate(Vector_, Total_Offset)

Inheritance Overview
image

but
Translated_geometry = Autodesk.DesignScript.Geometry.Translate(NewPoint, Vector_, Total_Offset)
is not wrong :grinning:

in both cases, if the point is not an Autodesk.DesignScript.Geometry object there will be an error

3 Likes

Thanks :slight_smile:

1 Like