dimensions of an imported body

Asked by Rioual

                                                                              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:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
Jan Stránský
Solved:
Last query:
Last reply:
Revision history for this message
Jan Stránský (honzik) said :
#1

Hello,

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

thanks
Jan

Revision history for this message
Rioual (francois-rioual-v) said :
#2

Hello Jan,

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

Thanks,

F.

Revision history for this message
Jan Stránský (honzik) said :
#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

Revision history for this message
Rioual (francois-rioual-v) said :
#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'

Thanks for your answer!

Best

V.

Revision history for this message
Best Jan Stránský (honzik) said :
#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

Revision history for this message
Rioual (francois-rioual-v) said :
#6

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