stability cad check
This commit is contained in:
parent
3e3a7360b8
commit
f9f58b3971
16 changed files with 196 additions and 152 deletions
95
cad_stability_check/.gitignore
vendored
Normal file
95
cad_stability_check/.gitignore
vendored
Normal file
|
@ -0,0 +1,95 @@
|
|||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
env/
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*,cover
|
||||
.hypothesis/
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
*.pot
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
local_settings.py
|
||||
|
||||
# Flask stuff:
|
||||
instance/
|
||||
.webassets-cache
|
||||
|
||||
# Scrapy stuff:
|
||||
.scrapy
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
|
||||
# PyBuilder
|
||||
target/
|
||||
|
||||
# Jupyter Notebook
|
||||
.ipynb_checkpoints
|
||||
|
||||
# pyenv
|
||||
.python-version
|
||||
|
||||
# celery beat schedule file
|
||||
celerybeat-schedule
|
||||
|
||||
# SageMath parsed files
|
||||
*.sage.py
|
||||
|
||||
# dotenv
|
||||
.env
|
||||
|
||||
# virtualenv
|
||||
.venv
|
||||
venv/
|
||||
ENV/
|
||||
|
||||
# Spyder project settings
|
||||
.spyderproject
|
||||
|
||||
# Rope project settings
|
||||
.ropeproject
|
||||
env.json
|
79
cad_stability_check/main.py
Normal file
79
cad_stability_check/main.py
Normal file
|
@ -0,0 +1,79 @@
|
|||
import FreeCAD as App
|
||||
import json
|
||||
import re
|
||||
from pyquaternion import Quaternion
|
||||
|
||||
def importObjAtPath(path: str):
|
||||
import importOBJ
|
||||
importOBJ.insert(u"" + path, App.ActiveDocument.Label)
|
||||
|
||||
pass
|
||||
|
||||
|
||||
def getFullPathObj(assemblyFolder: str, name: str):
|
||||
return assemblyFolder + 'sdf/meshes/' + name + '.obj'
|
||||
|
||||
|
||||
def computedStabiliti(refElement, childElement):
|
||||
b = childElement.Shape.BoundBox
|
||||
App.activeDocument().addObject("Part::MultiCommon", "Common")
|
||||
App.activeDocument().Common.Shapes = [refElement, childElement, ]
|
||||
App.ActiveDocument.getObject('Common').ViewObject.ShapeColor = getattr(App.getDocument('cubes').getObject(
|
||||
refElement.Name).getLinkedObject(True).ViewObject, 'ShapeColor', App.getDocument('cubes').getObject('Common').ViewObject.ShapeColor)
|
||||
App.ActiveDocument.getObject('Common').ViewObject.DisplayMode = getattr(App.getDocument('cubes').getObject(
|
||||
childElement.Name).getLinkedObject(True).ViewObject, 'DisplayMode', App.getDocument('cubes').getObject('Common').ViewObject.DisplayMode)
|
||||
App.ActiveDocument.recompute()
|
||||
obj = App.ActiveDocument.getObjectsByLabel('Common')[0]
|
||||
|
||||
shp = obj.Shape
|
||||
bbox = shp.BoundBox
|
||||
if bbox.XLength == b.XLength and bbox.YLength == b.YLength and b.ZLength == bbox.ZLength:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def main():
|
||||
App.newDocument()
|
||||
env = json.loads((open('./env.json')).read())
|
||||
coordinatsFilePath = env.get('pathToTheSimulationCoordinatesFile')
|
||||
assemblyFolder = env.get('generationFolder')
|
||||
buildNumber = int(re.findall(r'\d', coordinatsFilePath)[0])
|
||||
|
||||
assemblyStructure = json.loads(
|
||||
(open(assemblyFolder + 'step-structure.json')).read())
|
||||
assemblyNumber = int(buildNumber)
|
||||
activeDetail = assemblyStructure[assemblyNumber]
|
||||
|
||||
subassemblyNotParticipatingInMarkup = assemblyStructure[0:assemblyNumber - 1]
|
||||
detailOfTheMarkingZoneOfWhich = assemblyStructure[assemblyNumber - 1]
|
||||
importObjAtPath(getFullPathObj(assemblyFolder, activeDetail))
|
||||
importObjAtPath(getFullPathObj(
|
||||
assemblyFolder, detailOfTheMarkingZoneOfWhich))
|
||||
meshMark = App.ActiveDocument.Objects[0]
|
||||
meshDetailOfTheMarkZone = App.ActiveDocument.Objects[1]
|
||||
meshMark.ViewObject.ShapeColor = (0.31, 0.77, 0.87)
|
||||
meshDetailOfTheMarkZone.ViewObject.ShapeColor = (0.68, 0.66, 0.95)
|
||||
for el in list(map(lambda el: getFullPathObj(assemblyFolder, el), subassemblyNotParticipatingInMarkup)):
|
||||
importObjAtPath(el)
|
||||
for el in App.ActiveDocument.Objects[2:App.ActiveDocument.Objects.__len__()]:
|
||||
el.ViewObject.ShapeColor = (0.32, 0.05, 0.38)
|
||||
|
||||
coordinats = json.loads((open(coordinatsFilePath)).read())
|
||||
inc = 1
|
||||
for el in App.ActiveDocument.Objects:
|
||||
pos = coordinats[inc]['position']
|
||||
qua = coordinats[inc]['quaternion']
|
||||
new_quaternion = Quaternion(qua[0], qua[1], qua[2], qua[3])
|
||||
rotation_matrix = new_quaternion.rotation_matrix
|
||||
current_position = el.Placement.Base
|
||||
new_position = App.Vector(current_position.x, current_position.y, current_position.z)
|
||||
new_placement = App.Placement(new_position, rotation_matrix)
|
||||
el.Placement = new_placement
|
||||
App.ActiveDocument.recompute()
|
||||
el.Placement.move(App.Vector(pos[0], pos[1], pos[2]))
|
||||
|
||||
print(computedStabiliti(meshMark, meshDetailOfTheMarkZone))
|
||||
pass
|
||||
|
||||
|
||||
main()
|
Loading…
Add table
Add a link
Reference in a new issue