Projection to analytical column with python

Hello,
I want to project the analytical model of the column with two axes (Y and Z direction), I wanted to do these manipulations with Python, do you have any ideas? Thank you so much.

please who can help me :pray:

Hi @brahimlabbassi,

here is some python code that pretty much does your whole script…

AnalyticalStickModel.SetAligmentToGrids (Py)

##### Imports #####

import clr

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

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

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

##### Definitions #####

# Ensures object is always in a List...
def tolist(obj1):
	if hasattr(obj1,"__iter__"): return obj1
	else: return [obj1]

##### Inputs #####

ams = tolist(UnwrapElement(IN[0])) # Analytical stick model elements...
gridY = tolist(UnwrapElement(IN[1]))[0] # The Grid you want the Y Projection to be aligned to...
gridZ = tolist(UnwrapElement(IN[2]))[0] # The Grid you want the Z Projection to be aligned to...

##### Outputs #####

outList = [] # The element output...
report = [] # The success report...

##### Main Script #####

# Open a new Transaction as we are making changes to an Element...
TransactionManager.Instance.EnsureInTransaction(doc)
# Loop through all the analytical stick model elements...
for am in ams:
	try:
		# Set Alignment Method for both Base and Top to be by projection...
		am.SetAlignmentMethod(ST.AnalyticalElementSelector.Whole, ST.AnalyticalAlignmentMethod.Projection)
		# Set Projection for Y and Z to be the gridY and gridZ Plane respectively...
		am.SetProjection(ST.AnalyticalElementSelector.Whole, gridY.Id, gridZ.Id)
		# output results...
		outList.append(am)
		report.append("Success")
	# Catch any exceptions...
	except Exception, ex:
		outList.append(None)
		report.append("Failed: " + ex.message)		
TransactionManager.Instance.TransactionTaskDone()

# return user results to Dynamo Workspace...
OUT = outList, report

Note: I am using the actual methods for the AnalyticalStickModel rather than setting the parameters. But you could also set the Parameters too, but it’s better like this.

You can find the methods I used in the Revit API Inline Documentation…

Set Alignment

Set Projection

Hi @Daniel_Woodcock1
Great ! it works perfectly. Thanks a lot

You’re welcome @brahimlabbassi! :slightly_smiling_face: