OSArch Community

IfcOS BCF parser, Get a list of viewpoints objects GUIDs by Python

  1. B

    I would like to get started hacking on the new BCF parser.

    Assumed I have a bcf and latest IfcOpenShell. Does someone has a code snipped to get a list of viewpoint objects GUIDs by Python?

    cheers bernd

  2. H
  3. H

    Just tested. Please note that bcf lib only supports version 2.1 and 3.0.

    
    from bcf import bcfxml
    
    
    bcf = bcfxml.load("/path/to/file.bcf")
    
    for topic_guid in bcf.get_topics():
    
        viewpoints = bcf.get_viewpoints(topic_guid )
    
        for viewpoint_guid in viewpoints:
    
            print(viewpoint_guid)
    

    I think get_topics should return a list of Topic objects and get_viewpoints should return a list of Viewpoint objects. That sounds more pythonic. What do you think @Moult ?

  4. B

    thanks very much ... I had to adapt it a bit to get it working.

    import sys
    
    sys.path.append("C:/Users/BHA/Desktop/bcftest/bcf")
    
    
    
    from bcf import bcfxml
    
    bcf = bcfxml.load("C:/Users/BHA/Desktop/bcftest/Issues_2021-06-24_20.26.bcf")
    
    
    
    for topic_guid, topic_obj in bcf.get_topics().items():
    
        print(topic_obj.title)
    
        viewpoints = bcf.get_viewpoints(topic_obj.guid)
    
        for viewpoint_guid, viewpoint_obj in viewpoints.items():
    
            print(viewpoint_obj.guid)

    this is what it came out ... :-)

    >>> import sys
    
    >>> sys.path.append("C:/Users/BHA/Desktop/bcftest/bcf")
    
    >>> 
    
    >>> from bcf import bcfxml
    
    >>> bcf = bcfxml.load("C:/Users/BHA/Desktop/bcftest/Issues_2021-06-24_20.26.bcf")
    
    >>> 
    
    >>> for topic_guid, topic_obj in bcf.get_topics().items():
    
    ...     print(topic_obj.title)
    
    ...     viewpoints = bcf.get_viewpoints(topic_obj.guid)
    
    ...     for viewpoint_guid, viewpoint_obj in viewpoints.items():
    
    ...         print(viewpoint_obj.guid)
    
    ... 
    
    test_2
    
    8eb860dd-735e-45ac-b368-8975382a2da4
    
    test_4
    
    4611f220-647f-4d56-b196-d355c39e44a6
    
    test_1
    
    d77374e9-97a1-4c03-9a42-9254cd432798
    
    test_5
    
    4ab0b1f5-ade5-46ff-a376-be2eb4770ca7
    
    Decke UG inkl Rampe
    
    841b257c-dc37-458a-bc6a-d0dddb2074d4
    
    test_3
    
    82c10923-da08-478a-8a0f-286ca8446108
    
    c978fb25-f881-4ef5-9c15-19edf842a638
    
    >>> 
  5. B
    
    import sys
    
    sys.path.append("C:/Users/BHA/Desktop/bcftest/bcf")
    
    
    from bcf import bcfxml
    
    bcf = bcfxml.load("C:/Users/BHA/Desktop/bcftest/Issues_2021-06-24_20.26.bcf")
    
    
    the_topic = None
    
    for topic_guid, topic_obj in bcf.get_topics().items():
    
        print(topic_obj.title)
    
        if topic_obj.title == "test_2":
    
            the_topic = topic_obj
    
            break
    
    
    print(the_topic.title)
    
    viewpoints = bcf.get_viewpoints(the_topic.guid)
    
    for viewpoint_guid, viewpoint_obj in viewpoints.items():
    
        for component in viewpoint_obj.components.visibility.exceptions:
    
            print("    {}".format(component.ifc_guid))
    
    
    
    >>> import sys
    
    >>> sys.path.append("C:/Users/BHA/Desktop/bcftest/bcf")
    
    >>> 
    
    >>> from bcf import bcfxml
    
    >>> bcf = bcfxml.load("C:/Users/BHA/Desktop/bcftest/Issues_2021-06-24_20.26.bcf")
    
    >>> 
    
    >>> the_topic = None
    
    >>> for topic_guid, topic_obj in bcf.get_topics().items():
    
    ...     print(topic_obj.title)
    
    ...     if topic_obj.title == "test_2":
    
    ...         the_topic = topic_obj
    
    ...         break
    
    ... 
    
    test_2
    
    >>> print(the_topic.title)
    
    test_2
    
    >>> viewpoints = bcf.get_viewpoints(the_topic.guid)
    
    >>> for viewpoint_guid, viewpoint_obj in viewpoints.items():
    
    ...     for component in viewpoint_obj.components.visibility.exceptions:
    
    ...         print("    {}".format(component.ifc_guid))
    
    ... 
    
        00kS9D1zD0ufeqXLHcYjOn
    
        1GIMuf0qz5qPFOfK7KZl9X
    
        1JDOfXAI96V8EMm0S6yv3L
    
        2joDpfilbB4w6j9gqHGMX7
    
    >>> 
    
  6. B

  7. B

    @htlcnn said:

    I think get_topics should return a list of Topic objects and get_viewpoints should return a list of Viewpoint objects. That sounds more pythonic. What do you think @Moult ?

    a list of the objects would make things easier, thats True

  8. M

    Isn't a dictionary better than a list? In a list you need to sort through all to find the topic you want, whereas a dictionary (like it currently returns) you can find the topic by its ID, or run through its .values() as a list if you wished?

    Glad to see it works :)

  9. B

    @Moult said:

    ... run through its .values() ...

    Ahh yes this would have been easier than what I have used.

    Mhh most other parser libraries I know use list in such circumstances. For playing around a list is way simpler. Just assign the first item [0] to some variable and play around in python shell.

    Eventually it does not matter. As htlcnn said a list just feels more pythonic.

    BTW:

    great stuff this bcf library, will need and use it to read some information out of bcfs.

  10. M

    It would be awesome to replace the current FreeCAD bcfplugin lib with this one, since this one fixes many of the issues the bcfplugin had, and is updated for the latest BCF specs.

  11. B

    @Moult said:

    It would be awesome to replace the current FreeCAD bcfplugin lib with this one, since this one fixes many of the issues the bcfplugin had, and is updated for the latest BCF specs.

    yes for sure it makes sense to use your new parser. JFYI ... ATM this is not near the top of my OSS AEC TODO ... I just do not need it. There is BIMTester which is much more near the TOP and does not get done either ... I still use the version befor your big changes ... but on a daily basis ... :-)

  12. B

    are there some code examples around to create a new bcf from scratch with the ifcopenshell bcf paraser?

    bernd

  13. M

    Try this:

    
    bcfxml = bcf.v2.bcfxml.BcfXml()
    
    bcfxml.new_project()
    
  14. B

    it seams there has been taken place some API change ... following the code which works with latest BBIM for me to get main information out of the bcf ...

    from bcf import bcfxml
    
    bcf = bcfxml.load("C:/Users/BHA/Desktop/test.bbbim_zoom3_extended.bcf")
    
    for topic_guid, topic_obj in bcf.get_topics().items():
    
        print("{}: {}".format(topic_guid, topic_obj.topic.title))
    
        for viewpoint_guid, viewpoint_obj in topic_obj.viewpoints.items():
    
            print("  {}".format(viewpoint_obj.guid))

    inside BBIM ...

    >>> for topic_guid, topic_obj in bcf.get_topics().items():
    
    ...     print("{}: {}".format(topic_guid, topic_obj.topic.title))
    
    ...     for viewpoint_guid, viewpoint_obj in topic_obj.viewpoints.items():
    
    ...         print("  {}".format(viewpoint_obj.guid))
    
    ...         
    
    2ff81b84-6ce6-4607-8d7c-35a7f7714f96: mein zweiter issue
    
      f47abc58-465a-4a8c-aa25-d44abc94c0d7
    
      124cb5d4-ce47-455e-9938-3fc0a2a68a41
    
      9a36adef-b285-4673-a373-c7c03601b5a9
    
      c9c71e3e-b5ac-4a3b-9da6-480a914b5873
    
    81321a8d-8909-45f0-9982-edd0d116a533: myissue
    
      b5ccadb4-af11-4c1b-84df-da9c1a747075
    
    
    
    >>> 
  15. B

    some more viewpoint information ...

    for topic_guid, topic_obj in bcf.get_topics().items():
    
        print("{}: {}".format(topic_guid, topic_obj.topic.title))
    
        for viewpoint_guid, viewpoint_obj in topic_obj.viewpoints.items():
    
            print("  {}".format(viewpoint_obj.guid))
    
            comp = viewpoint_obj.visualization_info.components
    
            # print(comp)
    
            if comp is not None:
    
                print("    {}".format(comp.view_setup_hints))
    
                print("    {}".format(comp.selection))
    
                print("    {}".format(comp.visibility))
    
                #print("    {}".format(comp.visibility.exceptions))
    
                #print("    {}".format(comp.visibility.default_visibility))
    
                print("    {}".format(comp.coloring))
    
            else:
    
                print("    {}".format(comp))
  16. B

    even a few more view point information ...

    for topic_guid, topic_obj in bcf.get_topics().items():
    
        print("{}: {}".format(topic_guid, topic_obj.topic.title))
    
        for viewpoint_guid, viewpoint_obj in topic_obj.viewpoints.items():
    
            print("  {}".format(viewpoint_obj.guid))
    
            comp = viewpoint_obj.visualization_info.components
    
            # print(comp)
    
            if comp is not None:
    
                #
    
                print("    view_setup_hints")
    
                print("      {}".format(comp.view_setup_hints))
    
                #
    
                print("    visibility")
    
                if comp.visibility is None:
    
                    print("      {}".format(comp.visibility))
    
                else:
    
                    print("      {}".format(comp.visibility.default_visibility))
    
                    if hasattr(comp.visibility.exceptions, "component"):
    
                        print("      len   exceptions {}".format(len(comp.visibility.exceptions.component)))
    
                        print("      first exceptions {}".format(comp.visibility.exceptions.component[0]))
    
                #
    
                print("    selection")
    
                if comp.selection is None:
    
                    print("      {}".format(comp.selection))
    
                else:
    
                    print("      {}".format(comp.selection.component))
    
                #
    
                print("    coloring")
    
                if comp.coloring is None:
    
                    print("      {}".format(comp.coloring))
    
                else:
    
                    # print("      {}".format(comp.coloring.color))
    
                    print("      len  coloring: {}".format(len(comp.coloring.color)))
    
                    print("      first coloring: {}".format(comp.coloring.color[0].component))
    
                    print("      color coloring: {}".format(comp.coloring.color[0].color))
    
            else:
    
                print("    {}".format(comp))
    
            print("\n\n\n")

Login or Register to reply.