# dimensions of an imported body

Hello,

I would like to know how to get the dimensions of a body imported from a .stl file
(with ymport.stl) in a yade script.
Is it possible ?

Thanks,
Best regards,

F.

## Question information

Language:
English Edit question
Status:
Solved
For:
Assignee:
No assignee Edit question
Solved by:
Jan Stránský
Solved:
2020-01-22
Last query:
2020-01-22
2020-01-21
 Jan Stránský (honzik) said on 2020-01-16: #1

Hello,

please be more specific what "dimensions" mean:
- specific physical unit (meter, milimeter)?
- how "largel" the body is?
- ...

thanks
Jan

 Rioual (francois-rioual-v) said on 2020-01-16: #2

Hello Jan,

How long and large the body is in drawing units (or YADE units).

Thanks,

F.

 Jan Stránský (honzik) said on 2020-01-16: #3

imported body is a list of facets. You have access to its data, so you can do whatever you want. For example to get the min and max x coordinate:
###
minX = 1e99, maxX = -1e99
for facet in facets:
vs = [facet.state.pos + facet.state.ori * v for v in facet.shape.vertices] # vertices in global coord system
minX = min(minX,min(v[0] for v in vs))
maxX = max(maxX,max(v[0] for v in vs))
###

you can of course compute min and max y and z coordinates the same way or do more sophisticated analysis (smallest enclosing ellipsoid for instance).

cheers
Jan

 Rioual (francois-rioual-v) said on 2020-01-21: #4

Hello Jan,

I just did what you propose but I have an error message, possibly very basic mistake ??:

*******************************************************************************************************
fctIdscylinder=O.bodies.append(ymport.stl('Pot-FR-1.stl',color=(1,0,0),material=facetMat))
###
minX = 1e99
maxX = -1e99
minY = 1e99
maxY = -1e99
minZ = 1e99
maxZ = -1e99

for facet in fctIdscylinder:
print 'facet=', facet
vs = [facet.state.pos + facet.state.ori * v for v in facet.shape.vertices] # vertices in global coord system

minX = min(minX,min(v[0] for v in vs))
maxX = max(maxX,max(v[0] for v in vs)) ###

minY = min(minY,min(v[1] for v in vs))
maxY = max(maxY,max(v[1] for v in vs)) ###

minX = min(minZ,min(v[2] for v in vs))
maxX = max(maxZ,max(v[2] for v in vs)) ###

The error message is the following (facet is an integer!):

vs = [facet.state.pos + facet.state.ori * v for v in facet.shape.vertices] # vertices in global coord system
AttributeError: 'int' object has no attribute 'shape'

Best

V.

 Jan Stránský (honzik) said on 2020-01-21: #5

O.bodies.append returns list of ids (as suggested also by fctIdscylinder name). My solution assumes list of bodies.
Do
facet = O.bodies[facet]
as the first line of the for loop and it should work

cheers
Jan

 Rioual (francois-rioual-v) said on 2020-01-22: #6

Thanks Jan Stránský, that solved my question.