Agisoft Metashape

Agisoft Metashape => Python and Java API => Topic started by: justinT on May 26, 2022, 03:59:25 AM

Title: Set distances of scalebars via Python API
Post by: justinT on May 26, 2022, 03:59:25 AM
Hi all,

I am trying to update the distances of scalebars via the Python API of Metashape. However, it turned out that my code does not work. Please kindly find my code as follows:
Code: [Select]
    chunk.addScalebar(chunk.markers[0], chunk.markers[1])
    chunk.addScalebar(chunk.markers[0], chunk.markers[2])
    chunk.addScalebar(chunk.markers[0], chunk.markers[3])
    chunk.addScalebar(chunk.markers[1], chunk.markers[2])
    chunk.addScalebar(chunk.markers[1], chunk.markers[3])
    chunk.addScalebar(chunk.markers[2], chunk.markers[3])

    chunk.sortScalebars()
    #Input distance of scalebars.
    chunk.scalebars[0].Reference.distance = 0.03
    chunk.scalebars[1].Reference.distance = 0.04
    chunk.scalebars[2].Reference.distance = 0.05
    chunk.scalebars[3].Reference.distance = 0.05
    chunk.scalebars[4].Reference.distance = 0.04
    chunk.scalebars[5].Reference.distance = 0.03

This code does not give me any error or warning. However, the corresponding distances will not change accordingly.

However, I found it is possible for me to rename the scalebars via the code:

Code: [Select]
chunk.scalebars[0].label = "example_scalebar"

Thus, I was wondering if I might be looking at the wrong functions/objects to change the distance.

Thank you so much for your attention.
Title: Re: Set distances of scalebars via Python API
Post by: Alexey Pasumansky on May 30, 2022, 03:54:23 PM
Hello Justin,

You should use the following (error in your code is related to the capital letter in Reference):

Code: [Select]
chunk.scalebars[0].reference.distance = 0.03
 chunk.scalebars[0].reference.enabled = True
 #...
 chunk.updateTransform()
Title: Re: Set distances of scalebars via Python API
Post by: justinT on June 02, 2022, 08:25:38 PM
Thank you so much Alexey! It works fine now!