6
$\begingroup$

Is there a way to delete all measurements with python?

If you have any measurements in your scene you can run this to get the lengths of them, but I don't know how to delete them.

import bpy

lengths = []
ruler_data = bpy.data.grease_pencils["Annotations"].layers['RulerData3D']
frame = ruler_data.frames[0]
for stroke in frame.strokes:
    p1, p2 = stroke.points[0], stroke.points[-1]
    length = (p1.co - p2.co).length
    lengths.append(length)

for i in lengths:
    print(i)
$\endgroup$

2 Answers 2

5
$\begingroup$
import bpy

# strokes = bpy.data.grease_pencils["Annotations"].layers['RulerData3D'].frames[0].strokes

def is_measure_tool_active():
    try:
        if 'builtin.measure' in bpy.context.workspace.tools: return True
        return False
    except: return False

def set_active_tool(tool_name):
    for area in bpy.context.screen.areas:
        if area.type == "VIEW_3D":
            override = bpy.context.copy()
            override["space_data"] = area.spaces[0]
            override["area"] = area
            bpy.ops.wm.tool_set_by_id(override, name=tool_name)
            break

def refresh():
    if is_measure_tool_active():
        set_active_tool("builtin.select_box")
        set_active_tool("builtin.measure")

def get_layers():
    try: return bpy.data.grease_pencils["Annotations"].layers
    except: return None

layers = get_layers()

if layers is not None and 'RulerData3D' in layers:
    layers.remove(layers['RulerData3D'])

    refresh()
$\endgroup$
-1
$\begingroup$

AI Icon Warning, Potential AI generated content⚠️

This post is suspected to have been generated with the help of an artificial intelligence, chat bot, or other language model tools without proper attribution.

There is reason to believe this post was not written by a human due to its structure, and grammatical construction, and has been marked by our community.
Current AI chat bots are a language models, that means they are like a parrot, they can mimic human language well, but they are built to write seemingly logical, seemingly factual grammatically valid text, rather than actually be correct, like a human would.
The veracity of the following content cannot be ascertained. See the Concerns regarding AI generated content.

Just a little update to this script so that it runs on Blender 3.6. Thank you ChatGPT 4:

import bpy

def is_measure_tool_active():
    try:
        if 'builtin.measure' in bpy.context.workspace.tools: return True
        return False
    except: return False

def set_active_tool(tool_name):
    for area in bpy.context.screen.areas:
        if area.type == "VIEW_3D":
            override = bpy.context.copy()
            override["space_data"] = area.spaces[0]
            override["area"] = area
            bpy.ops.wm.tool_set_by_id(override, name=tool_name)
            break

def refresh():
    if is_measure_tool_active():
        set_active_tool("builtin.select_box")
        set_active_tool("builtin.measure")

def get_grease_pencil():
    try: return bpy.data.grease_pencils["Annotations"]
    except: return None

grease_pencil = get_grease_pencil()

if grease_pencil is not None:
    for layer in grease_pencil.layers:
        grease_pencil.layers.remove(layer)

    refresh()
New contributor
user2141040 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
$\endgroup$
1
  • $\begingroup$ Why did you copy XY's script? His script already works on Blender 3.6 $\endgroup$ 16 hours ago

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .