mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 15:08:51 +00:00
Basic module for integration with Augin. Nice.
This commit is contained in:
@@ -41,6 +41,7 @@ if bpy is not None:
|
|||||||
"diff": None,
|
"diff": None,
|
||||||
"patch": None,
|
"patch": None,
|
||||||
"covetool": None,
|
"covetool": None,
|
||||||
|
"augin": None,
|
||||||
"debug": None,
|
"debug": None,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import bpy
|
||||||
|
from . import ui, prop, operator
|
||||||
|
|
||||||
|
classes = (
|
||||||
|
prop.AuginProperties,
|
||||||
|
ui.BIM_PT_augin,
|
||||||
|
operator.AuginLogin,
|
||||||
|
operator.AuginCreateNewModel,
|
||||||
|
operator.AuginReset,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def register():
|
||||||
|
bpy.types.Scene.AuginProperties = bpy.props.PointerProperty(type=prop.AuginProperties)
|
||||||
|
|
||||||
|
|
||||||
|
def unregister():
|
||||||
|
del bpy.types.Scene.AuginProperties
|
||||||
@@ -0,0 +1,133 @@
|
|||||||
|
import os
|
||||||
|
import bpy
|
||||||
|
import json
|
||||||
|
import string
|
||||||
|
import random
|
||||||
|
import shutil
|
||||||
|
import requests
|
||||||
|
import tempfile
|
||||||
|
import datetime
|
||||||
|
import addon_utils
|
||||||
|
|
||||||
|
|
||||||
|
class AuginLogin(bpy.types.Operator):
|
||||||
|
bl_idname = "bim.augin_login"
|
||||||
|
bl_label = "Login to Augin"
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
props = bpy.context.scene.AuginProperties
|
||||||
|
|
||||||
|
url = "https://server.auge.pro.br/API/v3/augin_rest.php/user_login"
|
||||||
|
payload = {"email": props.username, "password": props.password}
|
||||||
|
response = requests.request("POST", url, data=payload)
|
||||||
|
result = response.json()
|
||||||
|
|
||||||
|
if result["success_feedback"]["success"]:
|
||||||
|
props.token = result["token"]
|
||||||
|
else:
|
||||||
|
self.report({"ERROR"}, "Login failed :(")
|
||||||
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
|
class AuginReset(bpy.types.Operator):
|
||||||
|
bl_idname = "bim.augin_reset"
|
||||||
|
bl_label = "Upload Another Project"
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
props = bpy.context.scene.AuginProperties
|
||||||
|
props.is_success = False
|
||||||
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
|
class AuginCreateNewModel(bpy.types.Operator):
|
||||||
|
bl_idname = "bim.augin_create_new_model"
|
||||||
|
bl_label = "Create New Augin Model"
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
import boto3
|
||||||
|
from botocore.config import Config
|
||||||
|
props = bpy.context.scene.AuginProperties
|
||||||
|
|
||||||
|
# Create project
|
||||||
|
url = "https://server.auge.pro.br/API/v3/augin_rest.php/new_model"
|
||||||
|
|
||||||
|
chars = string.ascii_uppercase + string.ascii_lowercase + string.digits
|
||||||
|
props.project_filename = "BBM{}{}".format(
|
||||||
|
datetime.datetime.now().strftime("%Y%m%d%H%M%S"), "".join(random.choice(chars) for _ in range(6))
|
||||||
|
)
|
||||||
|
addon_version = ".".join(
|
||||||
|
[
|
||||||
|
str(x)
|
||||||
|
for x in [
|
||||||
|
addon.bl_info.get("version", (-1, -1, -1))
|
||||||
|
for addon in addon_utils.modules()
|
||||||
|
if addon.bl_info["name"] == "BlenderBIM"
|
||||||
|
][0]
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
payload = {
|
||||||
|
"user_token": props.token,
|
||||||
|
"partner_token": "Mmf2zpxdgrkHaUNRm6Cv7GLJdBAeb7Rn",
|
||||||
|
"project_name": props.project_name,
|
||||||
|
"model_filename": props.project_filename + ".ifc",
|
||||||
|
"thumb_filename": props.project_filename + ".png",
|
||||||
|
"app_name": "BlenderBIM",
|
||||||
|
"sw_version": bpy.app.version_string,
|
||||||
|
"plugin_version": addon_version,
|
||||||
|
}
|
||||||
|
response = requests.request("POST", url, data=payload)
|
||||||
|
result = response.json()
|
||||||
|
|
||||||
|
# Upload to S3
|
||||||
|
my_config = Config(
|
||||||
|
region_name=result["s3_region"],
|
||||||
|
)
|
||||||
|
|
||||||
|
client = boto3.client(
|
||||||
|
"s3",
|
||||||
|
aws_access_key_id=result["s3_key"],
|
||||||
|
aws_secret_access_key=result["s3_secret"],
|
||||||
|
aws_session_token=result["s3_token"],
|
||||||
|
config=my_config,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Generate thumb
|
||||||
|
old_file_format = context.scene.render.image_settings.file_format
|
||||||
|
old_filepath = context.scene.render.filepath
|
||||||
|
|
||||||
|
cam = bpy.data.cameras.new("Camera")
|
||||||
|
cam_obj = bpy.data.objects.new("Camera", cam)
|
||||||
|
context.scene.collection.objects.link(cam_obj)
|
||||||
|
context.scene.camera = cam_obj
|
||||||
|
|
||||||
|
tmpdir = tempfile.mkdtemp()
|
||||||
|
thumb_path = os.path.join(tmpdir, "thumb.png")
|
||||||
|
context.scene.render.image_settings.file_format = "PNG"
|
||||||
|
context.scene.render.filepath = thumb_path
|
||||||
|
bpy.ops.render.opengl(write_still=True)
|
||||||
|
|
||||||
|
context.scene.render.image_settings.file_format = old_file_format
|
||||||
|
context.scene.render.filepath = old_filepath
|
||||||
|
|
||||||
|
client.upload_file(bpy.context.scene.BIMProperties.ifc_file, result["s3_bucket"], result["model_path"])
|
||||||
|
client.upload_file(thumb_path, result["s3_bucket"], result["thumb_path"])
|
||||||
|
|
||||||
|
|
||||||
|
# Notify done
|
||||||
|
url = "https://server.auge.pro.br/API/v3/augin_rest.php/files_uploaded"
|
||||||
|
payload = {
|
||||||
|
"user_token": props.token,
|
||||||
|
"ifc_filesize": os.path.getsize(bpy.context.scene.BIMProperties.ifc_file),
|
||||||
|
"model_filesize": os.path.getsize(bpy.context.scene.BIMProperties.ifc_file),
|
||||||
|
"thumb_filesize": os.path.getsize(thumb_path),
|
||||||
|
"model_upload_path": result["model_path"],
|
||||||
|
"thumb_upload_path": result["thumb_path"],
|
||||||
|
"model_id": result["model_id"],
|
||||||
|
}
|
||||||
|
headers = {"Content-Type": "application/x-www-form-urlencoded"}
|
||||||
|
response = requests.request("POST", url, headers=headers, data=payload)
|
||||||
|
|
||||||
|
shutil.rmtree(tmpdir)
|
||||||
|
props.is_success = True
|
||||||
|
return {"FINISHED"}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import bpy.props
|
||||||
|
import bpy.types
|
||||||
|
|
||||||
|
|
||||||
|
class AuginProperties(bpy.types.PropertyGroup):
|
||||||
|
username: bpy.props.StringProperty(name="Username")
|
||||||
|
password: bpy.props.StringProperty(name="Password")
|
||||||
|
token: bpy.props.StringProperty(name="Token")
|
||||||
|
project_name: bpy.props.StringProperty(name="Project Name")
|
||||||
|
project_filename: bpy.props.StringProperty(name="IFC Filename")
|
||||||
|
is_success: bpy.props.BoolProperty(name="Is Successful Upload", default=False)
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
import bpy.types
|
||||||
|
|
||||||
|
|
||||||
|
class BIM_PT_augin(bpy.types.Panel):
|
||||||
|
bl_label = "Augin"
|
||||||
|
bl_idname = "BIM_PT_augin"
|
||||||
|
bl_options = {"DEFAULT_CLOSED"}
|
||||||
|
bl_space_type = "PROPERTIES"
|
||||||
|
bl_region_type = "WINDOW"
|
||||||
|
bl_context = "scene"
|
||||||
|
|
||||||
|
def draw(self, context):
|
||||||
|
layout = self.layout
|
||||||
|
layout.use_property_split = True
|
||||||
|
|
||||||
|
scene = context.scene
|
||||||
|
props = scene.AuginProperties
|
||||||
|
|
||||||
|
if not props.token:
|
||||||
|
row = layout.row()
|
||||||
|
row.prop(props, "username")
|
||||||
|
row = layout.row()
|
||||||
|
row.prop(props, "password")
|
||||||
|
row = layout.row()
|
||||||
|
row.operator("bim.augin_login")
|
||||||
|
return
|
||||||
|
|
||||||
|
row = layout.row()
|
||||||
|
row.label(text="Logged in as " + props.username)
|
||||||
|
|
||||||
|
if not bpy.context.scene.BIMProperties.ifc_file:
|
||||||
|
row = layout.row()
|
||||||
|
row.label(text="No IFC Found")
|
||||||
|
return
|
||||||
|
|
||||||
|
if props.is_success:
|
||||||
|
row = layout.row()
|
||||||
|
row.label(text="Upload Successful")
|
||||||
|
row = layout.row()
|
||||||
|
row.operator("bim.augin_reset")
|
||||||
|
else:
|
||||||
|
row = layout.row()
|
||||||
|
row.prop(props, "project_name")
|
||||||
|
row = layout.row()
|
||||||
|
row.operator("bim.augin_create_new_model")
|
||||||
Reference in New Issue
Block a user