Hello and welcome,
when creating a new post, please use tags and the Q&A system. See Read Before Posting.
I tried your code in a R20 script and it seems to work perfectly fine:
rd = doc.GetActiveRenderData()
if rd is None:
return
fromSlice = rd[c4d.RDATA_FRAMEFROM]
toSlice = rd[c4d.RDATA_FRAMETO]
fps = doc.GetFps()
print(fromSlice.GetFrame(fps))
print(toSlice.GetFrame(fps)
What exactly is not working for you? In what context do you execute your code?
best wishes,
Sebastian