First attempt Editing a Python script

Hi All,

The below Python script first get’s the AssemblyOrigin of an AssemblyInstance.
GetTransform
Next step is the rotation of this AssemblyOrigin.
CreateRotationAtPoint
This is the part that doesn’t work properly. The AssemblyOrigin is rotated, but it seems to take a random basepoint for this rotation. It is my goal that it rotates around its own (z)axis.
I understand what the code does, but i’m not a programmer so i don’t know how to edit the (or add) code.
I hope someone is willing to help me out.

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

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc =  DocumentManager.Instance.CurrentDBDocument
app = DocumentManager.Instance.CurrentUIApplication.Application

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

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

def tolist(obj1):
	if hasattr(obj1,"__iter__"): return obj1
	else: return [obj1]

elems = tolist(UnwrapElement(IN[0]))
axis = tolist(IN[1])
rot = tolist(IN[2])

outList = []

for e, a, r in zip(elems, axis, rot):
        trans = e.GetTransform()
    	transRot = trans.CreateRotationAtPoint(a.ToXyz(),math.radians(r), trans.Origin)
	try:
		TransactionManager.Instance.EnsureInTransaction(doc)
    	e.SetTransform(transRot)
		TransactionManager.Instance.TransactionTaskDone()
		outList.append(e)
	except Exception, e:
	outList.append(e.message)

OUT = outList

picture%204

Before running the Python script

picture%205

After running the Python script

picture%206

Any help is much appreciated.

Kind regards,
Mark

1 Like