Add insulation error - expected ElementId, got int

Hi, i try to write program for add insulation in Revit model. Now i want put only one type of insulation and thicknes (user sets type and insulation → in the future) but i don’t know how to work around the error “expected ElementId, got int”. I tried few codes:
a) Plumbing.PipeInsulation.Create(doc,i.ElementId,599323,10) #599323 - insulation type id, 10 - thicknes
b) Plumbing.PipeInsulation.Create(doc,i,599323,10)
c) Plumbing.PipeInsulation.Create(doc,str(i.ElementId),599323,10)
etc. in all ways script doesn’t work because of wrong type of element id input. Thanks for help.
My code:

> import clr
> 
> import sys
> 
> import os
> 
> from rpw import revit
> 
> from Autodesk.Revit.UI.Selection import *
> 
> from Autodesk.Revit.DB import *
> 
> from pyrevit import DB, forms
> 
> doc = revit.doc
> 
> uidoc = revit.uidoc
> 
> # Pick model elements and add insulation
> 
> try:
> 
>     with forms.WarningBar(title="Pick elements in model"):
> 
>         collector = uidoc.Selection.PickObjects(ObjectType.Element)
> 
>        
> 
>     for i in collector:
> 
>         try:
> 
>            
> 
>             Plumbing.PipeInsulation.Create(doc,i.ElementId,599323,10) #599323 - insulation type id, 10 - thicknes
> 
>         except Exception as e:
> 
>             print(e)
> 
> except Exception as e:
> 
>     print(e)

Hi Pawel,

Plumbing.PipeInsulation.Create(doc,i.ElementId,ElementId(599323),10)

you are passing the insulation type Id as the integer
transforming it into an ElementId object should do

1 Like

This is the answer! But when i changed ElementId another problem arose “The document has no open transaction”. I workaround this thanks to this post Revit: Modifying is forbidden because the document has no open transaction - Stack Overflow

Thank you for your patiens i still learn how to read the documentation… I though the id should be the int.

No pb.
Me too…

Transactions the pyRevit way looks like this:

with revit.Transaction('name of the action you will see listed in the history of the Revit file'):
    # do your things
1 Like

I write this in that way (don’t know it is the best way when we think about optimalization):

        try:
            transaction = Transaction(doc, 'Transaction')
            transaction.Start()
            Plumbing.PipeInsulation.Create(doc,i.ElementId,ElementId(599323),1)
            transaction.Commit()
        except Exception as e: 
            print(e)