PostableCommand.AlignedToSamePlace

Hello everyone,

As you can see in the title, I am trying to copy one element instance several times at the same location. In order to do so, I looked for the command “Aligned to Same Place” in the Revit API.
image

I would need some aid as I do not know how to interpret that API command in a Python node. I tried to do the following with no success.

Any kind of suggestion?

Thank you so much.

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

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

clr.AddReference("RevitAPI")
import Autodesk

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIDocument
uiapp = DocumentManager.Instance.CurrentUIApplication

clr.AddReference("System.Core")
from System.Collections.Generic import HashSet

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

# IN variables...
run = tolist(IN[0])[0]
elems = tolist(UnwrapElement(IN[1]))

# Main Code...
if run:
	# Get ElementIds to list...
	elemIds = HashSet[ElementId]([e.Id for e in elems])	
	# Set Selection (required for the postable command)...
	uidoc.Selection.SetElementIds(elemIds)	
	uidoc.RefreshActiveView()
	
	# Get RevitCommandId of PostableCommand...
	rvtComId = Autodesk.Revit.UI.PostableCommand(PostableCommand.AlignedToSamePlace)
	# Run PostableCommand...
	uiapp.PostCommand(rvtComId)
	
	OUT = "Command Has Run"
else:
	OUT = "Please set Run to True"

You may want to explore using a different workflow from PostCommand, as this is still limited to a ‘run one’ process and doesn’t like being chained as part of a workflow.

Exception: Revit does not support more than one command are posted.

Using the copy and paste-aligned commands is entirely possible.
Kind of a forced-run though, as I ran once to copy then (I used + to add an input to the Paste node) and ran again to paste.

Copy Code

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

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

clr.AddReference('RevitAPIUI')
from  Autodesk.Revit.UI import *
from Autodesk.Revit.UI.Events import DialogBoxShowingEventArgs

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

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

clr.AddReference('System')
from System.Collections.Generic import List as sList

doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIDocument
uiapp = DocumentManager.Instance.CurrentUIApplication

clr.AddReference("System.Core")
from System.Collections.Generic import HashSet

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

# IN variables...
run = tolist(IN[0])[0]
elems = tolist(UnwrapElement(IN[1]))

empty = sList[ElementId]()

# Main Code...
if run:
	# Get ElementIds to list...
	elemIds = HashSet[ElementId]([e.Id for e in elems])	
	
	# Set Selection (required for the postable command)...
	uidoc.Selection.SetElementIds(elemIds)	
	uidoc.RefreshActiveView()
	
	# Get Revit Command Id
	rvtCmdId_Copy = RevitCommandId.LookupCommandId('ID_EDIT_COPY')
		
	# Run Command
	uiapp.PostCommand(rvtCmdId_Copy)
	
	uidoc.Selection.SetElementIds(empty)
	
	OUT = elems
else:
	OUT = "Please set Run to True"

Paste Code

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

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

clr.AddReference('RevitAPIUI')
from  Autodesk.Revit.UI import *
from Autodesk.Revit.UI.Events import DialogBoxShowingEventArgs

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

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

clr.AddReference('System')
from System.Collections.Generic import List as sList

doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIDocument
uiapp = DocumentManager.Instance.CurrentUIApplication

clr.AddReference("System.Core")
from System.Collections.Generic import HashSet

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

# IN variables...
run = tolist(IN[0])[0]
elems = tolist(UnwrapElement(IN[1]))

# Main Code...
if run:
	# Get Revit Command Id
	rvtCmdId_PasteAligned = RevitCommandId.LookupCommandId('ID_EDIT_PASTE_ALIGNED_SAME_PLACE')
		
	# Run Command
	uiapp.PostCommand(rvtCmdId_PasteAligned)

	OUT = "New Elements Pasted Aligned"
else:
	OUT = "Please set Run to True"

CopyPaste.dyn (12.4 KB)

Tip: If you ever need to know the command name for something that you have just done in Revit, look in the journal files. :wink:

4 Likes