Skip to content

Commit

Permalink
Added support to data_set_id in 3D models. (#1428)
Browse files Browse the repository at this point in the history
Co-authored-by: Håkon V. Treider <[email protected]>
  • Loading branch information
mithilacognite and haakonvt authored Oct 23, 2023
1 parent 41ec76f commit c8435fd
Show file tree
Hide file tree
Showing 7 changed files with 314 additions and 293 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ Changes are grouped as follows
- `Fixed` for any bug fixes.
- `Security` in case of vulnerabilities.

## [6.34.1] - 2023-10-23
### Added
- Support for setting `data_set_id` and `metadata` in `ThreeDModelsAPI.create`.
- Support for updating `data_set_id` in `ThreeDModelsAPI.update`.

## [6.34.0] - 2023-10-20
### Fixed
- `PropertyType`s no longer fail on instantiation, but warn on missing SDK support for the new property(-ies).
Expand Down
16 changes: 11 additions & 5 deletions cognite/client/_api/three_d.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,16 @@ def list(self, published: bool | None = None, limit: int | None = DEFAULT_LIMIT_
limit=limit,
)

def create(self, name: str | Sequence[str]) -> ThreeDModel | ThreeDModelList:
def create(
self, name: str | Sequence[str], data_set_id: int | None = None, metadata: dict[str, str] | None = None
) -> ThreeDModel | ThreeDModelList:
"""`Create new 3d models. <https://developer.cognite.com/api#tag/3D-Models/operation/create3DModels>`_
Args:
name (str | Sequence[str]): The name of the 3d model(s) to create.
data_set_id (int | None): The id of the dataset this 3D model belongs to.
metadata (dict[str, str] | None): Custom, application-specific metadata. String key -> String value.
Limits: Maximum length of key is 32 bytes, value 512 bytes, up to 16 key-value pairs.
Returns:
ThreeDModel | ThreeDModelList: The created 3d model(s).
Expand All @@ -146,14 +151,15 @@ def create(self, name: str | Sequence[str]) -> ThreeDModel | ThreeDModelList:
>>> from cognite.client import CogniteClient
>>> c = CogniteClient()
>>> res = c.three_d.models.create(name="My Model")
>>> res = c.three_d.models.create(name="My Model", data_set_id=1, metadata={"key1": "value1", "key2": "value2"})
"""
assert_type(name, "name", [str, Sequence])
item_processed: dict[str, Any] | list[dict[str, Any]]
if isinstance(name, str):
name_processed: dict[str, Any] | Sequence[dict[str, Any]] = {"name": name}
item_processed = {"name": name, "dataSetId": data_set_id, "metadata": metadata}
else:
name_processed = [{"name": n} for n in name]
return self._create_multiple(list_cls=ThreeDModelList, resource_cls=ThreeDModel, items=name_processed)
item_processed = [{"name": n, "dataSetId": data_set_id, "metadata": metadata} for n in name]
return self._create_multiple(list_cls=ThreeDModelList, resource_cls=ThreeDModel, items=item_processed)

def update(
self, item: ThreeDModel | ThreeDModelUpdate | Sequence[ThreeDModel | ThreeDModelUpdate]
Expand Down
2 changes: 1 addition & 1 deletion cognite/client/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import annotations

__version__ = "6.34.0"
__version__ = "6.34.1"
__api_subversion__ = "V20220125"
5 changes: 5 additions & 0 deletions cognite/client/data_classes/three_d.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,16 @@ def name(self) -> _PrimitiveThreeDModelUpdate:
def metadata(self) -> _ObjectThreeDModelUpdate:
return ThreeDModelUpdate._ObjectThreeDModelUpdate(self, "metadata")

@property
def data_set_id(self) -> _ObjectThreeDModelUpdate:
return ThreeDModelUpdate._ObjectThreeDModelUpdate(self, "data_set_id")

@classmethod
def _get_update_properties(cls) -> list[PropertySpec]:
return [
PropertySpec("name", is_nullable=False),
PropertySpec("metadata", is_container=True),
PropertySpec("data_set_id", is_nullable=True),
]


Expand Down
Loading

0 comments on commit c8435fd

Please sign in to comment.