gbCollection class

class xgbxml.xgbxml.gbCollection(*items)[source]

This class is a collection of xgbxml elements.

It acts like a list, but is immutable so cannot be changed or updated. However the items in the list can be changed.

Instances of this class occur when a list of xgbxml elements is returned using the get_children() method or a method that is based on get_children().

For example, the code below returns a gbCollection instance of Building elements:

from lxml import etree
import xgbxml

parser=xgbxml.get_parser()  # default is gbXML version 6.01

tree=etree.parse('gbXMLStandard.xml', parser)
gbxml=tree.getroot()
buildings=gbxml.Campus.Buildings

print(buildings)
# prints "gbCollection(<Building (id="aim0013")>)"

print(type(buildings))
# prints "<class 'xgbxml.xgbxml.gbCollection'>"
__getattr__(key)[source]

This method catches any unknown attribute calls on a gbCollection instance.

This allows gbCollection instances to propogate methods and property calls onto the elements stored in the collection.

Parameters:
  • key – The key passes to __getattr__

  • key – str

This can be used to access all child elements of the elements in a gbCollection. For example, the code below shows a quick access approach to query all the openings in a gbXML file.

from lxml import etree
import xgbxml

parser=xgbxml.get_parser()  # default is gbXML version 6.01

tree=etree.parse('gbXMLStandard.xml', parser)
gbxml=tree.getroot()
openings=gbxml.Campus.Surfaces.Openings

print(len(openings))
# prints "138"

print(type(openings))
# prints "<class 'xgbxml.xgbxml.gbCollection'>"

This can also be used to access the properties of the elements of a gbCollection. For example, the code below shows a quick-access approach to listing all the openingTypes attributes of the openings in a gbXL file.

from lxml import etree
import xgbxml

parser=xgbxml.get_parser()  # default is gbXML version 6.01

tree=etree.parse('gbXMLStandard.xml', parser)
gbxml=tree.getroot()
opening_types=gbxml.Campus.Surfaces.Openings.openingType

print(len(opening_types))
# prints "138"

print(type(opening_types))
# prints "<class 'tuple'>"

print(opening_types)
# prints "('NonSlidingDoor', 'NonSlidingDoor', 'NonSlidingDoor', ...)"

The approach also works with method calls. For example, the code below creates a list of the areas of all openings in a gbXML file.

from lxml import etree
import xgbxml

parser=xgbxml.get_parser()  # default is gbXML version 6.01

tree=etree.parse('gbXMLStandard.xml', parser)
gbxml=tree.getroot()
surface_areas=gbxml.Campus.Surfaces.Openings.get_area()

print(len(surface_areas))
# prints "138"

print(type(surface_areas))
# prints "<class 'tuple'>"

print(surface_areas)
# prints "(21.0, 21.000000056466668, 21.0, ...)"