Python Forum
Data not being set by x.Set() - Revit
Thread Rating:
  • 4 Vote(s) - 2.25 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Data not being set by x.Set() - Revit
#1
Hi Guys

im trying to write a script for Dynamo where i compare two values, from two 'elements' and if a==b AND c==d then copy the value from x to y.

my current code does not return any errors but the value does net get copied over.

Any help would be much appreciated.

fixtures = UnwrapElement(IN[0])
circuits = UnwrapElement(IN[1])

TransactionManager.Instance.EnsureInTransaction(doc)
for i in fixtures:
	a = i.LookupParameter("Comments")
	b = i.LookupParameter("Panel")
	c = i.LookupParameter("Circuit Number")
	for j in circuits:
		d = j.LookupParameter("Comments")
		e = j.LookupParameter("Panel")
		f = j.LookupParameter("Circtuit Number")
		if b==e and c==f:
			a.Set(d)
TransactionManager.Instance.TransactionTaskDone()
PS - my first of hopefully many posts in this community :D
Reply
#2
What's Dynamo? Do you have a link to the docs? Or at least the name of the module that UnwrapElement is coming from?
Reply
#3
Dynamo is a form of visual programming. At our company we specifically use Dynamo as an Add-in for Revit.

here are all the modules, if i remember correctly the UnwrapElement comes from Transaction Manager (I might be wrong, still a bit green with Python).

import clr
import sys

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

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

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

doc = DocumentManager.Instance.CurrentDBDocument
app = DocumentManager.Instance.CurrentUIApplication.Application

uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
Reply
#4
I think you'd have better luck asking the Dynamo/Revit community directly.

For anyone else who stumbles in here, Dynamo is: https://github.com/DynamoDS/Dynamo
And Revit looks like it's maybe the same thing, but built by AutoDesk: https://www.autodesk.com/products/revit/overview

And getting them to work together requires the Dynamo for Revit plugin: https://github.com/DynamoDS/DynamoRevit

UnwrapElement looks like it takes a Dynamo element, and returns the raw Revit element (which makes it faster and has more features or something, but then Dynamo stops tracking changes to it). The only way for Dynamo to know there's been changes to unwrapped elements is if there's a transaction (which it looks like OP is using).

I don't know what LookupParameter is/does, or what .Set() should do on whatever it returns, and how that process interacts with unwrapped elements.
Reply
#5
Thanks for all the suggestions.

By working in my own debugger i eventually found out it was a data type mismatch.

.set() was looking for a String and Revit Parameters are "Parameter" data type.

For anyone stumbling across this in the future:

fixtures = UnwrapElement(IN[0])
circuits = UnwrapElement(IN[1])
comments = IN[2]
panel = IN[3]
circuitNumber = IN[4]
debug = []

TransactionManager.Instance.EnsureInTransaction(doc)
for i in fixtures:
	a = i.LookupParameter(comments)
	b = i.LookupParameter(panel)
	c = i.LookupParameter(circuitNumber)
	for j in circuits:
		d = j.LookupParameter(comments)
		e = j.LookupParameter(panel)
		f = j.LookupParameter(circuitNumber)
		if (b.AsString()==e.AsString()) and (c.AsString()==f.AsString()):
			a.Set(d.AsString())
TransactionManager.Instance.TransactionTaskDone()
Reply
#6
Thanks for coming back with the solution :)
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020