It is possible to convert the macro to the RhinoScript?

Hi Guys!
It is possible to convert the macro to the RhinoScript?

THX

@leex,

there is no automatic conversion but if you post your macro with a short description here someone might be able to help out.

c.

Hi Clement!
It is a pity that there is no automatic converter.
For example, this macro. Just wanted to see how it will look in a script

! _Circle
Pause
SetRedrawOff
CPlane
Rotate Z 90
Pause
Pause
CPlane
Previous
SelLast
-_Rebuild p=12 _enter
SelNone
SetredrawOn

@leex, not sure why you’re changing the CPlane in the macro, but for the circle part you might start with this:

import rhinoscriptsyntax as rs

def DoSomething():
    # get the circle center
    center = rs.GetPoint("Circle center", in_plane=True)
    if not center: return

    # define the radius
    radius = rs.GetDistance(center, second_pt_msg="Radius")
    if not radius: return

    # add the circle
    circle_id = rs.AddCircle(center, radius)
    if not circle_id: return

    #rebuild the circle
    rs.RebuildCurve(circle_id, degree=3, point_count=12)

DoSomething()

c.

so that the end/start has appeared at the bottom of the circle

The script is not fully operational((

If you get this error, your rhinoscript syntax files (or rhino itself) might be out of date. I do have the method GetDistance in module userinterface.py. You might update your syntax files from here if they are not updated while installing the newest SR of Rhino 5.

To get the startpoint of the curve at the bottom, just rotate the resulting circle after rebuilding it like shown below:

import rhinoscriptsyntax as rs

def DoSomething():
    # get the circle center
    center = rs.GetPoint("Circle center", in_plane=True)
    if not center: return

    # define the radius
    radius = rs.GetDistance(center, second_pt_msg="Radius")
    if not radius: return

    # add the circle
    circle_id = rs.AddCircle(center, radius)
    if not circle_id: return

    # rebuild the circle
    rs.RebuildCurve(circle_id, degree=3, point_count=12)

    # rotate the curve
    rs.RotateObject(circle_id, center, -90.0)

DoSomething()

c.

I updated only one file userinterface.py
but the error still occurs.
I’ll try to update the Rhino.

Thank you Clement!

====

By the way I have long wanted to ask.
Why first start Python comes with some delay within the opened Rhino??

@leex, what service release of Rhino 5 are you using (Help -> About…)?

Version 5 SR12 64-bit

At least try updating to SR 13.

I updated to SR13
script works now
Thank you everybody :slight_smile:

====

By the way I have long wanted to ask.
Why first start Python comes with some delay within the opened Rhino??

It held for about 5 seconds and then starts

But RhinoScript starts immediately

Yep, always been that way, and I agree it’s annoying. It seems to just take a lot of time to load the libraries. Don’t know why.

–Mitch

Hi @leex, great that it works now. The reason why it takes so long to initialize is that this line above in the script:

import rhinoscriptsyntax as rs

It imports all methods and functions of the rhinoscriptsyntax, even unused ones. You could get away of this and speed up the first and all subsequent script runs if you only import the required (the used) modules in your script. With small scripts like the one above, it is easy and the script would look like this:

from rhinoscriptsyntax import GetPoint, GetDistance, AddCircle, RebuildCurve, RotateObject

def DoSomething():
    # get the circle center
    center = GetPoint("Circle center", in_plane=True)
    if not center: return

    # define the radius
    radius = GetDistance(center, second_pt_msg="Radius")
    if not radius: return

    # add the circle
    circle_id = AddCircle(center, radius)
    if not circle_id: return

    # rebuild the circle
    RebuildCurve(circle_id, degree=3, point_count=12)

    # rotate the curve
    RotateObject(circle_id, center, -90.0)

DoSomething()

Notice that the main difference here is the first line where all methods are imported individually and that you will not have to write the “rs” in front of the method names. The script above does not create a timeout.

c.

Not entirely - it’s always a bit slow on the first run. What I did is the following:

  • Created a small scriptlet with as follows and named it “LoadPython”.
import rhinoscriptsyntax, scriptcontext, Rhino
print "Python loaded!"
  • Created an alias that calls the above script.
  • Placed the alias in my Rhino startup commands.

So when I run Rhino for the first time, it runs the startup script, loading the modules while Rhino is starting up. This does speed up the running of the first script in a given session, but it seems there is still a tiny perceptible time lag (not 5 seconds though). Any subsequent scripts run instantaneously.

–Mitch

1 Like

For a long time I was trying to go this way, but this file is not loaded when start Rhino.
It has the extension .py
Can only use .rvb

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino

Now I try to create an alias.
Thank you Mitch for this tip!!

Yes, you cannot load python scripts at Rhino startup, unless you use the workaround I showed above, create an alias to the script and then put the alias in your startup commands (not startup scripts).

One had hoped that with V6, python scripting would become as integrated into Rhino as the current Rhinoscript is, but unfortunately that hasn’t happened.

–Mitch

I crate a macro

! _-RunPythonScript ( import rhinoscriptsyntax, scriptcontext, Rhino print “Python loaded” )

I put it macro in the aliases

I put aliases Pythonload to :
Run this commands every time Rhino start

But nothing has changed.
Python loaded with a serious delay
Where is my mistake?

I don’t think that actually works that way.

I have my little script saved as LoadPython.py in my scripts folder.

The alias to run it is as follows:
LoadPython … ! _-RunPythonScript ("C:\Users\<me>\AppData\Roaming\McNeel\Rhinoceros\5.0\Scripts\LoadPython")

In my startup commands I have just LoadPython

–Mitch

I did everything like you, but the delay is still there.

Maybe add an attribute **sleep** as well as in the Rhino Script?

for example run import rhinoscriptsyntax, scriptcontext, Rhino when start Rhino five times in every 10 seconds?

I don’t understand this comment Mitch. Can you help me understand?:slight_smile: