Thornely made 261 not out, clouting 11 sixes, and joined former Test leg-spinner Stuart MacGill in a 10th wicket partnership of 219 that helped NSW to 419 on the second day of their match on Wednesday.
In reply WA were bowled out for 137 and were 23 without loss following on, still trailing by 259 runs with two days to play.
Thornely broke the record held by the late David Hookes for the most sixes in a first-class innings in Australia, Hookes having hit 10 for South Australia against NSW at Adelaide in 1985-86.
Queenslander Andrew Symonds holds the world record for the most sixes in a first-class innings, smashing 16 for Gloucestershire against Glamorgan in 1995.
After Thornely's heroics with the bat, the NSW pace trio of Stuart Clark (4-24), Matthew Nicholson (3-18), and Nathan Bracken (1-22) cleaned up the visitors.
Murray Goodwin was the only WA player to offer any resistance, batting for 215 minutes for 55 before he was bamboozled by a legspinner from MacGill and was stumped by Brad Haddin.
MacGill, pushing for a possible Test call-up following Shane Warne's broken thumb in India, bowled superbly and finished with 2-20 off 10 overs.
At Sydney (day two): New South Wales 419 (D. Thornely 261 not out, B. Haddin 45; B. Casson 3-88) v Western Australia 137 (M. Goodwin 55, R. Campbell 28; S. Clark 4-24, M. Nicholson 3-18) and 23 without loss.