-- get a valid pattern index
local index = renoise.song().selected_pattern_index
-- get pattern length
local num_lines = renoise.song().patterns[index].number_of_lines
-- process num_lines in some way
-- set to a random number of lines from 1 to 512
num_lines = 1 + math.floor(math.random() * 511)
-- set pattern length
renoise.song().patterns[index].number_of_lines = num_lines
Yep. PatternTrack refers to a single track within a pattern. If you want to access automations or note data, then you can find these within the PatternTrack object.
If you want to access properties of the entire pattern, such as the number of lines, pattern name, the track objects within the pattern, etc., then you can find these within the Pattern object.
You can use the oprint() function to inspect each object and find out what properties and methods it has.