[Help] How to draw line segments while picking the points

Well, as I said, if you just want to see the polyline drawn while picking points -

import rhinoscriptsyntax as rs
def MakePolyline():
    msg1="Pick first point"
    msg2="Pick next point or press Enter to end"
    if pts and len(pts)>1: rs.AddPolyline(pts)

Thanks Mitch,

That does exactly what the title of this topic states.
I have some issues putting this inside command_with_options, but I’ll create another thread for that, to keep this one relatively clean.

Hehe … yes, we can do strange things with scripts. :slight_smile:

If you like thinking to different ways to draw the polyline …
… I think another way would be drawing one line at a time while you pick the points and then joining the lines at the end running the _Join command by RhinoApp.RunScript()


Possibly pre-selecting the lines to be joined by one of the ObjectTable.Select() methods,
for example:


Hi @ivelin.peychev

If you want to become a better programmer, a right step would be to start reading more programming books. If you want to know more about IronPython, get a book on it.

This Ironpython in action would be a good start.

For beginning programmers, RhinoScript is actually excellent. You seem never to have questions regarding how that one works. Problems start with more Object-Oriented programming (OOP) concepts, that require some training.

Also, if you want to do more development in RhinoCommon, a C# book will help.



Giulio Piacentino
for Robert McNeel & Associates

1 Like

I’ve done automation on a couple of different CAD Platforms.
Rhino offers by far the best documented,easiest and best structured API around.
Especially compared to Catia’s Com-Interface, where often you need to apply Winapi hacking to get things working.
For Beginners, Rhino is definitely one of the most simpler ones, in my opinion.

However, most confusion comes when directly calling Rhinocommon using IronPython, because you call a C# wrapper library around a C++ library, with different programming philosophies behind. I would always recommend, learning some basic C# or even C++, to fully understand how Rhinocommon is structured. This helps with (Iron-)Python as well. It requires some learning, but if you know Python and C Style languages you can almost read all applied languages of today. So its definitely no waste of time.

@ivelin.peychev, you might take a look into the script i posted here.


Thanks Emilio, this looks promising, I’m gonna try it out.

Yes I already have this book on my ToDo list. Problem is I do all this in my spare time. Reading and trying to complete my ideas with Rhino (+/-) GH.

That’s because I try to stay clear of VB-derivated scripting languages. At work I work with a scripting language which is mixture of Java/VB/and who knows what else. I know a bit Python and very basic C#. I don’t want to mess-up my head completely.

Yes, I have that in mind, but I haven’t worked with VisualStudio and C# for a few years, I have to remember how it all works again, assemblies, GUI-designer, classes, global/static stuff…etc. Also, I have to work with .net apis which don’t have enough comments to be easily understand by a beginner. I better try first to implement my ideas with scripting, then I’ll try compiling or translating to C#. I have enough books, just not the time to read them all. Learning by example is always the quick and dirty solution if you wanna get the result. I’m not trying to become a programmer after all.

Yes, :slight_smile: I know what you mean. DS didn’t know what they are doing back then, but using WinApi you could make pretty decent automations with Python in Catiav5, now with v6 they really screw it up. They created a scripting language (which is licensed) and then created another scripting language called from the 1st one (which is free to all customers). I like all the possibilities of Rhino emerging from McNeel decision to give access to all APIs. It’s great, unfortunately for a beginner like me it’s like a labyrinth, with signs on the walls written in babylonian :smiley:

Basic C# sure, but C++ no way. I have to quit my engineering/consulting job and devote my full-time on programming in order to learn all different syntax of Python3, IronPython, C#, C++, RhinoScript, VB, and not having them messed up in my head. I started learning C++ some 20 years ago, and created a few simple console apps. That helped me read pretty much all languages, but writing code from highly cusomized api is something different. I need more examples and comments. I saw on this forum a code it looked like it was binding Rhino Method to GH method. I could not follow the code after this because I lost the logic.

