Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Edit Panel Schedule

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
Anonymous
1495 Views, 3 Replies

Edit Panel Schedule

Hello
I'm trying to change the order of circuits in the Panel Schedule. Usually GUI options Move Up, Move Down are

used (pic below), but this time we have too many schedules to do this manually. 

GUItools.png

I tried using Dynamo Python script to automate this. I have found the suitable API entry at PanelScheduleView Class and wanted to use  MoveSlotTo . The following snippet of code seems to move an entry to a desired position, as I wanted it to (pic and code below).

 

psv = UnwrapElement(IN[0])

fr = 12
to = 13
can = psv.CanMoveSlotTo(fr,1, to, 1)

if can:
	TransactionManager.Instance.EnsureInTransaction(doc)
	psv.MoveSlotTo(fr,1, to, 1)
	TransactionManager.Instance.TransactionTaskDone()

 

 

REs.png

 

The problem is, when a schedule is filled, the function prevents me from swapping the places of two entries. There is also no room in the schedule to temporarily move one of them somewhere else. I get the following warning if I remove the IF safeguard (CanMoveSlotTo method) (pic below).

warm.png

 

I can't see any other function in the API I could use. Is there any other way to reorder the schedule entries?

 

Thank you for help!

3 REPLIES 3
Message 2 of 4
stever66
in reply to: Anonymous

You may need to temporarily disconnect one circuit from the panel, and then reconnect it later.  Or, you could add more spaces to the panel and then delete them later.   And Revit 2020 gives the possibility of moving one circuit to feed through lugs, and then moving it back to a breaker once space is available ( assuming there isn’t something already connected to the feed through lugs.)

I assume this can all be accomplished through the api, but I haven’t searched for possible commands to do this.

 

 

 

 

 

 

Message 3 of 4
Anonymous
in reply to: stever66

Thank you for a hint. Adding a space sounds like it could solve my issue. If I manage to solve the problem this way I will post a code later, "for future generations". In the mean time, I leave the topic open, maybe there's simpler way to do this, like accessing GUI functionality, or something. MoveSlotTo method is a little bit uncooperative.

Message 4 of 4
Anonymous
in reply to: stever66

You were right, temporarily disconnecting the circuit did the job. Here is my code should anyone need it in the future. Initially I wanted to run this in SharpDevelop as a Macro, but unfortunately, there seems to be some issue with the DisconnectPanel(), which causes internal Revit error.

 

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


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

# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
# ToPoint, ToXYZ, etx
clr.ImportExtensions(Revit.GeometryConversion)


# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager


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

psv = uidoc.ActiveView

if( not isinstance(psv, PanelScheduleView ) ):
	raise Exception("Current view is not panel schedule")


psd = psv.GetTableData()

slotNumber = psd.NumberOfSlots
off = 2

panel = doc.GetElement(psv.GetPanel() )

done = False

TransactionManager.Instance.EnsureInTransaction(doc)
while not done:
	done = True
	for i in range(slotNumber-1):
		crc1 = psv.GetCircuitByCell(i+off, 1)
		crc2 = psv.GetCircuitByCell(i+off+1, 1)
		
		if(crc1 == None and crc2 != None):
			psv.MoveSlotTo(i+off+1, 1, i+off, 1)
			done = False
		
		if(crc1 != None and crc2 != None):
			txt1 = psv.GetCellText(SectionType.Body, i+off, 2)
			txt2 = psv.GetCellText(SectionType.Body, i+off+1,2)
			
			if txt1 > txt2:
				crc1.DisconnectPanel()
				psv.MoveSlotTo(i+off+1, 1, i+off, 1)
				crc1.SelectPanel(panel)
				
				done = False
			
		
TransactionManager.Instance.TransactionTaskDone()

 

 

EDIT: It wasn't internal error, it was me forgetting to use transaction. So now I have two versions: in python and c sharp.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report