Orientation of interactive length measurements

In this subforum specific Topics concerning ZEN Core, e.g workbenches, are discussed
Post Reply
Robert Nirnberger.2
Posts: 1
Joined: Thu Sep 08, 2022 8:22 am

Orientation of interactive length measurements

Post by Robert Nirnberger.2 »

Hallo,
i have to categorize interactive length measurements (ZEN Core Length Tool) whether orientation is horizontal , vertical.(exact)
I tried with orientation of bounding box, but that does not work, as the box is always oriented horizontal.
Need help with an ides or hint.
Thank you

image = Zen.Application.ActiveWorkbench.GetDefaultInputValue()

for g in range(0,image.Graphics.Count):
gr = image.Graphics[g]

print("Graphic name = ", gr.Name)
print("Measurement Text = ", gr.MeasurementText)
print("custom Text = ", gr.CustomText)

print("Angel", + gr.RotationAngle)

a,b,c,d = gr.GetBounds()
print("Bounds list " ,a,b,c,d)

b_bottomLeft_X = gr.Bounds.BottomLeft.X
b_bottomLeft_Y = gr.Bounds.BottomLeft.Y
b_bottomRight_X = gr.Bounds.BottomRight.X
b_bottomRight_y = gr.Bounds.BottomRight.Y

print("b_bottomLeft_X = ", b_bottomLeft_X, " b_bottomRight_X = " ,b_bottomRight_X)
print("b_bottomLeft_Y = " ,b_bottomLeft_Y, " b_bottomRight_y = ", b_bottomRight_y)
print()

b_topLeft_X = gr.Bounds.TopLeft.X
b_topLeft_Y = gr.Bounds.TopLeft.Y
b_topRight_X = gr.Bounds.TopRight.X
b_topRight_Y = gr.Bounds.TopRight.Y

print("b_topLeft_X = ", b_topLeft_X, " b_topRight_X = " ,b_topRight_X)
print("b_topLeft_Y = " ,b_topLeft_Y, " b_topRight_Y = ", b_topRight_Y)

kind regards

Robert


o
CarlZeissMicroscopy3
Posts: 180
Joined: Wed May 20, 2020 10:10 am

Re: Orientation of interactive length measurements

Post by CarlZeissMicroscopy3 »

Hello Robert Nirnberger,

there is no way to do that directly but when looking at the data a trick came to my mind.

Taking the MeasurementText and convert it to a float either the width or the height is closer to it.
With this comparison a decision is made if it is vertical or horizontal.

Perhaps this will not work in all cases but in most.

Code: Select all

Zen.Application.MacroEditor.ClearMessages()

image = Zen.Application.ActiveDocument

print image.GraphicLayers.Count

for g in range(0,image.Graphics.Count):
    graphic = image.Graphics[g]

    mText = graphic.MeasurementText
    if (not mText is None):
        print '---------------'
        print graphic.Bounds.Width
        print graphic.Bounds.Height

        width = image.Scaling.X * graphic.Bounds.Width
        height = image.Scaling.Y * graphic.Bounds.Height
    
        print width
        print height

	# Remove and Convert chars depending on scaling and language
        mText = mText.Replace(',','.')
        mText = mText.Replace(' ','')
        mText = mText.Replace('µ','')
        mText = mText.Replace('m','')

        print mText
    
        length = float(mText)
    
        if abs(length - width) < abs(length - height):
            print "horizontal"
        else:
            print "vertical"
rosy dam
Posts: 6
Joined: Fri Aug 25, 2023 5:48 am
Contact:

Re: Orientation of interactive length measurements

Post by rosy dam »

It seems like you are trying to retrieve the orientation information from the bounding box of the graphics in the ZEN Core Length Tool, but it is always oriented horizontally. To accurately determine the orientation, you might need to explore other properties or methods within the ZEN Core Length Tool. One possible approach could involve analyzing the direction or angle of the measured line itself, rather than relying solely on the bounding box. Here's an example that you might find useful:

python
image = Zen.Application.ActiveWorkbench.GetDefaultInputValue()

