BIM + Python

A cross-post for curious people. Thanks to PyRx.

import traceback
from pyrx_imp import Rx, Ge, Gs, Gi, Db, Ap, Ed, Bim
 
def PyRxCmd_Bim_cmdMyBimClassify() -> None:
    try:
        db = Db.curDb()
 
        ourBuilding = Bim.BimBuilding.createNewBuilding(db, "TowerNorth")
        ourBuilding.setDescription("the north side tower building")
        ourBuilding.setName("TowerNorth")
        ourBuilding.setLongName("TowerNorth")
 
        floor_1 = Bim.BimStory.createNewStory(db, "TowerNorth", "Floor 1")
        floor_1.setDescription("first floor")
        floor_1.setElevation(1.0)
        elev = floor_1.elevation()
        floor_2 = Bim.BimStory.createNewStory(db, "TowerNorth", "Floor 2")
        floor_2.setDescription("second floor")
        floor_1.setElevation(6.0)
        floor_3 = Bim.BimStory.createNewStory(db, "TowerNorth", "Floor X")
        floor_3.setDescription("Floor 3")
        floor_3.setElevation(11.0)
 
        if not ourBuilding.assignedObjects(db):
            print("creating building elements")
            box =  Db.Solid3d()
            box.createBox(100.0,35.0,20.0)
            box.transformBy(Ge.Matrix3d.translation(Ge.Vector3d(0,0,10.0)))
            bid = db.addToModelspace(box)
            ourBuilding.assignToEntity(bid)
            Bim.BimClassification.setName(bid, ourBuilding.name())
            Bim.BimClassification.setDescription(bid, ourBuilding.description())
 
        if not floor_1.isBuilding():
            print("creating floor 1")
            box =  Db.Solid3d()
            box.createBox(98, 33, 4)
            box.transformBy(Ge.Matrix3d.translation(Ge.Vector3d(0,0,3.0)))
            bid = db.addToModelspace(box)
            ourBuilding.assignToEntity(bid)
            floor_1.assignToEntity(bid)
            Bim.BimClassification.setName(bid, floor_1.name())
            Bim.BimClassification.setDescription(bid, floor_1.description())
 
        if not floor_2.isBuilding():
            print("creating floor 2")
            box =  Db.Solid3d()
            box.createBox(98, 33, 4)
            box.transformBy(Ge.Matrix3d.translation(Ge.Vector3d(0,0,8.0)))
            bid = db.addToModelspace(box)
            ourBuilding.assignToEntity(bid)
            floor_2.assignToEntity(bid)
            Bim.BimClassification.setName(bid, floor_2.name())
            Bim.BimClassification.setDescription(bid, floor_2.description())
 
        if not floor_3.isBuilding():
            print("creating floor 3")
            box =  Db.Solid3d()
            box.createBox(98, 33, 4)
            box.transformBy(Ge.Matrix3d.translation(Ge.Vector3d(0,0,13.0)))
            bid = db.addToModelspace(box)
            ourBuilding.assignToEntity(bid)
            floor_3.assignToEntity(bid)
            Bim.BimClassification.setName(bid, floor_3.name())
            Bim.BimClassification.setDescription(bid, floor_3.description())
 
        # put some objects to the floors
        # floor1
        box =  Db.Solid3d()
        box.createBox(2, 1, 0.5) # sofa
        box.transformBy(Ge.Matrix3d.translation(Ge.Vector3d(0,0,3.0)))
        bid = db.addToModelspace(box)
        ourBuilding.assignToEntity(bid)
        floor_1.assignToEntity(bid)
        Bim.BimClassification.setName(bid, "sofa 1")
        Bim.BimClassification.setDescription(bid, "leather, brown")
 
        box =  Db.Solid3d()
        box.createBox(10, 0.5, 1) # railing 1
        box.transformBy(Ge.Matrix3d.translation(Ge.Vector3d(0,0,3.0)))
        bid = db.addToModelspace(box)
        ourBuilding.assignToEntity(bid)
        floor_1.assignToEntity(bid)
        Bim.BimClassification.setName(bid, "railing 1")
        Bim.BimClassification.setDescription(bid, "to 2nd floor")
 
        box =  Db.Solid3d()
        box.createBox(10, 2.5, 0.5) # stair 1
        box.transformBy(Ge.Matrix3d.translation(Ge.Vector3d(0,0,3.0)))
        bid = db.addToModelspace(box)
        ourBuilding.assignToEntity(bid)
        floor_1.assignToEntity(bid)
        Bim.BimClassification.setName(bid, "stair 1")
        Bim.BimClassification.setDescription(bid, "to 2nd floor")
 
        # floor2
        box =  Db.Solid3d()
        box.createBox(2, 1, 0.5) # sofa 2
        box.transformBy(Ge.Matrix3d.translation(Ge.Vector3d(0,0,8.0)))
        bid = db.addToModelspace(box)
        ourBuilding.assignToEntity(bid)
        floor_2.assignToEntity(bid)
        Bim.BimClassification.setName(bid, "sofa 2")
        Bim.BimClassification.setDescription(bid, "cotton, white")
 
        box =  Db.Solid3d()
        box.createBox(10, 0.5, 1) # railing 2
        box.transformBy(Ge.Matrix3d.translation(Ge.Vector3d(0,0,8.0)))
        bid = db.addToModelspace(box)
        ourBuilding.assignToEntity(bid)
        floor_2.assignToEntity(bid)
        Bim.BimClassification.setName(bid, "railing 2")
        Bim.BimClassification.setDescription(bid, "to 3rd floor")
 
        box =  Db.Solid3d()
        box.createBox(10, 2.5, 0.5) # stair 1
        box.transformBy(Ge.Matrix3d.translation(Ge.Vector3d(0,0,8.0)))
        bid = db.addToModelspace(box)
        ourBuilding.assignToEntity(bid)
        floor_2.assignToEntity(bid)
        Bim.BimClassification.setName(bid, "stair 2")
        Bim.BimClassification.setDescription(bid, "to 3rd floor")
 
        # floor3
        box =  Db.Solid3d()
        box.createBox(2, 1, 0.5) # sofa 3
        box.transformBy(Ge.Matrix3d.translation(Ge.Vector3d(0,0,13.0)))
        bid = db.addToModelspace(box)
        ourBuilding.assignToEntity(bid)
        floor_2.assignToEntity(bid)
        Bim.BimClassification.setName(bid, "sofa 3")
        Bim.BimClassification.setDescription(bid, "leather, beige")
 
        box =  Db.Solid3d()
        box.createBox(10, 0.5, 1) # railing 3
        box.transformBy(Ge.Matrix3d.translation(Ge.Vector3d(0,0,13.0)))
        bid = db.addToModelspace(box)
        ourBuilding.assignToEntity(bid)
        floor_2.assignToEntity(bid)
        Bim.BimClassification.setName(bid, "railing 3")
        Bim.BimClassification.setDescription(bid, "to roof")
 
    except Exception as err:
        traceback.print_exception(err)

