I’ve got a script here and i’m trying to get it to place the labels at the curve centroid. Right now it places it at the crvstart i think. How would I go about doing that?numberItemsText.rvb (5.3 KB)
Well, you have this:
Which does make the insertion point at the curve start. However if you want the curve area centroid, you are going to need to limit your curves to being closed and planar… not sure if you want that?
Oh, actually, before the dot is added, they change the insertion point to the midpoint… strange way to go about it.
hmmm, all the curves are planar and closed.i changed some lines in that section but it isn’t adding the text to the points, any idea? thank you.
' Process each item in the collection
For i = 0 To UBound(arrCollect)
' Get an item from the collection
arrItem = arrCollect(i)
' Rebuild the point array
arrPoint = Array(arrItem(0), arrItem(1), arrItem(2))
'Curves need to have the textdot at thier Midpoint
If Rhino.IsCurve(arrItem(3)) Then
'arrPoint = Rhino.CurveMidPoint(arrItem(3))
arrPoint = Rhino.CurveAreaCentroid(arrItem(3))
End If
' Add a text at the point location
strDot = Rhino.AddText(strName & CStr(intSuffix + i), arrPoint)
' Set the dot name to the originating object
'Rhino.ObjectName strDot, arrItem(3)
'Rhino.ObjectName arrItem(3), strName & CStr(intSuffix + i)
'Rhino.SetObjectData arrItem(3), "AutoCount", "DotUiid", strDot
Next
Rhino.CurveAreaCentroid returns an array of two items, the first item is the point and the second is the error bound:
So maybe you need
arrPoint = Rhino.CurveAreaCentroid(arrItem(3)(0))
my scripting kung fu is failing me. i’m getting a type mismatch.
Edit: @kleerkoat - made a slight mistake, corrected below (re-download the .rvb)
I put the following in the appropriate section. It takes care of both closed planar curves as well as non closed/planar and those where centroid fails.
' Process each item in the collection
For i = 0 To UBound(arrCollect)
' Get an item from the collection
arrItem = arrCollect(i)
' Rebuild the point array
arrPoint = Array(arrItem(0), arrItem(1), arrItem(2))
'Curves need to have the textdot at thier Midpoint
If Rhino.IsCurve(arrItem(3)) Then
If Rhino.IsCurveClosed(arrItem(3)) And Rhino.IsCurvePlanar(arrItem(3)) Then
arrCentroid = Rhino.CurveAreaCentroid(arrItem(3))
If IsArray(arrCentroid) Then
arrPoint = arrCentroid(0)
Else
arrPoint = Rhino.CurveMidPoint(arrItem(3))
End If
End If
End If
You also need to Dim arrCentroid somewhere above. Here’s the whole thing.
Autolabel-mod.rvb (5.5 KB)
O how I hate working in .rvb
awesome! thank you soooo much!