Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 32dca397a3 | |||
| 48759746dc | |||
| 4d5fb64893 | |||
| 6a3247aafa | |||
| ae0280a630 | |||
| 698b2a79fe |
@@ -1,7 +1,7 @@
|
||||
import bpy
|
||||
from bpy.types import Context, Event, UILayout
|
||||
from specklepy.core.api.inputs import CreateModelInput
|
||||
from typing import Tuple
|
||||
from specklepy.core.api.models import Model
|
||||
|
||||
from ..utils.account_manager import _client_cache
|
||||
|
||||
@@ -21,12 +21,12 @@ class SPECKLE_OT_create_model(bpy.types.Operator):
|
||||
return {"CANCELLED"}
|
||||
|
||||
try:
|
||||
model_id, model_name = create_model(
|
||||
model = _create_model(
|
||||
wm.selected_account_id, wm.selected_project_id, self.model_name
|
||||
)
|
||||
wm.selected_model_id = model_id
|
||||
wm.selected_model_name = model_name
|
||||
self.report({"INFO"}, f"Created model: {model_name} -> ID: {model_id}")
|
||||
wm.selected_model_id = model.id
|
||||
wm.selected_model_name = model.name
|
||||
self.report({"INFO"}, f"Created model: {model.name} -> ID: {model.id}")
|
||||
# Force redraw
|
||||
context.window.screen = context.window.screen
|
||||
context.area.tag_redraw()
|
||||
@@ -51,19 +51,17 @@ def unregister() -> None:
|
||||
bpy.utils.unregister_class(SPECKLE_OT_create_model)
|
||||
|
||||
|
||||
def create_model(account_id: str, project_id: str, model_name: str) -> Tuple[str, str]:
|
||||
def _create_model(account_id: str, project_id: str, model_name: str) -> Model:
|
||||
try:
|
||||
# Get cached client
|
||||
client = _client_cache.get_client(account_id)
|
||||
if not client:
|
||||
raise ValueError(f"Could not get client for account: {account_id}")
|
||||
|
||||
model = client.model.create(
|
||||
input=CreateModelInput(
|
||||
name=model_name, description="", project_id=project_id
|
||||
)
|
||||
)
|
||||
return (model.id, model.name)
|
||||
return model
|
||||
except Exception as e:
|
||||
# Clear cache on error to prevent stale clients
|
||||
_client_cache.clear()
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
from typing import Optional
|
||||
|
||||
import bpy
|
||||
from bpy.types import Context, Event, UILayout
|
||||
|
||||
from specklepy.core.api.enums import ProjectVisibility
|
||||
from specklepy.core.api.inputs import ProjectCreateInput
|
||||
from specklepy.core.api.inputs.project_inputs import WorkspaceProjectCreateInput
|
||||
from specklepy.core.api.enums import ProjectVisibility
|
||||
from typing import Tuple, Optional
|
||||
from specklepy.core.api.models import Project
|
||||
|
||||
from ..utils.account_manager import _client_cache
|
||||
|
||||
@@ -22,16 +23,16 @@ class SPECKLE_OT_create_project(bpy.types.Operator):
|
||||
|
||||
def execute(self, context: Context) -> set[str]:
|
||||
wm = context.window_manager
|
||||
project_id, project_name = create_project(
|
||||
project = _create_project(
|
||||
wm.selected_account_id,
|
||||
self.project_name,
|
||||
None
|
||||
if wm.selected_workspace.id == "personal"
|
||||
else wm.selected_workspace.id,
|
||||
)
|
||||
wm.selected_project_id = project_id
|
||||
wm.selected_project_name = project_name
|
||||
self.report({"INFO"}, f"Created project: {project_name} -> ID: {project_id}")
|
||||
wm.selected_project_id = project.id
|
||||
wm.selected_project_name = project.name
|
||||
self.report({"INFO"}, f"Created project: {project.name} -> ID: {project.id}")
|
||||
# Force redraw
|
||||
context.window.screen = context.window.screen
|
||||
context.area.tag_redraw()
|
||||
@@ -53,20 +54,19 @@ def unregister() -> None:
|
||||
bpy.utils.unregister_class(SPECKLE_OT_create_project)
|
||||
|
||||
|
||||
def create_project(
|
||||
def _create_project(
|
||||
account_id: str, project_name: str, workspace_id: Optional[str]
|
||||
) -> Tuple[str, str]:
|
||||
) -> Project:
|
||||
try:
|
||||
# Get cached client
|
||||
client = _client_cache.get_client(account_id)
|
||||
if not client:
|
||||
raise Exception(f"Could not get client for account: {account_id}")
|
||||
|
||||
if workspace_id:
|
||||
project = client.project.create_in_workspace(
|
||||
input=WorkspaceProjectCreateInput(
|
||||
name=project_name,
|
||||
description="",
|
||||
visibility=ProjectVisibility("PUBLIC"),
|
||||
visibility=ProjectVisibility.PUBLIC,
|
||||
workspaceId=workspace_id,
|
||||
)
|
||||
)
|
||||
@@ -75,11 +75,11 @@ def create_project(
|
||||
input=ProjectCreateInput(
|
||||
name=project_name,
|
||||
description="",
|
||||
visibility=ProjectVisibility("PUBLIC"),
|
||||
visibility=ProjectVisibility.PUBLIC,
|
||||
)
|
||||
)
|
||||
|
||||
return (project.id, project.name)
|
||||
return project
|
||||
except Exception as e:
|
||||
print(f"Failed to create project: {str(e)}")
|
||||
# Clear cache on error to prevent stale clients
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
from typing import Dict, Union
|
||||
|
||||
import bpy
|
||||
from bpy.types import Context
|
||||
from specklepy.transports.server import ServerTransport
|
||||
from specklepy.core.api import operations
|
||||
from specklepy.objects.models.collections.collection import Collection as SCollection
|
||||
from specklepy.core.api import host_applications, operations
|
||||
from specklepy.logging import metrics
|
||||
from specklepy.objects.graph_traversal.default_traversal import (
|
||||
create_default_traversal_function,
|
||||
)
|
||||
from specklepy.core.api import host_applications
|
||||
from specklepy.objects.models.collections.collection import Collection as SCollection
|
||||
from specklepy.transports.server import ServerTransport
|
||||
|
||||
from ..utils.get_ascendants import get_ascendants
|
||||
from ..utils.account_manager import _client_cache
|
||||
from ...converter.utils import find_object_by_id, get_project_workspace_id
|
||||
from ... import bl_info
|
||||
from ...converter.to_native import (
|
||||
convert_to_native,
|
||||
render_material_proxy_to_native,
|
||||
instance_definition_proxy_to_native,
|
||||
find_instance_definitions,
|
||||
instance_definition_proxy_to_native,
|
||||
render_material_proxy_to_native,
|
||||
)
|
||||
from specklepy.logging import metrics
|
||||
from ... import bl_info
|
||||
from typing import Dict, Union
|
||||
from ...converter.utils import find_object_by_id
|
||||
from ..utils.account_manager import _client_cache
|
||||
from ..utils.get_ascendants import get_ascendants
|
||||
|
||||
|
||||
def load_operation(
|
||||
@@ -33,9 +33,6 @@ def load_operation(
|
||||
|
||||
# get cached client
|
||||
client = _client_cache.get_client(context.window_manager.selected_account_id)
|
||||
if not client:
|
||||
print("No Speckle client found")
|
||||
return {}
|
||||
|
||||
print(f"Using client for account: {context.window_manager.selected_account_id}")
|
||||
|
||||
@@ -48,36 +45,21 @@ def load_operation(
|
||||
|
||||
metrics.set_host_app("blender")
|
||||
|
||||
# Get account for metrics tracking
|
||||
from specklepy.core.api.credentials import get_local_accounts
|
||||
|
||||
account = next(
|
||||
(
|
||||
acc
|
||||
for acc in get_local_accounts()
|
||||
if acc.id == context.window_manager.selected_account_id
|
||||
),
|
||||
None,
|
||||
metrics.track(
|
||||
metrics.RECEIVE,
|
||||
client.account,
|
||||
{
|
||||
"ui": "dui3",
|
||||
"hostAppVersion": ".".join(map(str, bl_info["blender"])),
|
||||
"core_version": ".".join(map(str, bl_info["version"])),
|
||||
"sourceHostApp": host_applications.get_host_app_from_string(
|
||||
version.source_application
|
||||
).slug,
|
||||
"isMultiplayer": version.author_user.id != client.account.userInfo.id,
|
||||
"workspace_id": client.project.get(wm.selected_project_id).workspace_id,
|
||||
},
|
||||
)
|
||||
|
||||
if account:
|
||||
metrics.track(
|
||||
metrics.RECEIVE,
|
||||
account,
|
||||
{
|
||||
"ui": "dui3",
|
||||
"hostAppVersion": ".".join(map(str, bl_info["blender"])),
|
||||
"core_version": ".".join(map(str, bl_info["version"])),
|
||||
"sourceHostApp": host_applications.get_host_app_from_string(
|
||||
version.source_application
|
||||
).slug,
|
||||
"isMultiplayer": version.author_user.id != account.userInfo.id,
|
||||
"workspace_id": get_project_workspace_id(
|
||||
client, wm.selected_project_id
|
||||
),
|
||||
},
|
||||
)
|
||||
|
||||
# Create material mapping first
|
||||
material_mapping = render_material_proxy_to_native(version_data)
|
||||
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
import bpy
|
||||
from bpy.types import Context, Collection as BlenderCollection
|
||||
from typing import List, Optional, Dict, Tuple
|
||||
from typing import Dict, List, Optional, Tuple
|
||||
|
||||
import bpy
|
||||
from bpy.types import Collection as BlenderCollection
|
||||
from bpy.types import Context
|
||||
from specklepy.core.api import operations
|
||||
from specklepy.core.api.inputs.version_inputs import CreateVersionInput
|
||||
from specklepy.logging import metrics
|
||||
from specklepy.objects import Base
|
||||
from specklepy.objects.models.collections.collection import Collection
|
||||
from specklepy.core.api import operations
|
||||
from specklepy.transports.server import ServerTransport
|
||||
from specklepy.core.api.inputs.version_inputs import CreateVersionInput
|
||||
from specklepy.objects.models.units import Units
|
||||
from specklepy.transports.server import ServerTransport
|
||||
|
||||
from ... import bl_info
|
||||
from ...converter.to_speckle import convert_to_speckle
|
||||
from ...converter.to_speckle.material_to_speckle import (
|
||||
add_render_material_proxies_to_base,
|
||||
)
|
||||
from ...converter.utils import get_project_workspace_id
|
||||
from ..utils.account_manager import _client_cache
|
||||
from specklepy.logging import metrics
|
||||
from ... import bl_info
|
||||
|
||||
|
||||
def publish_operation(
|
||||
@@ -33,8 +33,6 @@ def publish_operation(
|
||||
try:
|
||||
# get cached client
|
||||
client = _client_cache.get_client(wm.selected_account_id)
|
||||
if not client:
|
||||
return False, "No Speckle client found", None
|
||||
|
||||
transport = ServerTransport(stream_id=wm.selected_project_id, client=client)
|
||||
|
||||
@@ -52,40 +50,29 @@ def publish_operation(
|
||||
obj_id = operations.send(root_collection, [transport])
|
||||
|
||||
version_input = CreateVersionInput(
|
||||
objectId=obj_id,
|
||||
modelId=wm.selected_model_id,
|
||||
projectId=wm.selected_project_id,
|
||||
object_id=obj_id,
|
||||
model_id=wm.selected_model_id,
|
||||
project_id=wm.selected_project_id,
|
||||
message=version_message,
|
||||
sourceApplication="blender",
|
||||
source_application="blender",
|
||||
)
|
||||
|
||||
version = client.version.create(version_input)
|
||||
version_id = version.id
|
||||
|
||||
# Get account for metrics tracking
|
||||
from specklepy.core.api.credentials import get_local_accounts
|
||||
|
||||
account = next(
|
||||
(acc for acc in get_local_accounts() if acc.id == wm.selected_account_id),
|
||||
None,
|
||||
# track metrics
|
||||
metrics.set_host_app("blender")
|
||||
metrics.track(
|
||||
metrics.SEND,
|
||||
client.account,
|
||||
{
|
||||
"ui": "dui3",
|
||||
"hostAppVersion": ".".join(map(str, bl_info["blender"])),
|
||||
"core_version": ".".join(map(str, bl_info["version"])),
|
||||
"workspace_id": client.project.get(wm.selected_project_id).workspace_id,
|
||||
},
|
||||
)
|
||||
|
||||
if account:
|
||||
# track metrics
|
||||
metrics.set_host_app("blender")
|
||||
metrics.track(
|
||||
metrics.SEND,
|
||||
account,
|
||||
{
|
||||
"ui": "dui3",
|
||||
"hostAppVersion": ".".join(map(str, bl_info["blender"])),
|
||||
"core_version": ".".join(map(str, bl_info["version"])),
|
||||
"workspace_id": get_project_workspace_id(
|
||||
client, wm.selected_project_id
|
||||
),
|
||||
},
|
||||
)
|
||||
|
||||
# count total objects for success message
|
||||
total_objects = count_objects_in_collection(root_collection)
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import bpy
|
||||
from bpy.types import UILayout, Context, PropertyGroup, Event
|
||||
from bpy.types import Context, Event, PropertyGroup, UILayout
|
||||
|
||||
from ..utils.model_manager import get_models_for_project
|
||||
from ..utils.version_manager import get_latest_version
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
from typing import Dict, List, Optional, Tuple
|
||||
|
||||
import bpy
|
||||
from specklepy.core.api.credentials import get_local_accounts
|
||||
from typing import List, Tuple, Optional, Dict
|
||||
from specklepy.core.api.credentials import Account
|
||||
from specklepy.core.api.client import SpeckleClient
|
||||
from specklepy.core.api.credentials import Account, get_local_accounts
|
||||
from specklepy.core.api.wrapper import StreamWrapper
|
||||
|
||||
from .misc import strip_non_ascii
|
||||
|
||||
|
||||
@@ -23,7 +24,11 @@ class SpeckleClientCache:
|
||||
if not account:
|
||||
raise ValueError(f"No account found for ID: {account_id}")
|
||||
|
||||
client = SpeckleClient(host=account.serverInfo.url)
|
||||
assert account.serverInfo.url
|
||||
client = SpeckleClient(
|
||||
host=account.serverInfo.url,
|
||||
use_ssl=account.serverInfo.url.startswith("https"),
|
||||
)
|
||||
client.authenticate_with_account(account)
|
||||
self._clients[account_id] = client
|
||||
return client
|
||||
@@ -179,6 +184,7 @@ def get_project_from_url(
|
||||
try:
|
||||
wrapper = StreamWrapper(url)
|
||||
account = wrapper.get_account()
|
||||
assert account.id
|
||||
client = _client_cache.get_client(account.id)
|
||||
|
||||
# get the stream_id (project_id) from the wrapper
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
from typing import List, Optional, Tuple
|
||||
|
||||
from specklepy.core.api.inputs.project_inputs import ProjectModelsFilter
|
||||
from specklepy.core.api.models.current import Model
|
||||
from typing import List, Tuple, Optional
|
||||
from .misc import format_relative_time, strip_non_ascii
|
||||
|
||||
from .account_manager import _client_cache
|
||||
from .misc import format_relative_time, strip_non_ascii
|
||||
|
||||
|
||||
def get_models_for_project(
|
||||
@@ -18,17 +20,9 @@ def get_models_for_project(
|
||||
)
|
||||
return []
|
||||
|
||||
# Get cached client
|
||||
client = _client_cache.get_client(account_id)
|
||||
if not client:
|
||||
print(f"Error: Could not get client for account: {account_id}")
|
||||
return []
|
||||
|
||||
try:
|
||||
client.project.get(project_id)
|
||||
except Exception as e:
|
||||
print(f"Error: Project with ID {project_id} not found: {str(e)}")
|
||||
return []
|
||||
client.project.get(project_id)
|
||||
|
||||
filter = ProjectModelsFilter(search=search) if search else None
|
||||
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
from typing import List, Optional, Tuple
|
||||
|
||||
from specklepy.core.api.client import SpeckleClient
|
||||
from specklepy.core.api.resources.current.workspace_resource import WorkspaceResource
|
||||
from specklepy.core.api.inputs.project_inputs import WorksaceProjectsFilter
|
||||
from typing import List, Tuple, Optional
|
||||
from specklepy.core.api.credentials import Account
|
||||
from .misc import format_relative_time, format_role, strip_non_ascii
|
||||
from specklepy.core.api.inputs.project_inputs import WorksaceProjectsFilter
|
||||
from specklepy.core.api.resources.current.workspace_resource import WorkspaceResource
|
||||
|
||||
from .account_manager import _client_cache
|
||||
from .misc import format_relative_time, format_role, strip_non_ascii
|
||||
|
||||
|
||||
def get_projects_for_account(
|
||||
account_id: str, workspace_id: str = None, search: Optional[str] = None
|
||||
account_id: str, workspace_id: str, search: Optional[str] = None
|
||||
) -> List[Tuple[str, str, str, str, bool]]:
|
||||
"""
|
||||
fetches projects for a given account from the Speckle server
|
||||
@@ -102,12 +104,13 @@ def _get_personal_projects_with_permissions(
|
||||
helper function to get personal projects with permissions using the old method
|
||||
"""
|
||||
from specklepy.core.api.inputs.user_inputs import UserProjectsFilter
|
||||
|
||||
from .account_manager import can_load
|
||||
|
||||
filter = UserProjectsFilter(
|
||||
search=search,
|
||||
workspaceId=None,
|
||||
personalOnly=True,
|
||||
workspace_id=None,
|
||||
personal_only=True,
|
||||
include_implicit_access=True,
|
||||
)
|
||||
|
||||
@@ -141,12 +144,13 @@ def _get_projects_with_individual_permissions(
|
||||
Fallback helper function to get projects with permissions using individual API calls
|
||||
"""
|
||||
from specklepy.core.api.inputs.user_inputs import UserProjectsFilter
|
||||
|
||||
from .account_manager import can_load
|
||||
|
||||
filter = UserProjectsFilter(
|
||||
search=search,
|
||||
workspaceId=workspace_id,
|
||||
personalOnly=False,
|
||||
workspace_id=workspace_id,
|
||||
personal_only=False,
|
||||
include_implicit_access=True,
|
||||
)
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
from specklepy.core.api.client import SpeckleClient
|
||||
from .account_manager import _client_cache
|
||||
from typing import List, Tuple
|
||||
from .misc import format_relative_time
|
||||
from specklepy.core.api.inputs.model_inputs import ModelVersionsFilter
|
||||
|
||||
from specklepy.core.api.client import SpeckleClient
|
||||
from specklepy.core.api.models.current import Version
|
||||
|
||||
from .account_manager import _client_cache
|
||||
from .misc import format_relative_time
|
||||
|
||||
|
||||
def get_versions_for_model(
|
||||
account_id: str, project_id: str, model_id: str
|
||||
@@ -20,17 +21,11 @@ def get_versions_for_model(
|
||||
)
|
||||
return []
|
||||
|
||||
# Get cached client
|
||||
client: SpeckleClient = _client_cache.get_client(account_id)
|
||||
if not client:
|
||||
print(f"Error: Could not get client for account: {account_id}")
|
||||
return []
|
||||
|
||||
filter: ModelVersionsFilter = ModelVersionsFilter(priorityIds=[])
|
||||
|
||||
# Get versions
|
||||
versions: List[Version] = client.version.get_versions(
|
||||
project_id=project_id, model_id=model_id, limit=10, filter=filter
|
||||
versions = client.version.get_versions(
|
||||
project_id=project_id, model_id=model_id, limit=10
|
||||
)
|
||||
versions_list: List[Tuple[str, str, str]] = []
|
||||
for version in versions.items:
|
||||
@@ -66,9 +61,6 @@ def get_latest_version(
|
||||
|
||||
# Get cached client
|
||||
client: SpeckleClient = _client_cache.get_client(account_id)
|
||||
if not client:
|
||||
print(f"Error: Could not get client for account: {account_id}")
|
||||
return ("", "", "")
|
||||
|
||||
# Get versions (limit to 1 since we only need the latest)
|
||||
versions: List[Version] = client.version.get_versions(
|
||||
|
||||
@@ -5,7 +5,6 @@ from specklepy.objects import Base
|
||||
from specklepy.objects.graph_traversal.default_traversal import (
|
||||
create_default_traversal_function,
|
||||
)
|
||||
from specklepy.core.api.client import SpeckleClient
|
||||
|
||||
|
||||
def to_rgba(argb_int: int) -> Tuple[float, float, float, float]:
|
||||
@@ -187,21 +186,3 @@ def find_object_by_id(root_object: Base, target_id: str) -> Optional[Base]:
|
||||
return None
|
||||
|
||||
return deep_search(root_object)
|
||||
|
||||
|
||||
def get_project_workspace_id(client: SpeckleClient, project_id: str) -> Optional[str]:
|
||||
workspace_id = None
|
||||
server_version = client.project.server_version or client.server.version()
|
||||
|
||||
# Local yarn builds of server will report a server version if "dev"
|
||||
# We'll assume that local builds are up-to-date with the latest features
|
||||
if server_version[0] == "dev":
|
||||
maj = 999
|
||||
min = 999
|
||||
else:
|
||||
maj = server_version[0]
|
||||
min = server_version[1]
|
||||
|
||||
if maj > 2 or (maj == 2 and min > 20):
|
||||
workspace_id = client.project.get(project_id).workspace_id
|
||||
return workspace_id
|
||||
|
||||
Reference in New Issue
Block a user