Rhino Script

I wanna pick two points and finaly must be like the picture

  1. draw 3d line
  2. Arrow head(line transform to arrow line)
  3. Meausere length
  4. M. Length value write with Dot to midpoint of the line

please help me

1 Like

hi Hakan,

here is a sample RhinoScript to do it:

    Option Explicit
    Call Main()
    Sub Main()
       
    	Dim arrP : arrP = Rhino.GetPoints(True,,,, 2)
    	If isnull(arrP) Then Exit Sub
    	If Ubound(arrP) <> 1 Then Exit Sub

    	Dim idL : idL = Rhino.AddLine(arrP(0), arrP(1))
    	Call Rhino.CurveArrows(idL, 3)

    	Dim idDot : idDot = Rhino.AddTextDot(Round(Rhino.CurveLength(idL), 2), Rhino.CurveMidPoint(idL))

    	Call Rhino.SelectObjects(array(idL, idDot))
    	
    End Sub

–jarek

2 Likes

thank you so much Jarek,
How can I use it ? how it working ? Sorry I dont now.

hi Hakan,

You can save the script file: DotArrow.rvb (515 Bytes)
anywhere on your HD and just drag-and-drop into Rhino viewport to run it.

It can also be placed on a button or added as Alias / command (let me know if you need help with that).
Another option is to open RhinoScript editor and paste the above code there (_EditScript command), and run the script from there.

It’s a simple one so maybe by looking at the code you can figure out what each steps does, and modify the script as needed (like number of digits for rounding the number - currently: 2).

cheers,

–jarek

2 Likes

yeeeeeeeees. this is it !.thanks so much.
Can I make Button.

sure, assume you know how to make/edit a new button (if not, take a look here: http://docs.mcneel.com/rhino/5/help/en-us/index.htm#toolbarsandmenus/toolbar_button_editor.htm#OpenButtonEditor)

In one of the Edit Button Command fields (left or right), paste this:
(it’s basically the script, but framed by _-Runscript ( … ) statement. That’s in general how you put scripts on buttons.

    _-Runscript (

    Option Explicit
        Call Main()
        Sub Main()
           
        	Dim arrP : arrP = Rhino.GetPoints(True,,,, 2)
        	If isnull(arrP) Then Exit Sub
        	If Ubound(arrP) <> 1 Then Exit Sub

        	Dim idL : idL = Rhino.AddLine(arrP(0), arrP(1))
        	Call Rhino.CurveArrows(idL, 3)

        	Dim idDot : idDot = Rhino.AddTextDot(Round(Rhino.CurveLength(idL), 2), Rhino.CurveMidPoint(idL))

        	Call Rhino.SelectObjects(array(idL, idDot))
        	
        End Sub

    )
2 Likes

I wouldn’t have done it without you. You are a great man.

excuse me, why did you write “Call” before a command, does it works without?

1 Like

– Dale

1 Like

It’s a personal preference. Can be done both ways:

Call Rhino.CurveArrows(idL, 3)

or

Rhino.CurveArrows idL, 3

I prefer using Call as it is visually cleaner for me to have the arguments in parenthesis.

1 Like

This sicript very usefull for me. Bur script not work. :disappointed:
Please help me !

This script very usefulla for me. But it not works and show me two wrong message.
Please help me?


Hi Hakan,

Looks like your RhinoScript plugin got damaged (that’s Rhino plugin that allows any RhinoScript to run). Unfortunately that has been happening and I see still happening recently especially when Rhino 7 is installed. What version of Rhino are you having this error with?
What should fix it is repairing Rhino install from the Windows Apps and Features. After running Repair, make sure RhinoScript plugin is loaded from Toos > Options > Plugins > RhinoScript.rhp.
That should fix it.

–jarek

2 Likes

I LOVE THIS MACRO.
But I will have a request. Ineed a macro. like the Macro here.

Measure the polycurve by Length Command
Make arrow to the ends of the polycurve
Make dot in the mid point of the polycurve
Write the length of the plycurve in the dot.

please help me

I use rhino 7. I have no problem

Hi Hakan,

Here is the script that should do it (works with multiple curves at once. If you need to change the rounding method it is commented there, I made “2” as default.
Also, if you need this on a button, you may need to add: -_RunScript ( … ) lines as the other one does.

Call Main()
Sub Main()

	'change this for different rounding 
	Dim intRound:  intRound = 2
	
	Dim arrC : arrC = Rhino.GetObjects("Curves?", 4,, True)
	If isnull(arrC) Then Exit Sub
	
	Dim i
	Rhino.EnableRedraw False
	For i=0 To Ubound(arrC)
		Call Rhino.AddTextDot(Round(Rhino.CurveLength(arrC(i)), intRound), Rhino.CurveMidPoint(arrC(i)))
		Call Rhino.CurveArrows(arrC(i), 3)
	Next
	Rhino.EnableRedraw True
	
End Sub

hth,

–jarek

1 Like

:+1: :+1: :+1: :heart: :heart: :heart:
Thank you so much. You are a very wonderful person.
These kinds of solutions work very well for me.
How can I learn. Where should I start?

hi Hakan,

Long time ago I learned scripting from this great primer:
RhinoScript 101 [McNeel Wiki]
It took a little initial effort since I did not have any coding background, but it was a time well invested.

These days most people would probably advise you to learn Python instead of RhinoScript to do scripting in Rhino - in a long run it is much more powerful, but on a basic level they both work well:
Rhino.Python 101 with unset (rhino3d.com)

All developer resources are here, for both basic scripting and advanced programming:
Rhino and Grasshopper Developer Documentation (rhino3d.com)

I would say pick a language (RhinoScript vs Python) and start with reading the 101 Primer with some basic exercises.

cheers,

–jarek

2 Likes

Thank you so much.
I will do this

1 Like

Dear Jarek and everyone, !
I hope you see my message. This scrip wonderfull .
Again, we owe you a big thank you.
Dear Jarek and everyone !
I want to add my section command in front of this script.
So when you make a section, it will do what this script does.
I would be very happy if someone could do this.