mene mene tekel upharsin.

// Rolf

“Sign on the wall” and with red what’s expected:

In babylonian lingo:

List<Point3d> ListOfPoints = new List<Point3d>();

ListOfPoints.Add(new Point3d(0.0, 1.1, 2.2);
ListOfPoints.Add(new Point3d(...);
ListOfPoints.Add(new Point3d(...);

var pline = new Polyline(ListOfPoints); 

That should do. An Enumerable is a List or Array.

In Python a “[]” should do(?).

// Rolf

I actually meant IronPython-based RhinoScript (rhinoscriptsyntax). VbScript-based RhinoScript is really really old IMO, too. You may enjoy the video on the frontpage of http://developer.rhino3d.com.

We do not have the resources to write samples for all of RhinoCommon methods. I once checked it and there are around 100’000 namespaces, types, and members.

We do, however, provide samples for all of RhinoScriptSyntax functions. There are almost 1’000 attributes in the RhinoScriptSyntax pseudomodule in V6 today.

All of RhinoScriptSyntax is open-source and you can read its source to understand how that works. For example, the rhinoscriptsyntax.AddPolyline() function today starts on this line. This can help explaining how to write RhinoCommon code.

By looking at rhinoscriptsyntax code, you can see how we implemented its high-level functions using RhinoCommon methods.

I hope this helps, thanks,


Giulio Piacentino
for Robert McNeel & Associates

1 Like

Thanks Giulio, that’s a good starting point.

We do not have the resources to write samples for all of RhinoCommon methods. I once checked it and there are around 100’000 namespaces, types, and members.

I would also argue that its not really necessary in this case (however, yes of course it would be nice to have examples for every little thing). In this specific example it is really about understanding the language not the API. If we know you need IEnumerable of Point3d then we know there are two ways to make that. List or Array. Knowing how to populate a list or array in about the language (List.add(Point3d) or Array[index] = Point3d.) In which case Rhinocommons responsibility is to show how to make a point, which it does here

Then we will end up with @RIL example

List<Point3d> ListOfPoints = new List<Point3d>();
ListOfPoints.Add(new Point3d(0.0, 1.1, 2.2);
ListOfPoints.Add(new Point3d(…);
ListOfPoints.Add(new Point3d(…);
var pline = new Polyline(ListOfPoints);

Yes, it is easy to mock the mice who enter the labyrinth for the first time and wonder: “how can’t they figure out the way, it’s right there!”. When you have spent numerous years in trial and error and managed to get out. Now in the high tower you laugh at them from above.

what? The point was to inform you to learn the language. For instance if you are interested in C# you might start here: https://www.youtube.com/watch?v=sQurwqK0JNE Is that bad advice? Fine, I’ll change my advice. Please do not learn the language and continue to fumble around complaining about things you can learn if you took even the slightest initiative. Goodluck.

I got that point from the others, and I said my opinion of C# at the moment. Hence, your pile up answer was a mockery.


yes, I just meant knowing basics. Just to get a simple idea of whats going on.
I mean that IEnumerable example is actually very good. If you know basic C# you know exactly what this means. Every object name starting with an “I” is a sign for being an “Interface”. Interfaces are “contracts” for classes, meaning when creating a class which derives from an interface, you need to implement certain methods and members, defined in that interface. So its kind of a blueprint.
When coding with interfaces, you can make a program run without even specifying a concrete object. You can say: “no matter which type, just make sure it has this method or member implemented”.
There are implementation of interfaces in Python as well. Its just not very common and not part of the standard library.

That “IEnumerable” interface is a standard blueprint for most collections, such as lists, arrays and others.
What does it mean? Simply that you can feed this constructor/function with any type of collections (build upon this interface). This can be quite handy, because it prevents a conversion from one collection to another. So if the constructor would say “Polyline(List<> pts)” instead, but you are having an array of points, you would need to convert it to a List before passing it in. So its nothing part of the RhinoApi.

1 Like