Revit Sample script does not work

I am trying the sample script “Calculate Total Length of Selected Lines” but it´s not working.

Error message “Dereferencing a non-pointer”.

Scripts that not need me to select objects in Revit works fine, but not the ones who needs selection.

Can you provide a screencast of how you’re using this? My guess is there is something in the selection which doesn’t have a length parameter.