Hi everyone I am developing a python script in Dynamo to change the TempertureRating and WireMaterial of a wiretype, based on another existing WireMaterial with its respective TemperatureRating. Please see the code and the image below. Any advice will be excellent to achieve this task thank you regards.
# Load the Python Standard and DesignScript Libraries
import clr
import sys
import System
#import Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB
from Autodesk.Revit.DB.Electrical import *
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
toList = lambda x : x if hasattr(x, '__iter__') else [x]
wiretype = UnwrapElement(IN[0])
TempRat = UnwrapElement(IN[1])
result = []
TransactionManager.Instance.EnsureInTransaction(doc)
#Main codes to be within this region
try:
for i in wiretype:
tempRating = i.TemperatureRating
wireMaterial = tempRating.MaterialType
TempRat = tempRating
TempRat.MaterialType = wireMaterial
result.append(TempRat.ToDSType(False).Name)
result.append(TempRat.MaterialType.ToDSType(False).Name)
except:
pass
#End of region
TransactionManager.Instance.ForceCloseTransaction()
OUT = result
This the result that I got.
This is how looks now
This is what I want to achieve
Remove the try/except loop from your code so we can see where your code is failing. I’m guessing it’s with your conversion. You’re using a geometry conversion when Python should automatically convert the Revit objects for you. Also, it would be helpful to show a screenshot of the inputs you’re providing to your python code.
EDIT: You also can’t assign a material like that and I don’t think you can get the name from either object that way either.
Thank you for your comments, I just remove the try/except and your right I can´t assign in that way. Here is the code and the the image with the error.
# Load the Python Standard and DesignScript Libraries
import clr
import sys
import System
#import Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB
from Autodesk.Revit.DB.Electrical import *
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
toList = lambda x : x if hasattr(x, '__iter__') else [x]
wiretype = UnwrapElement(IN[0])
TempRat = UnwrapElement(IN[1])
result = []
TransactionManager.Instance.EnsureInTransaction(doc)
#Main codes to be within this region
for i in wiretype:
tempRating = i.TemperatureRating
wireMaterial = tempRating.MaterialType
TempRat = tempRating
TempRat.MaterialType = wireMaterial
result.append(TempRat.ToDSType(False).Name)
result.append(TempRat.MaterialType.ToDSType(False).Name)
#End of region
TransactionManager.Instance.ForceCloseTransaction()
OUT = result
Here where I got the Wiretype. IN[0]
Here the existing TemperatureRatingType based on is WireMaterialType. this the IN[1] for the python script.
You’ll have to research the API and figure out how to assign a new MaterialType
to the TemperatureRatingType
.
What is the purpose of the initial TemperatureRatingType
that you supply to IN[1]
? Right now you overwrite it before doing anything with it.
the purpose of having the TemperatureRatingType was to obtain through the properties of MaterialType to get its MaterialType and assign it to the wiretype that I want to modify. but I guess I think is not the correct way to do it. So this is what I am confronting right now. The correct way to assign it
What I mean is you define TempRat
as the TemperatureRating
you supply to python but then you later define TempRat
as tempRating
you got from the WireType
. You’re not doing anything with the initial TemperatureRating
from IN[1]
.
TempRat = UnwrapElement(IN[1])
tempRating = i.TemperatureRating
TempRat = tempRating
Sorry bro I do not know what was on my mind, I am not a programmer, I am still learning, speaking of that, I just found the correct way to Addwiretype, is from the ElectricalSettings class Addwiretype method. But I need to get all the arguments properly work with this method. thanks for the help.
This what I got so far
# Load the Python Standard and DesignScript Libraries
import clr
import sys
import System
#import Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB
from Autodesk.Revit.DB.Electrical import *
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
toList = lambda x : x if hasattr(x, '__iter__') else [x]
wiretype = UnwrapElement(IN[0])
TempRat = UnwrapElement(IN[1])
WireTypeName = IN[2]
wireMaterialType = UnwrapElement(IN[3])
ElectricalSt = ElectricalSetting.GetElectricalSettings(doc)
result = []
TransactionManager.Instance.EnsureInTransaction(doc)
#Main codes to be within this region
for i in wiretype:
Insulation = wiretype.Insulation
Wiresize = wiretype.maxSize
NeutralML = wiretpe.neutralMultiplier
NeutralReq = wiretype.neutralRequired
NeutralMode = wiretype.neutralMode
Wireconduit = wiretype.conduit
AddwireType = ElectricalSt.AddWireType(TempRat,WireTypeName,wireMaterialType,Wiresize,NeutralML,NeutralReq, Insulation,NeutralMode,Wireconduit)
result.append(AddwireType.ToDSType(False).Name)
#.append(TempRat.MaterialType.ToDSType(False).Name)
#End of region
TransactionManager.Instance.ForceCloseTransaction()
OUT = result
1 Like
regards of getting the wiretype, I almost have the arguments of the Addwiretype method, but where if I am struggling is to get the InsulationType, any advice is more than welcome thanks. here the code
# Load the Python Standard and DesignScript Libraries
import clr
import sys
import System
#import Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB
from Autodesk.Revit.DB.Electrical import *
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
toList = lambda x : x if hasattr(x, '__iter__') else [x]
wiretype = UnwrapElement(IN[0])
TempRat = UnwrapElement(IN[1])
wireMaterialType = UnwrapElement(IN[2])
WireTypeName = IN[5]
NML = float(IN[3])
NReq = IN[4]
ElectricalSt = ElectricalSetting.GetElectricalSettings(doc)
result = []
TransactionManager.Instance.EnsureInTransaction(doc)
#Main codes to be within this region
Insulation = TempRat.InsulationTypes
for insl in Insulation:
foundISL = [insl.Id]
insulation = insl
if Insulation == "THWN":
Insulation = insl
Wiresize = TempRat.WireSizes
for ws in Wiresize:
foundWS = [ws.Size, ws.Ampacity, ws.Diameter]
wsize = ws.Size
if wsize == "2000":
Wiresize = ws.Size
Wireconduit = ElectricalSt.WireConduitTypes
for wc in Wireconduit:
foundWC = [wc.Name]
wconduit = wc.Name
if wconduit == "Steel":
Wireconduit = wc.Name
NeutralMode = NeutralMode.HotConductorSize
NeutralML = NML
NeutralReq = NReq
wireMaterialT = wireMaterialType
#AddwireType = ElectricalSt.AddWireType(WireTypeName,wireMaterialT,TempRat,Insulation,Wiresize,NeutralML,NeutralReq,NeutralMode,Wireconduit)
#result.append(AddwireType.ToDSType(False).Name)
#End of region
TransactionManager.Instance.ForceCloseTransaction()
OUT = Wiresize, Wireconduit, NeutralMode,NeutralML,NeutralReq,wireMaterialT,Insulation
This the result the problem that i have is to get one InsulationType for that list or set
After struggling all weekend i finally got a solution . Here is the code in case you need for thanks again for your feedbacks.
# Load the Python Standard and DesignScript Libraries
import clr
import sys
import System
#import Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB
from Autodesk.Revit.DB.Electrical import *
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
toList = lambda x : x if hasattr(x, '__iter__') else [x]
wiretype = UnwrapElement(IN[0])
TempRat = UnwrapElement(IN[1])
wireMaterialType = UnwrapElement(IN[2])
WireTypeName = IN[5]
NML = float(IN[3])
NReq = IN[4]
ElectricalSt = ElectricalSetting.GetElectricalSettings(doc)
result = []
TransactionManager.Instance.EnsureInTransaction(doc)
#Main codes to be within this region
Insulation = FilteredElementCollector(doc).OfClass(InsulationType).WhereElementIsElementType().FirstElement()
Wiresize = TempRat.WireSizes
for ws in Wiresize:
foundWS = [ws.Size, ws.Ampacity, ws.Diameter]
wsize = ws.Size
if wsize == "2000":
Wiresize = ws.Size
Wiresize1 = ws
Wireconduit = ElectricalSt.WireConduitTypes
for wc in Wireconduit:
foundWC = [wc.Name]
wconduit = wc.Name
if wconduit == "Steel":
Wireconduit = wc.Name
Wireconduit1 = wc
NeutralMode = NeutralMode.HotConductorSize
NeutralML = NML
NeutralReq = NReq
wireMaterialT = wireMaterialType
AddwireType = ElectricalSt.AddWireType(WireTypeName,wireMaterialT,TempRat,Insulation,Wiresize1,NeutralML,NeutralReq,NeutralMode,Wireconduit1)
result.append(AddwireType.ToDSType(False).Name)
#End of region
TransactionManager.Instance.ForceCloseTransaction()
OUT = AddwireType