Implementing MLINE command in Rhino

Since there is no native command in Rhino similar to the MLINE command in AutoCAD, I am going to implement one by myself. During my everyday work, I constantly need this function to draw plan walls, punch holes/windows/doors, etc. One magic thing about MLINE is that it can create merged cross automatically. I wonder whether there are any existing solutions out there. If not, any suggestions/tips on how this can be done beautifully?

Note: I am aware of the plugin VisualARQ, but it is an overkill simply for this feature.

Any thoughts/ideas are welcome!

I prototyped something like this years ago. But darn if I know what happened to the source code…

1 Like

What a pity! Please let me know whenever you find them or recall the basic procedures.

As I am starting coding, I run into two questions:

  1. Is there a sample python code for drawing polyline using Rhinocommon which dynamically updates polyline with mouse (basically the same functionality with the native Polyline command)? How do I remove the Display.DrawLine if the user choose to Undo the last segment?

  2. When I do getObject, can I set filter using userdata? For example, I may have some wall objects with custom “hallmarks”. And later when I do modification, I want to only select these wall objects.

Many thanks!

Also, do you think it is easier to maintain these MLINEs as planar surfaces or lines? It makes little difference when I print them, but it may be easier to punch or trim the walls as surfaces.

Hi @vincentfs,

it quickly gets quite complex to mimic Rhino’s complete polyline drawing behavior, but you might try this example: (2.4 KB)

For a minimal solution, without Undo, Autoclose, Color change when layer is changed while drawing, duplicate point removal etc. you could just use this:

import rhinoscriptsyntax as rs

points = rs.GetPoints(True)
if points: 
    id = rs.AddPolyline(points)

Yes, you can use custom filters to limit selection to all kinds of attributes during a GetObject() prompt, example code here.


1 Like

Great! These examples are exactly what I was looking for.

Thank you. @clement

@clement @dale Sorry to bother again. Is there a way to trigger custom behaviors after a object is modified (say, moved, copied or scaled).

For example in the Rhino plugin visualARQ, when you move or copy a wall it will automatically merge with adjacent walls. How is that behavior normally achieved?

Much appreciated!

Note that these commands (copy, move, scale) are native Rhino commands. Nonetheless, it triggers the merge function (or other custom behaviors).

Hi @vincentfs, you might take a look at events to do this. Whenever you modify the contents of the rhino document, various events are fired. You can “hook into” these events and add your own behaviour, however not all events can be used with python. There is some info about this here.


Very helpful. Thank you very much!