How to get the centroid of a wall?

How to get the centroid of a wall?

Anonymous
Not applicable
2,018 Views
3 Replies
Message 1 of 4

How to get the centroid of a wall?

Anonymous
Not applicable

Can somebody help me with this?

 

the workflow is ..

 

1. pick a wall - done

2. get the centroid of a wall

3. create point to the centroid of the wall

0 Likes
2,019 Views
3 Replies
Replies (3)
Message 2 of 4

matthew_taylor
Advisor
Advisor

This may help:

http://thebuildingcoder.typepad.com/blog/2015/06/dynamo-centroid-volume-calculation-migration-blitz....

(It's not a Dynamo macro!)


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
0 Likes
Message 3 of 4

Anonymous
Not applicable

Hello napa2017

 

I think the centeriod of a wall is the (BottomFace.origin+TopFace.origin)/2.

 

Sure,the wall must be regular.

 

Hope is good for you


XYZ GetCenteriod(Solid solid) { XYZ BottomOrigin = null; XYZ TopOrigin = null; XYZ CenteriodPoint = null; string Message = null; PlanarFace pf = null; foreach (Face face in solid.Faces) { pf = face as PlanarFace; if (null != pf) { if (Math.Abs(pf.FaceNormal.X) < 0.01 && Math.Abs(pf.FaceNormal.Y) < 0.01 && pf.FaceNormal.Z < 0)//Face.FaceNormal Judge TopFace or BottomFace { BottomOrigin = pf.Origin; Message += BottomOrigin.ToString()+"BottomFace \n"; continue; } if (Math.Abs(pf.FaceNormal.X) < 0.01 && Math.Abs(pf.FaceNormal.Y) < 0.01 && pf.FaceNormal.Z > 0)//Face.FaceNormal Judge TopFace or BottomFace { TopOrigin = pf.Origin; Message += TopOrigin.ToString() + "TopFace \n"; continue; } } } CenteriodPoint = (TopOrigin + BottomOrigin) / 2; Message += CenterPoint.ToString()+"Centeriod \n"; TaskDialog.Show("CenteriodPoint", Message); return CenteriodPoint; }

 

 

0 Likes
Message 4 of 4

FAIR59
Advisor
Advisor

the Solid class has a method ComputeCentroid().

So from the wall Geometry you can get the Centroid

 

 


Options opt = new Options(); opt.DetailLevel = ViewDetailLevel.Coarse; Solid wallSolid = null; foreach (GeometryObject obj in wall.get_Geometry(opt)) { Solid s = obj as Solid; if (s!= null) { wallSolid = s; break; } } if (wallSolid!=null) { XYZ centre = wallSolid.ComputeCentroid(); }