for g in range(0, image.Graphics.Count):
gr = image.Graphics[g]

print("Graphic name = ", gr.Name)
print("Measurement Text = ", gr.MeasurementText)
print("Custom Text = ", gr.CustomText)

line_start_X = gr.StartPoint.X
line_start_Y = gr.StartPoint.Y
line_end_X = gr.EndPoint.X
line_end_Y = gr.EndPoint.Y

print("Start Point X = ", line_start_X, " Start Point Y = ", line_start_Y)
print("End Point X = ", line_end_X, " End Point Y = ", line_end_Y)

# Calculate the angle of the line
angle_rad = math.atan2(line_end_Y - line_start_Y, line_end_X - line_start_X)
angle_deg = math.degrees(angle_rad)

# Determine the orientation based on the angle
if 45 <= angle_deg < 135 or -135 <= angle_deg < -45:
print("Vertical Orientation")
elif -45 <= angle_deg < 45 or 135 <= angle_deg <= 180 or -180 <= angle_deg < -135:
print("Horizontal Orientation")
else:
print("Unknown Orientation")

print()
This script calculates the angle of the line between the start and end points of the measured length. Based on the calculated angle, it categorizes the orientation as either horizontal or vertical. Adjust the angle geometry dash ranges as necessary based on the specific requirements of your application.
Miranda Joye
Posts: 3
Joined: Thu Apr 06, 2023 4:41 am

Re: Orientation of interactive length measurements

Post by Miranda Joye »

Robert Nirnberger.2 wrote: Thu Sep 08, 2022 8:39 am Hallo,
i have to categorize interactive length measurements (ZEN Core Length Tool) whether orientation is horizontal , vertical.(exact)
I tried with orientation of bounding box, but that does not work, as the box is always oriented horizontal.
Need help with an ides or hint.
Thank you

image = Zen.Application.ActiveWorkbench.GetDefaultInputValue()

for g in range(0,image.Graphics.Count):
gr = image.Graphics[g]

print("Graphic name = ", gr.Name)
print("Measurement Text = ", gr.MeasurementText)
print("custom Text = ", gr.CustomText)

print("Angel", + gr.RotationAngle)

a,b,c,d = gr.GetBounds()
print("Bounds list " ,a,b,c,d)

b_bottomLeft_X = gr.Bounds.BottomLeft.X
b_bottomLeft_Y = gr.Bounds.BottomLeft.Y
b_bottomRight_X = gr.Bounds.BottomRight.X
b_bottomRight_y = gr.Bounds.BottomRight.Y

print("b_bottomLeft_X = ", b_bottomLeft_X, " b_bottomRight_X = " ,b_bottomRight_X)
print("b_bottomLeft_Y = " ,b_bottomLeft_Y, " b_bottomRight_y = ", b_bottomRight_y)
print()

b_topLeft_X = gr.Bounds.TopLeft.X
b_topLeft_Y = gr.Bounds.TopLeft.Y
b_topRight_X = gr.Bounds.TopRight.X
b_topRight_Y = gr.Bounds.TopRight.Y

print("b_topLeft_X = ", b_topLeft_X, " b_topRight_X = " ,b_topRight_X)
print("b_topLeft_Y = " ,b_topLeft_Y, " b_topRight_Y = ", b_topRight_Y)

kind regards

Robert


o
Have you received any suitable https://forums.zeiss.com/microscopy/community/posting.php?mode=quote&p=5221 suggestions for this problem?
Miranda Joye
Posts: 3
Joined: Thu Apr 06, 2023 4:41 am

Re: Orientation of interactive length measurements

Post by Miranda Joye »

The improvement of specific grain orientation and the refining of grain size with surface velocity during the melt spinning process have interactive and contradicting impacts on the magnetic characteristics.
Jesse Pinkman
Posts: 1
Joined: Wed Dec 06, 2023 5:21 am
Location: https://wordleunlimited.online/
Contact:

Re: Orientation of interactive length measurements

Post by Jesse Pinkman »

I suggest comparing the difference between the X and Y coordinates of the bounding box's top-left and bottom-right corners.
Post Reply