How to read the coordinates of the specified atom in Materials Studio?

Dear Materials Studio Users,

I want to read the coordinates of two atoms named "R1" and "R2" to calculate the angle with the axis, part of the perl script is as follows:

my \$atoms = \$Documents{"polymer.xsd"}->AsymmetricUnit->Atoms;

foreach my \$atom (@\$atoms) {
 
  my \$atom1 = \$atom->Name = ("R1");
  my \$atom2 = \$atom->Name = ("R2");
 
my \$anglevalue = CalcAngle(\$atom1->XYZ, \$atom2->XYZ);
\$angle = \$anglevalue;
 
write;
}

However, I get the error information that "Can't locate object method "XYZ" via package "R1" (perhaps you forgot to load "R1"?) at -e line 68." How to fix this problem?

Thank you.