Skip to content

Commit

Permalink
Merge pull request #4 from paireks/dev_addition
Browse files Browse the repository at this point in the history
Dev addition
  • Loading branch information
paireks authored Mar 20, 2022
2 parents f9e2e06 + 909bd5e commit 87541ab
Show file tree
Hide file tree
Showing 8 changed files with 5,426 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# dotbimpy (Version 0.0.5)
# dotbimpy (Version 0.0.6)

## Description

Expand Down Expand Up @@ -176,6 +176,15 @@ file.view()
```
![2022-02-23_23h49_52](https://user-images.githubusercontent.com/47977819/155422920-9f0a9aa0-d3d6-442b-a0b0-084acb7e0ea7.png)


### Merge files

If you want to merge two files together:

```python
merged_file = file_a + file_b
```

### dotbimpy + cadquery

Sometimes it's much easier to create B-REP and then convert it into mesh. For this purpose you can try cadquery: https://github.com/CadQuery/cadquery
Expand Down
55 changes: 55 additions & 0 deletions dotbimpy/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import plotly.graph_objects as go
import pyquaternion
import numpy as np
import copy


class File:
Expand All @@ -21,6 +22,43 @@ def __eq__(self, other):
and self.elements == other.elements \
and self.info == other.info

def __add__(self, other):
if not isinstance(other, File):
return NotImplemented

new_meshes = []
new_elements = []
new_schema_version = self.schema_version
new_file_info = self.info.copy()

max_mesh_id = 0
for i in self.meshes:
if max_mesh_id < i.mesh_id:
max_mesh_id = i.mesh_id
new_meshes.append(copy.deepcopy(i))

for i in self.elements:
new_elements.append(copy.deepcopy(i))

for i in other.meshes:
new_id = i.mesh_id + max_mesh_id + 1
new_meshes.append(Mesh(new_id, i.coordinates.copy(), i.indices.copy()))

for i in other.elements:
new_id = i.mesh_id + max_mesh_id + 1
new_elements.append(Element(mesh_id=new_id,
color=copy.deepcopy(i.color),
rotation=copy.deepcopy(i.rotation),
vector=copy.deepcopy(i.vector),
info=i.info.copy(),
type=i.type,
guid=i.guid))

return File(schema_version=new_schema_version,
info=new_file_info,
meshes=new_meshes,
elements=new_elements)

def save(self, path):
if path[-4:] != ".bim":
raise Exception("Path should end up with .bim extension")
Expand Down Expand Up @@ -155,6 +193,17 @@ def __eq__(self, other):
and self.type == other.type \
and self.mesh_id == other.mesh_id

def equals_without_mesh_id(self, other):
if not isinstance(other, Element):
return NotImplemented

return self.info == other.info \
and self.color == other.color \
and self.guid == other.guid \
and self.rotation == other.rotation \
and self.vector == other.vector \
and self.type == other.type


class Color:
def __init__(self, r, g, b, a):
Expand Down Expand Up @@ -182,6 +231,12 @@ def __eq__(self, other):

return self.mesh_id == other.mesh_id and self.coordinates == other.coordinates and self.indices == other.indices

def equals_without_mesh_id(self, other):
if not isinstance(other, Mesh):
return NotImplemented

return self.coordinates == other.coordinates and self.indices == other.indices


class Rotation:
def __init__(self, qx, qy, qz, qw):
Expand Down
175 changes: 175 additions & 0 deletions dotbimpy/other/Truss.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "9d95439c-243c-46b9-981e-c1ebb4b358b8",
"metadata": {},
"source": [
"# Cadquery + ipywidget + dotbimpy"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "00596700-6ddc-4bf0-b437-325cc942bd3a",
"metadata": {},
"outputs": [],
"source": [
"from dotbimpy import *\n",
"from ipywidgets import interact\n",
"import cadquery\n",
"import uuid"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "ce601b01-9982-4e1e-a055-003b9f5129c1",
"metadata": {},
"outputs": [],
"source": [
"def cadquery_mesh_to_dotbim_mesh(cadquery_mesh, mesh_id):\n",
" vertices, triangles = cadquery_mesh\n",
" coordinates = []\n",
" for i in vertices:\n",
" coordinates.extend([i.x, i.y, i.z])\n",
" indices = [item for sublist in triangles for item in sublist]\n",
" return Mesh(mesh_id=mesh_id, coordinates=coordinates, indices=indices)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "0db56e56-dde0-4abb-8339-1f93ffa7abc4",
"metadata": {},
"outputs": [],
"source": [
"def create_mesh_tube(plane, face, l, h, t, mesh_id):\n",
" workplane = cadquery.Workplane(plane).circle(h).extrude(l).faces(face).workplane().circle(h-t).cutThruAll()\n",
" mesh_cq = workplane.val().tessellate(0.1)\n",
" mesh = cadquery_mesh_to_dotbim_mesh(mesh_cq, mesh_id)\n",
" return mesh\n",
"\n",
"def create_tube_element(vector, rotation, color, mesh_id, type_name):\n",
" return Element(mesh_id=mesh_id,vector=vector,guid=str(uuid.uuid4()),\n",
" info={\"Material\": \"Steel\"},rotation=rotation,type=type_name,color=color)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "bc39f142-8f1f-4d65-9d01-6fda00b1aebc",
"metadata": {},
"outputs": [],
"source": [
"def f(length):\n",
" meshes = []\n",
" elements = []\n",
" \n",
" # Creating chords\n",
" meshes.append(create_mesh_tube('YZ', '>X', length, 0.03, 0.01, 0))\n",
" elements.append(create_tube_element(Vector(0,0.25,0.25), Rotation(0,0,0,1), Color(0,0,255,255), 0, \"Top Chord\"))\n",
" elements.append(create_tube_element(Vector(0,-0.25,0.25), Rotation(0,0,0,1), Color(0,0,255,255), 0, \"Top Chord\"))\n",
" elements.append(create_tube_element(Vector(0,0.25,-0.25), Rotation(0,0,0,1), Color(0,0,255,255), 0, \"Bottom Chord\"))\n",
" elements.append(create_tube_element(Vector(0,-0.25,-0.25), Rotation(0,0,0,1), Color(0,0,255,255), 0, \"Bottom Chord\"))\n",
" \n",
" # Creating posts\n",
" meshes.append(create_mesh_tube('XY', '>Z', 0.46, 0.02, 0.005, 1))\n",
" elements.append(create_tube_element(Vector(0.25,0.25,-0.23), Rotation(0,0,0,1), Color(0,255,0,255), 1, \"Post\"))\n",
" elements.append(create_tube_element(Vector(0.25,-0.25,-0.23), Rotation(0,0,0,1), Color(0,255,0,255), 1, \"Post\"))\n",
" elements.append(create_tube_element(Vector(length-0.25,0.25,-0.23), Rotation(0,0,0,1), Color(0,255,0,255), 1, \"Post\"))\n",
" elements.append(create_tube_element(Vector(length-0.25,-0.25,-0.23), Rotation(0,0,0,1), Color(0,255,0,255), 1, \"Post\"))\n",
" \n",
" # Creating girder\n",
" meshes.append(create_mesh_tube('XZ', '>Y', 0.46, 0.02, 0.005, 2))\n",
" elements.append(create_tube_element(Vector(0.25,0.23,0.25), Rotation(0,0,0,1), Color(222,49,99,255), 2, \"Girder\"))\n",
" elements.append(create_tube_element(Vector(0.25,0.23,-0.25), Rotation(0,0,0,1), Color(222,49,99,255), 2, \"Girder\"))\n",
" elements.append(create_tube_element(Vector(length-0.25,0.23,0.25), Rotation(0,0,0,1), Color(222,49,99,255), 2, \"Girder\"))\n",
" elements.append(create_tube_element(Vector(length-0.25,0.23,-0.25), Rotation(0,0,0,1), Color(222,49,99,255), 2, \"Girder\"))\n",
" \n",
" # Creating webs\n",
" length_to_fill = length - 0.5\n",
" number_of_gaps = int(length_to_fill / 0.5)\n",
" meshes.append(create_mesh_tube('YZ', '>X', 1.41421*0.5, 0.015, 0.005, 3))\n",
" for i in range(number_of_gaps):\n",
" if i % 2 == 0:\n",
" elements.append(create_tube_element(Vector(i*0.5+0.25,0.25,0.5/2.0), Rotation(0,0.382683,0,0.92388), Color(255,165,0,255), 3, \"Web\"))\n",
" elements.append(create_tube_element(Vector(i*0.5+0.25,-0.25,-0.5/2.0), Rotation(0,-0.382683,0,0.92388), Color(255,165,0,255), 3, \"Web\"))\n",
" elements.append(create_tube_element(Vector(i*0.5+0.25,0.25,0.5/2.0), Rotation(0,0,-0.382683,0.92388), Color(255,165,0,255), 3, \"Web\"))\n",
" elements.append(create_tube_element(Vector(i*0.5+0.25,-0.25,-0.5/2.0), Rotation(0,0,0.382683,0.92388), Color(255,165,0,255), 3, \"Web\"))\n",
" else:\n",
" elements.append(create_tube_element(Vector(i*0.5+0.25,0.25,-0.5/2.0), Rotation(0,-0.382683,0,0.92388), Color(255,165,0,255), 3, \"Web\"))\n",
" elements.append(create_tube_element(Vector(i*0.5+0.25,-0.25,0.5/2.0), Rotation(0,0.382683,0,0.92388), Color(255,165,0,255), 3, \"Web\"))\n",
" elements.append(create_tube_element(Vector(i*0.5+0.25,-0.25,0.5/2.0), Rotation(0,0,0.382683,0.92388), Color(255,165,0,255), 3, \"Web\"))\n",
" elements.append(create_tube_element(Vector(i*0.5+0.25,0.25,-0.5/2.0), Rotation(0,0,-0.382683,0.92388), Color(255,165,0,255), 3, \"Web\"))\n",
" \n",
" # Creating webs on ends\n",
" meshes.append(create_mesh_tube('XZ', '>Y', 1.41421*0.5, 0.015, 0.005, 4))\n",
" elements.append(create_tube_element(Vector(0.25,0.25,0.5/2.0), Rotation(0.382683,0,0,0.92388), Color(255,105,180,255), 4, \"Web\"))\n",
" elements.append(create_tube_element(Vector(length-0.25,0.25,-0.5/2.0), Rotation(-0.382683,0,0,0.92388), Color(255,105,180,255), 4, \"Web\"))\n",
" \n",
" file = File(\"1.0.0\", meshes=meshes, elements=elements, info={\"Author\": \"John Doe\"})\n",
" file.view()\n",
" file.save(\"Truss.bim\")"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "04180879-ccdb-490d-a297-a62e304a5bf2",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "bc9cebdf52454b6ba0cb0f7099b7d8c3",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"interactive(children=(FloatSlider(value=6.0, description='length', max=10.0, min=2.0, step=1.0), Output()), _d…"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"<function __main__.f(length)>"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"interact(f, length=(2.0, 10.0, 1.00))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Anaconda (base)",
"language": "python",
"name": "anaconda-base"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading

0 comments on commit 87541ab

Please sign in to comment.