# The concept for reading XYZ coordinates from a TXT and place model from clipboard

Dear friends,
Congratulations for your interesting work in this forum.
I use sketchup for simple models and renders with no experience in ruby scripts etc. I am interested in a particular case, which I want to doublecheck with you guys here that it can be done in SketchUp Ruby or SDK APIs before I start working on it.
There is a list of coordinates (X,Y,Z) in a txt. In each X,Y,Z, I want to place the model of a soldier and rotate it according to an angle theta which is also in the txt. So I must write a script whereby (1) I read the txt, (2) copy the soldier (it is already designed in the model) and place it in each XYZ and (3) rotate the soldier. [The soldier reference is only for illustration; it could be any model].
My question is if the above concept can be done. Any tips as to where I should start from are welcome.
Many thanks.
Chris

Yes it can be done. The soldier should be a Component. You place a ComponentInstance at each location and orientation using a Transformation constructed from the position and orientation.

You should study basic Ruby programming first and then the SketchUp Ruby API. Come back here with specific questions when you run into problems.

1 Like

Start in the pinned thread I made in the Ruby APIs category:

1 Like

Load a SKP file [‘soldier’] as a component - get a reference to it.
Choose and then read the txt file which has lines of
X,Y,Z,A
Start an operation…
Iterate the array of read-in lines.
Split the line at ‘,’ - strip any \n etc
Assuming the XYZ are in inches you need to convert each ‘string’ to a ‘float’.
If in other units you need to convert that into inches.
Make a point3d using XYZ and use it in a transformation [tp]
Make a rotation transformation based on the point, Z-axis and a rotation angle [assuming A is in degrees and again converted from a string to a float] - [tr]
Make a combined transformation t=tr*tp
Add an instance of ‘soldier’ to the model.entities, using ‘t’…
Commit the operation.

Now you should have a set of soldiers all placed at the various XYZ, each rotated by A

2 Likes

Thank you TiG. Your directions are very clear. I was expecting such steps.