Comments

  • This is what Mistral does of it:

    def PyRxCmd_Bim_cmdMyBimClassify2() -> None:
        try:
            db = Db.curDb()
    
            # Create building
            ourBuilding = Bim.BimBuilding.createNewBuilding(db, "TowerNorth")
            ourBuilding.setDescription("the north side tower building")
            ourBuilding.setName("TowerNorth")
            ourBuilding.setLongName("TowerNorth")
    
            # Create floors
            floors = [
                ("Floor 1", "first floor", 1.0),
                ("Floor 2", "second floor", 6.0),
                ("Floor X", "Floor 3", 11.0)
            ]
    
            floor_objects = [
                ((2, 1, 0.5), "sofa", ["leather, brown", "cotton, white", "leather, beige"]),
                ((10, 0.5, 1), "railing", ["to 2nd floor", "to 3rd floor", "to roof"]),
                ((10, 2.5, 0.5), "stair", ["to 2nd floor", "to 3rd floor", "to roof"])
            ]
    
            for i, (name, desc, elev) in enumerate(floors):
                floor = Bim.BimStory.createNewStory(db, "TowerNorth", name)
                floor.setDescription(desc)
                floor.setElevation(elev)
    
                if not floor.isBuilding():
                    print(f"creating {name}")
                    box = Db.Solid3d()
                    box.createBox(98, 33, 4)
                    box.transformBy(Ge.Matrix3d.translation(Ge.Vector3d(0, 0, elev + 2.0)))
                    bid = db.addToModelspace(box)
                    floor.assignToEntity(bid)
                    Bim.BimClassification.setName(bid, name)
                    Bim.BimClassification.setDescription(bid, desc)
    
                for (dims, obj_name, obj_descs) in floor_objects:
                    box = Db.Solid3d()
                    box.createBox(*dims)
                    box.transformBy(Ge.Matrix3d.translation(Ge.Vector3d(0, 0, elev + 2.0)))
                    bid = db.addToModelspace(box)
                    floor.assignToEntity(bid)
                    Bim.BimClassification.setName(bid, f"{obj_name} {i + 1}")
                    Bim.BimClassification.setDescription(bid, obj_descs[i])
    
            # Create building elements if not assigned
            if not ourBuilding.assignedObjects(db):
                print("creating building elements")
                box = Db.Solid3d()
                box.createBox(100.0, 35.0, 20.0)
                box.transformBy(Ge.Matrix3d.translation(Ge.Vector3d(0, 0, 10.0)))
                bid = db.addToModelspace(box)
                ourBuilding.assignToEntity(bid)
                Bim.BimClassification.setName(bid, ourBuilding.name())
                Bim.BimClassification.setDescription(bid, ourBuilding.description())
    
        except Exception as err:
            traceback.print_exception(err)