Newby scripting problem... probably obvious


#1

I am getting a type mismatch on the strPt line.

Sub Main()

Dim ObjectforCG: ObjectforCG = Rhino.GetObject("Pick", 8 + 16, True, True)

Dim areaCentroid: areaCentroid = Rhino.SurfaceAreaCentroid(ObjectforCG)

Dim date: date = Rhino.DocumentInfo

Dim strPt: strPt = areaCentroid(0) & vbTab & areaCentroid(1) & vbTab & areaCentroid(2) & vbTab & date(6)

Rhino.ClipboardText(strPt)

End Sub


#2

Hi Ryan,

SurfaceAreaCentroid returns an array, where the first value is the point.
So you would need to do:
areaCentroid = Rhino.SurfaceAreaCentroid(ObjectforCG)(0)
or if not above, then use:
areaCentroid(0)(0).areaCentroid(0)(1),areaCentroid(0)(2) for your point coordinates.

hth

–jarek


#3

OK got it. thanks @Jarek


#4

So if I wanted to select multiple surfaces and get the area centroid of all of them…

would do a for each surface in group of surfaces and then add the values up and divide by the # of items, correct?

Is there an easy way to count how many surfaces are grabbed in the Get.Objects? Or would it be better to just have a counter and increment it each time the loop runs.


#5

You can use Ubound(arrResult) - it will give you the number of items in the array -1 (arrays are 0-based).
For multiple surfaces you need to iterate thru all of them, I don’t think you can get an average centroid for bunch of them at once…

-j