Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use IfcOpenShell's 2D engine #34

Open
yorikvanhavre opened this issue Mar 20, 2023 · 9 comments
Open

Use IfcOpenShell's 2D engine #34

yorikvanhavre opened this issue Mar 20, 2023 · 9 comments
Labels
enhancement New feature or request

Comments

@yorikvanhavre
Copy link
Owner

Use IfcOpenShell to generate SVG code.

@luzpaz luzpaz added the enhancement New feature or request label Mar 20, 2023
@yorikvanhavre
Copy link
Owner Author

yorikvanhavre commented Mar 21, 2023

@Moult are IfcConvert's svg output capabilities available from Python? I haven't found that anywhere, and I have the impression that BBIM uses its own system to get an SVG view from a mesh, right?

Looking at https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.7.0/src/blenderbim/blenderbim/bim/module/drawing/svgwriter.py now but the magic seems to be happening somewhere else...

@Moult
Copy link
Collaborator

Moult commented Mar 21, 2023

The SVG serialization capabilities are available from Python, but it is not documented. One example usage may be found in the ifcopenshell.draw module, and another in blenderbim/BIM/module/drawing/operator.py in create_drawing (see generate_line work).

However the BlenderBIM Add-on uses a hybrid of the serialiser for line work and our own svg writer for annotations. This is because it's all a wip and whereas line work is fast in c++ and changes less often which needs recompilation, annotation features change more frequently and are relatively simple and may be prototyped in python.

@yorikvanhavre
Copy link
Owner Author

Thanks! I begin to have a picture.

Yes, doing the annotation work in python is also what we do in FreeCAD. There is so much little detail there to adjust that it makes all sense, and it's still globally relatively fast (much faster than the actual HLR work)

So basically we need to work with a svg serializer:

settings = ifcopenshell.geom.settings(DISABLE_TRIANGULATION=True, STRICT_TOLERANCE=True, INCLUDE_CURVES=True)
buffer = ifcopenshell.geom.serializers.buffer()
serialiser = ifcopenshell.geom.serializers.svg(buffer, settings)
serialiser.setFile(ifcfile)
it = ifcopenshell.geom.iterator(settings, ifcfile, multiprocessing.cpu_count(), include=elements)
if it.initialize():
    while True:
        serialiser.write(it.get())
        if not it.next():
            break
serialiser.finalize()
results = buffer.get_value()

Next question then (Thanks for your patience 😅) How do you set the projection direction, and/or cut plane?

@yorikvanhavre
Copy link
Owner Author

yorikvanhavre commented Mar 22, 2023

Ok I think found the answer myself in https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.7.0/src/ifcopenshell-python/ifcopenshell/draw.py :

serialiser.addDrawing(
        (x,y,z), # location
        (x,y,z), # z axis (view direction)
        (x,y,z), # x axis
        "Test", # drawing name
        True)    # include projection

@Moult
Copy link
Collaborator

Moult commented Mar 22, 2023

Well actually no, the projection direction and cut plane is set in the geometry of the IfcAnnotation object with ObjectType="DRAWING". We established a convention to use a box representation to represent the "section box" of the drawing. So everything is stored in the model and the geometry of the section box is in the model too, so it can be used immediately for intersection tests. It's best to create a drawing in BBIM to see what I mean.

@yorikvanhavre
Copy link
Owner Author

Ok. it's pretty easy to add such an object (all the data can be obtained from an arch section plane). How do you inform the serializer of which drawing it should use? seraliser.setElevationRefGuid() ? Is there an different setting if you want a section or just a projection (no cut lines)? Or is that handled automatically?

@yorikvanhavre
Copy link
Owner Author

i really need to tweak my mind that EVERYTHING becomes part of the IFC file :) it's really cool

@yorikvanhavre
Copy link
Owner Author

Is there an different setting if you want a section or just a projection (no cut lines)? Or is that handled automatically?

Ok found it myself I guess..

serialiser.setAutoElevation(True)
serialiser.setAutoSection(True)

I guess we'll need to play a bit with those settings. Probably the best path forward is to use ifcopenshell.draw:

settings = ifcopenshell.draw.draw_settings()
settings.drawing_guid = "XXXX" #  the guid of the drawing to use
svg_result = ifcopenshell.main(settings, [ifcfile])

@yorikvanhavre
Copy link
Owner Author

Example at https://gitlab.com/osarch/FreeMVD_WorkFlow/-/tree/master/Examples/BlenderBIM%20-%20annotation%20file
To create a view:
IfcAnnotation ObjectType="DRAWING" -> IfcShapeRepresentation -> IfcSolid -> IfcBlock(x,y,z)
Still need to figure out the placement

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants