Skip to main content
Solved

Update contextualization of plans with assets

  • November 12, 2024
  • 6 replies
  • 35 views

Pablo Palacios
Seasoned
Forum|alt.badge.img+3

Hello everyone in the community,
I have a question:
I have a project created with CDF and the assets are already contextualized with the P&IDs. I received new revisions of plans.
My question is, do I have to contextualize everything again and what has already been contextualized is lost? Is there a way to only upload the new plans in the new revisions and have it done automatically?

Best answer by Que Tran

You can use list annotations for a file with List annotation Python SDK. Sample code:


# List all annotations for the file with id=123:

from cognite.client import CogniteClient
from cognite.client.data_classes import AnnotationFilter
client = CogniteClient()
flt = AnnotationFilter(annotated_resource_type="file", annotated_resource_ids=[{"id": 123}])
annotations = client.annotations.list(flt, limit=None)

and then add annotations to a new file with Create an annotation. Sample code:

new_file_id = 234
for ann in annotations:
    ann.annotated_resource_id = new_file_id

client.annotations.create(annotations)

 

Best regards,

Que Tran

View original
Did this topic help you find an answer to your question?

6 replies

  • Practitioner
  • 42 replies
  • November 13, 2024

Hi @Pablo Palacios,

Thanks for bringing this up.

Handling revisions and automatically re-contextualizing new versions is on our long-term roadmap, but it’s not yet available.

In the meantime, one approach when uploading a new version of an already contextualized file is to use a script to fetch the annotations from the previous version and apply them to the new one. This way, you don’t need to fully re-contextualize the new file, you can just transfer the contextualized data from the previous version. But of course, the downside is that this approach doesn't account for any changes made between versions.

Best regards,
Que Tran


Pablo Palacios
Seasoned
Forum|alt.badge.img+3

Thanks for your reply,
Is this script you're talking about with the Python SDK?
Where can I see this code so I can implement it?


  • Practitioner
  • 42 replies
  • November 13, 2024

Hi @Pablo Palacios,
Is your data in Data Modeling or in the Asset-centric data model?


Pablo Palacios
Seasoned
Forum|alt.badge.img+3
Que Tran wrote:

Hi @Pablo Palacios,
Is your data in Data Modeling or in the Asset-centric data model?

 

Asset-centric data model


  • Practitioner
  • 42 replies
  • Answer
  • November 13, 2024

You can use list annotations for a file with List annotation Python SDK. Sample code:


# List all annotations for the file with id=123:

from cognite.client import CogniteClient
from cognite.client.data_classes import AnnotationFilter
client = CogniteClient()
flt = AnnotationFilter(annotated_resource_type="file", annotated_resource_ids=[{"id": 123}])
annotations = client.annotations.list(flt, limit=None)

and then add annotations to a new file with Create an annotation. Sample code:

new_file_id = 234
for ann in annotations:
    ann.annotated_resource_id = new_file_id

client.annotations.create(annotations)

 

Best regards,

Que Tran


Pablo Palacios
Seasoned
Forum|alt.badge.img+3

It worked well for me, this solves the update of new plans.
If the plans must come in the same size and format, it happened to me that the new version of the plan came with a different size and the annotations were displaced. But this solution fulfills what I needed.
Thanks


Reply


Cookie Policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie Settings