If you wanted to give your encoder a name you would do it in the “I2C Sensors” tab of the motors & sensors dialog, however, you are correct in your approach to read the encoder value. To access encoder values using nMotorEncoder] you use the motor port or name as the index, for example, lets say you have an IME on the motor on port2. To retrieve the encoder value use;
long value;
value = nMotorEncoder port2 ];