I tried ExportPoints.py and received this message after supplying a file name:
"---------------------------
Exception Occured ‘file’ object has no attribute ‘writeline’ ExportPoints.py
Message: ‘file’ object has no attribute ‘writeline’
Traceback:
line 23, in ExportPoints, “C:\Users\User\AppData\Roaming\McNeel\Rhinoceros\5.0\scripts\samples\ExportPoints.py”
line 32, in , “C:\Users\User\AppData\Roaming\McNeel\Rhinoceros\5.0\scripts\samples\ExportPoints.py”
OK
"
It’s the first time I’ve tried running the script since installing Rhino in September, 2015 so it might need to be updated.
I appreciate the help, and now I have another question.
I had selected 20 points and saved the txt files successfully for both write() and writelines(), respectively
I am wanting to extract the x-coordinates of each point by importing the file in MS Excel. When I did that, I got 41 values. I was expecting 120; x,y,z,r,g,b.
What am I missing? Where can I find an explanation of the structure of the point data so that I can understand better how to extract the x-coordinates?
Please see the txt and zip files, attached.
Is there a better(easier) way to do this?
TIA ~ David
What rgb values are you trying to read? The objects color? If so, you need to use RS.ObjectColor(object) to get the specific color and add it to your txt file. The point itself only stores the x,y,z values. Thats part of the whole geometry/object magic in rhino, where geometry is part of an object that saves stuff such as names, colors, layers etc.
Actually, I only want the x-coordinate values. I had planned on extracting the x-coords from the x,y,z data. My confusion comes from the fact that 41 values were exported from 20 points selected. Shouldn’t it have been 60, one value each for the x, the y, and the z of 20 points?
Here’s a transposed (vertical column) version of the Excel file.
You are missing the line breaks. I assume each point was supposed to be on a separate line, but instead you write the entire chunk on one. For example, you have the “number” 1.82513.9749224841188 which has 2 points in it. No valid number can have that. You can add a line break by adding +'\n' to each line (click here for more information).
Also its good practice to use a context manager when writing to files - this reduces the risk of the file being corrupted and unusable if something unexpected happens during your loop:
with open(filename, "w") as file:
for id in objectIds:
#process point clouds
...
This way you don’t need file.close() as the file is automatically closed at the end of the with block or when an exception occurs.