Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 5938

Creating a custom command with python SelDimLess

$
0
0

Hi,

I am new to Python. I am trying to see if I can come up with a script for a command that selects any Dimensions that are less than a certain value (layout unit). I am not sure what went wrong here posting here to see if there is anyone who can help.

Thanks in advance.

import rhinoscriptsyntax as rs

def select_dimensions_less_than(length_threshold):
    # Get all dimension objects in the document
    dimensions = rs.ObjectsByType(rs.filter.Annotation)
    
    if not dimensions:
        print("No dimensions found in the document.")
        return
    
    # Select dimensions with length less than the threshold
    selected_dimensions = []
    for dim_id in dimensions:
        length = rs.DimensionValue(dim_id)
        if length < length_threshold:
            selected_dimensions.append(dim_id)
    
    # Select the dimensions in Rhino
    if selected_dimensions:
        rs.SelectObjects(selected_dimensions)
        print("Selected dimensions with length less than", length_threshold)
    else:
        print("No dimensions found with length less than", length_threshold)

def Command_SelectDimensionsLessThan():
    # Get user input for the threshold value
    length_threshold = rs.GetReal("Enter the threshold length:", 10)
    if length_threshold is None:
        print("Invalid threshold value.")
        return
    
    # Call the function to select dimensions
    select_dimensions_less_than(length_threshold)

# Register the command
if __name__ == "__main__":
    Command_SelectDimensionsLessThan()

Thank you

3 posts - 3 participants

Read full topic


Viewing all articles
Browse latest Browse all 5938

Trending Articles