<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Betreff: Region Centroid in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/region-centroid/m-p/3194274#M58804</link>
    <description>&lt;P&gt;Thanks Alfred&lt;/P&gt;&lt;P&gt;Thats it!!!!!&lt;/P&gt;</description>
    <pubDate>Mon, 17 Oct 2011 17:26:29 GMT</pubDate>
    <dc:creator>leaveAlone</dc:creator>
    <dc:date>2011-10-17T17:26:29Z</dc:date>
    <item>
      <title>Region Centroid</title>
      <link>https://forums.autodesk.com/t5/net-forum/region-centroid/m-p/3193544#M58802</link>
      <description>&lt;P&gt;I need to find center of Region (refer to as Centroid in MassProperties of acad, also known as Centre of gravity if 'element' mass is unique).&lt;BR /&gt;After few days of googling, searchin i this forum... I still can not figure it out how to get centroid point from Region in VB.NET.&lt;BR /&gt;For Solid3D is easy while it exposes this property, but Region does not reveal any properties except Area.&lt;BR /&gt;&lt;BR /&gt;Has anybody manage to solve this and how?&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2011 06:13:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/region-centroid/m-p/3193544#M58802</guid>
      <dc:creator>leaveAlone</dc:creator>
      <dc:date>2011-10-17T06:13:33Z</dc:date>
    </item>
    <item>
      <title>Betreff: Region Centroid</title>
      <link>https://forums.autodesk.com/t5/net-forum/region-centroid/m-p/3193556#M58803</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;does that help? With the Interop/COM-functionality you should get the value in this way:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#666699" face="courier new,courier"&gt;'tRegion is the AutoCAD-Region object&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#666699" face="courier new,courier"&gt;Dim tCent() As Double = CType(CType(tRegion.AcadObject, _&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#666699" face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Autodesk.AutoCAD.Interop.Common.AcadRegion).Centroid, Double())&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- alfred -&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2011 06:36:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/region-centroid/m-p/3193556#M58803</guid>
      <dc:creator>Alfred.NESWADBA</dc:creator>
      <dc:date>2011-10-17T06:36:58Z</dc:date>
    </item>
    <item>
      <title>Betreff: Region Centroid</title>
      <link>https://forums.autodesk.com/t5/net-forum/region-centroid/m-p/3194274#M58804</link>
      <description>&lt;P&gt;Thanks Alfred&lt;/P&gt;&lt;P&gt;Thats it!!!!!&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2011 17:26:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/region-centroid/m-p/3194274#M58804</guid>
      <dc:creator>leaveAlone</dc:creator>
      <dc:date>2011-10-17T17:26:29Z</dc:date>
    </item>
    <item>
      <title>Betreff: Region Centroid</title>
      <link>https://forums.autodesk.com/t5/net-forum/region-centroid/m-p/5607772#M58805</link>
      <description>&lt;P&gt;Hi Alfred,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I cannot seem to access&amp;nbsp;&lt;SPAN&gt;Autodesk.AutoCAD.Interop.Common.AcadRegion via intellisense in Visual Studio.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Dim tCent() As Double = CType(CType(tRegion.AcadObject, _&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;CType isn't coming up in Intellisence either?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I must be doig something wrong?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Apr 2015 05:38:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/region-centroid/m-p/5607772#M58805</guid>
      <dc:creator>BKSpurgeon</dc:creator>
      <dc:date>2015-04-25T05:38:35Z</dc:date>
    </item>
    <item>
      <title>Betreff: Region Centroid</title>
      <link>https://forums.autodesk.com/t5/net-forum/region-centroid/m-p/5607779#M58806</link>
      <description>&lt;P&gt;HI folks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Worked out that Ctype doesn't work in C#.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And to get to the COM interop:&amp;nbsp;&lt;A href="http://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2015/ENU/AutoCAD-NET/files/GUID-BFFF308E-CC10-4C56-A81E-C15FB300EB70-htm.html" target="_blank"&gt;http://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2015/ENU/AutoCAD-NET/files/GUID-BFFF308E-CC10-4C56-A81E-C15FB300EB70-htm.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but is there a way to access the centroid properties without resorting to COM/interop and using simply native .NET?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Apr 2015 06:02:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/region-centroid/m-p/5607779#M58806</guid>
      <dc:creator>BKSpurgeon</dc:creator>
      <dc:date>2015-04-25T06:02:17Z</dc:date>
    </item>
    <item>
      <title>Betreff: Region Centroid</title>
      <link>https://forums.autodesk.com/t5/net-forum/region-centroid/m-p/5607923#M58807</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;BKSpurgeon a écrit&amp;nbsp;:&lt;/BLOCKQUOTE&gt;
&lt;BLOCKQUOTE&gt;but is there a way to access the centroid properties without resorting to COM/interop and using simply native .NET?
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You can use COM whitout adding references to the COM libraries by using &lt;A href="http://en.wikipedia.org/wiki/Late_binding" target="_blank"&gt;late binding&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you're using C# and targeting Framework 4.0 or higher (the Frameork 4.0 is installed with AutoCAD 2012), you can use the &lt;STRONG&gt;dynamic&lt;/STRONG&gt; type which allows to write a code very similar to the one using early binding:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;dynamic acadRegion = region.AcadObject;
double[] centroid = acadRegion.Centroid;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For prior Frameworks, you can use late binding with Reflection:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;object acadRegion = region.AcadObject;
double[] centroid = (double[])acadRegion.GetType().InvokeMember(
    "Centroid", System.Reflection.BindingFlags.GetProperty, null, acadRegion, null);&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With VB, I'm not certain but it seems to me that the late binding is implicit with the Object type while Option Strict is Off, so you should simply write (not tested):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Dim acadRegion As Object = region.AcadObject
Dim centroid() As Double = acadRegion.Centroid&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you really do not want to use COM.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since AutoCAD 2014 the Region class offers a new method: AreaProperties() which returns a RegionAreaProperty object which has a Centroid property.&lt;/P&gt;
&lt;P&gt;An example to get the centroid of a region lying on the WCS XY plane:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Point3d origin = Point3d.Origin;
Vector3d xAxis = Vector3d.XAxis;
Vector3d yAxis = Vector3d.YAxis;
Point2d centroid = region.AreaProperties(ref origin, ref xAxis, ref yAxis).Centroid;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For prior versions of AutoCAD, you can create a Solid3d by extruding the region, get the solid centroid and move it back to the region plane:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Point3d centroid;
using (Solid3d solid = new Solid3d())
{
    solid.Extrude(region, 2.0, 0.0);
    Point3d solidCentroid = solid.MassProperties.Centroid;
    centroid = solidCentroid.TransformBy(Matrix3d.Displacement(region.Normal.Negate()));
}&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Apr 2015 10:35:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/region-centroid/m-p/5607923#M58807</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2015-04-25T10:35:47Z</dc:date>
    </item>
    <item>
      <title>Betreff: Region Centroid</title>
      <link>https://forums.autodesk.com/t5/net-forum/region-centroid/m-p/5620751#M58808</link>
      <description>&lt;P&gt;Thank you sir this has been inordinately helpful. I appreciate it very much, and so will future readers, I am sure.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;BK&lt;/P&gt;</description>
      <pubDate>Tue, 05 May 2015 02:14:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/region-centroid/m-p/5620751#M58808</guid>
      <dc:creator>BKSpurgeon</dc:creator>
      <dc:date>2015-05-05T02:14:13Z</dc:date>
    </item>
  </channel>
</rss>

