How to paint a wall?

How to paint a wall?

Organon
Advisor Advisor
1,422 Views
3 Replies
Message 1 of 4

How to paint a wall?

Organon
Advisor
Advisor

Hello.

 

I'm trying to paint a wall in Revit 2014. First I get the material and then the faces of the wall, but when I select the wall nothing happens. This is the code in Python:

 

------------------------------------------------------------------------------------------------------------ 

def PaintFace(self):
        uidoc = self.ActiveUIDocument
        doc =  uidoc.Document
        
        collector = FilteredElementCollector(doc)
        materials = collector.WherePasses(ElementClassFilter(Material)).ToElements()

        for material in materials:
            if material.Name == 'Copper':
                matName = material
                break
        
        elRef = uidoc.Selection.PickObject(ObjectType.Element)
        wall = doc.GetElement(elRef)        
        
        geomElement = wall.get_Geometry(Options())
        for geomObject in geomElement:            
            if geomObject == Solid:
                solid = geomObject                
                for face in solid.Faces:
                    if doc.IsPainted(wall.Id, face) == False:
                        doc.Paint(wall.Id, face, matName.Id)

-----------------------------------------------------------------------------------------------------------

 

Any help is appreciated.

 

Regards.

 


Arquitectura | Análisis CAD & BIM | Diseño Paramétrico | Programación
BIM-METADATA | LinkedIn | YouTube
0 Likes
Accepted solutions (1)
1,423 Views
3 Replies
Replies (3)
Message 2 of 4

Revitalizer
Advisor
Advisor
Accepted solution

Hi Organon,

 

the first that comes in mind is:

Do you use a Transaction ?

I'm not experienced in Python but as far as I can see, changes to the Revit DB must be encapsulated in a Transaction, excepting when using the TransactionMode.Automatic attribute for an ExternalCommand.

 

Second idea: have you checked if your material is not null ?

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Message 3 of 4

Organon
Advisor
Advisor

Revitalizer,

 

Yes, you are right; a Transaction is requiered. Rookie mistake.

 

Thanks

 

Organon


Arquitectura | Análisis CAD & BIM | Diseño Paramétrico | Programación
BIM-METADATA | LinkedIn | YouTube
0 Likes
Message 4 of 4

arnostlobel
Alumni
Alumni

I actually recommend using Transaction directly in the code (where a model gets changed) depending on the Automatic Transaction mode, of which support will be phased out in Revit soon.

Arnošt Löbel
0 Likes