Sun, 08/18/2024 - 20:19
Forums:
Hello,
I am putting together a collection of common things you might want to do in a CAD application and making some proc to handle these tasks.
The extract_normals proc make a normal vector from a planar face.
the extrude proc builds a prism that is normal to the face.
proc extract_normals {faceName distance} {
# Run the normals command with -print option and capture the output
set output [catch {uplevel #0 normals $faceName $distance -print} result]
# Check if the command was successful
if {$output != 0} {
return -code error "Error executing normals command: $result"
}
# Define a regular expression to match the numerical vector
set regex {\(-?\d+,\s*-?\d+,\s*-?\d+\)}
# Initialize a list to hold the numerical values
set numerical_values {}
# Search for the pattern in the output
if {[regexp $regex $result match]} {
# Remove the parentheses and split the numbers into a list
set numerical_values [split [string trim $match "()"] ,]
} else {
return -code error "No numerical vector found in the output."
}
# Return the numerical values as the result of the proc
return $numerical_values
}
proc extrude {newBodyName faceToExtrude distance} {
# Extract the normal vector from the face using the extract_normals proc
set normalVector [extract_normals $faceToExtrude $distance]
# Check if the normalVector was successfully extracted
if {[llength $normalVector] != 3} {
return -code error "Failed to extract normal vector for extrusion."
}
# Decompose the normal vector into its components
set nx [lindex $normalVector 0]
set ny [lindex $normalVector 1]
set nz [lindex $normalVector 2]
# Use the prism command to perform the extrusion
uplevel #0 prism $newBodyName $faceToExtrude $nx $ny $nz
}
# Example usage:
# extrude newBodyName faceToExtrudeName 10
I would also like to ask if there is any existing libraries of DRAW tcl functions for handling these kinds of tasks. Is there any places that have large collections of DRAW tcl code outside of the test cases published as part of the OpenCASCADE source?