dimensions are great, but sometimes a quick distance annotation is all one needs. I tried to use rhinoscript to make the following:
Pick point A,
pick point B,
draw line AB
apply arrowheads
place a textdot in the middle with the distance between points
somehow my script didn’t work - has someone an idea how to achieve this?
thanks
Pick point A,
pick point B,
draw line AB
calc distance
calc mid-point
apply arrowheads
place a textdot in the middle with the distance between points
! _NoEcho _-Runscript (
Option Explicit
Call Distbetween()
Sub Distbetween()
Dim pt,pt2,dist,units,prec,msg
pt = Rhino.GetPoint("Pick point on object")
If Not IsArray(pt) Then Exit Sub
pt2 = Rhino.GetPoint("Pick point on object")
If Not IsArray(pt) Then Exit Sub
dist = Rhino.Distance(pt,pt2)
Rhino.AddLine pt, pt2
units = Rhino.UnitSystemName(,, True)
prec = Rhino.UnitDistanceDisplayPrecision()
msg = "Distance between points is "
Rhino.TextDotPoint Round(dist, prec), Rhino.PointDivide (Rhino.PointAdd(pt, pt2), 2)
Call Rhino.Print(msg & Cstr(Round(dist, prec)) & " " & units)
End Sub
)
Funny thing about this RadialDimension example was that you copy paste it directly. Run it it asks you to select a curve. You comply, and then it throws an error.
How reliable should the examples in the API be?
Well have you tried Python instead of VB. Much easier to comprehend. Not my expression, many people on the internet say Python is the English of the programming languages.
Although, this is a bad python example:
from Rhino import *
from Rhino.DocObjects import *
from Rhino.Commands import *
from Rhino.Geometry import *
from Rhino.Input import *
from scriptcontext import doc
Call Distbetween()
Sub Distbetween()
Dim pt,pt2,dist,units,prec,msg
pt = Rhino.GetPoint(“Pick point on object”)
If Not IsArray(pt) Then Exit Sub
pt2 = Rhino.GetPoint(“Pick point on object”)
If Not IsArray(pt) Then Exit Sub
dist = Rhino.Distance(pt,pt2)
Rhino.AddLine pt, pt2
units = Rhino.UnitSystemName(, True)
prec = Rhino.UnitDistanceDisplayPrecision()
msg = "Distance between points is "
Rhino.AddTextDot Cstr(Round(dist, prec)), Rhino.PointDivide (Rhino.PointAdd(pt, pt2), 2)
Call Rhino.Print(msg & Cstr(Round(dist, prec)) & " " & units)
End Sub
)
Call Distbetween()
Sub Distbetween()
Dim pt,pt2,dist,units,prec,msg, arrLine
pt = Rhino.GetPoint("Pick point On object")
If Not IsArray(pt) Then Exit Sub
pt2 = Rhino.GetPoint("Pick point On object")
If Not IsArray(pt) Then Exit Sub
dist = Rhino.Distance(pt, pt2)
arrLine = Rhino.AddLine(pt, pt2)
Call Rhino.CurveArrows(arrLine, 3)
units = Rhino.UnitSystemName(, True)
prec = Rhino.UnitDistanceDisplayPrecision()
msg = "Distance between points is "
Rhino.AddTextDot Cstr(Round(dist, prec)), Rhino.PointDivide(Rhino.PointAdd(pt, pt2), 2)
Call Rhino.Print(msg & Cstr(Round(dist, prec)) & " " & units)
End Sub
Hi @Konrad, you might also take care if the picked points are far enough from eachother so a line can be added, otherwise you’ll get an error eg. if both points are identical.
Option Explicit
Call Main()
Sub Main()
Dim arrPt0, arrPt1, dblTolerance, dblDistance, strLine, arrMidPt
arrPt0 = Rhino.GetPoint("First point")
If IsNull(arrPt0) Then Exit Sub
arrPt1 = Rhino.GetPoint("Second point")
If IsNull(arrPt1) Then Exit Sub
' exit if the distance is to small to add a line
dblDistance = Rhino.Distance(arrPt0, arrPt1)
dblTolerance = Rhino.UnitAbsoluteTolerance()
If dblDistance < dblTolerance Then Exit Sub
' create line with arrowheads
strLine = Rhino.AddLine(arrPt0, arrPt1)
If IsNull(strLine) Then Exit Sub
Call Rhino.CurveArrows(strLine, 3)
' add annotation dot to line mid point
arrMidPt = Rhino.PointDivide(Rhino.PointAdd(arrPt0, arrPt1), 2.0)
Call Rhino.AddTextDot(Round(dblDistance, 3), arrMidPt)
End Sub
just to share the script with everyone:
I’ve changed the input method to getLine for more feedback and grouped the output
use at your own risk
! _NoEcho _-Runscript (
Call Distbetween()
Sub Distbetween()
Dim arrPt0, arrPt1, dblTolerance, dblDistance, strLine, arrMidPt, strDot, strGroup, strLineArr
' create line with arrowheads
strLineArr = Rhino.GetLine
If IsNull(strLineArr) Then Exit Sub
If IsNull(strLineArr(0)) Then Exit Sub
If IsNull( strLineArr(1)) Then Exit Sub
strLine = Rhino.AddLine( strLineArr(0), strLineArr(1))
If IsNull(strLine) Then Exit Sub
' exit if the distance is to small to add a line
dblDistance = Rhino.Distance(strLineArr(0), strLineArr(1))
dblTolerance = Rhino.UnitAbsoluteTolerance()
If dblDistance < dblTolerance Then Exit Sub
Call Rhino.CurveArrows(strLine, 3)
' add annotation dot to line mid point
arrMidPt = Rhino.PointDivide(Rhino.PointAdd(strLineArr(0), strLineArr(1)), 2.0)
strDot = Rhino.AddTextDot(Round(dblDistance, 3), arrMidPt)
Call Rhino.ObjectColor(strDot, vbWhite)
strGroup = Rhino.AddGroup()
Call Rhino.AddObjectToGroup( strDot, strGroup)
Call Rhino.AddObjectToGroup( strLine, strGroup)
End Sub
)