Python script command for creating an Arc using Centre,Start,Angle

Hello,

Is there a rhinoscriptsyntax command that replicates the _Arc command using the Centre, Start and Angle option through the interface or will I have to use Rhino.Command?

The only 3 methods I see are AddArc, AddArc3pt and AddArcPtTanPt, none of which I can pass in the Centre, Start and Angle parameters.

Any help is greatly appreciated

Hi,

It doesn’t seem to be implemented in rhinoscriptsyntax yet, but it’s available in RhinoCommon:

import Rhino.Geometry as rg
import math

pt = rg.Point3d(0, 0, 0)
radius = 1.0
angle = math.pi / 2  # radians
arc = rg.Arc(pt, radius, angle)

You’ll get an instance of the Arc class or struct - an Arc object -, not a GUID.
If you want a GUID, you need to add the object to your Rhino document and give it a unique identifier:

import Rhino.Geometry as rg
import scriptcontext as sc
import System
import math

pt = rg.Point3d(0, 0, 0)
radius = 1.0
angle = math.pi / 2  # radians
arc = rg.Arc(pt, radius, angle)

guid = sc.doc.Objects.AddArc(arc)
if guid == System.Guid.Empty: 
    raise RuntimeError("Unable to add arc to document")

Here’s the documentation.

Finally, there’s also a constructor for an arc that’s constructed on a custom plane, instead of the default XY-one.

2 Likes

Hi diff, thank-you for your response. I don’t think this solution is what I need because it requires me to know the radius of the arc I am creating. I have looked at the documentation and don’t see any options for what I need. I even tried creating an arc with 2 points and a vector but that didn’t seem to work either.
Here is what I am trying to accomplish. I have a file that supplies the Start Point, the End Point and the Centre of the radius, and whether it is CW or CCW and I am trying to create geometry from the information in this file(it is building a cutting tool for a cam software) The Arc command that uses Centre,Start,Angle works perfect when manually creating arcs because I can control which side the arc is on, but when ran in a script I don’t know how to control whether it is cw or ccw. I have just been using
rhinoscriptsyntax.Command() with the points from the file as the parameters passed in and it works right about 95% of the time, which is great, but not when processing hundreds of files. If you have any other ideas I am all ears, thank-you again for taking the time to help me!

Hi @Scott_Berry,

If you skip pass rhinoscriptsyntax and go right to RhinoCommon, you’ll have a few more Arc constructors.

An arc is just an oriented plane, with “center” being the origin of the plane and “start” being a point on the plane’s x-axis. Then just specify the “angle” in radians.

– Dale

Well, maybe I’m not understanding this correctly, but if you have an arc center, start, end, it doesn’t need CW or CCW information to be created - there is only one single arc that has the specified center that starts at the start point and ends at the end point - the radius being fixed as the distance from center to start. Whether it’s CW or CCW will just depend on which side you’re looking at it from…

Edit: my brain is not working correctly here - too early on a Saturday morning… :stuck_out_tongue_winking_eye: There are of course two arcs possible, one less than or equal to 180° and the other one its complement. So, we can ad the CW/CCW specification to the code below:

So, for example, using the Arc constructor Start, tangent at start, end:

We assume that the start tangent is perpendicular to the arc plane’s X-Axis, i.e. the Y-Axis vector. All you need to do is create the plane first, then the arc. As the arc is normally created CCW in the arc plane, all we need to do later is reverse the arc tangent direction to get the CW arc possibility, I will do this with a True (CW) / False (CCW) flag in the method.

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino

def CreateArcCtrStartEnd(ctr,start,end,cw):
    plane=Rhino.Geometry.Plane(ctr,start,end)
    start_tan_vec=plane.YAxis
    #if cw is true, invert the tangent vector, the arc goes the other way
    if cw: start_tan_vec=-start_tan_vec
    arc=Rhino.Geometry.Arc(start,start_tan_vec,end)
    return arc

ctr_pt=Rhino.Geometry.Point3d(10.0,10.0,0)
start_pt=Rhino.Geometry.Point3d(31.651,22.5,0)
end_pt=Rhino.Geometry.Point3d(22.5,31.651,0)

arc=CreateArcCtrStartEnd(ctr_pt,start_pt,end_pt,False)
if arc:
    sc.doc.Objects.AddArc(arc)
    sc.doc.Views.Redraw()

The above numbers make a 30° arc of radius 25 centered at 10,10,0 (World Top) starting at 30° to the horizontal and going CCW, but you can plug in any numbers you like. If you pass the argument True for cw, you will get the 330° CW arc instead.

arc=CreateArcCtrStartEnd(ctr_pt,start_pt,end_pt,True)

It also works in different planes, for example these numbers will make a 90° radius 25 arc, CW viewed from Front, centered at 0 and starting at X-25. If you pass the True argument, you will get the 270° arc instead, CCW when viewed from the Front.

ctr_pt=Rhino.Geometry.Point3d(0,0,0)
start_pt=Rhino.Geometry.Point3d(-25,0,0)
end_pt=Rhino.Geometry.Point3d(0,0,25)

Thank-you so much for this, this is exactly what I was looking for. Interestingly, I didn’t end up using the CW and CCW call-outs from the file, just creating them with the argument of False worked every time. I ran 169 files through and they were perfect. Using the CW/CCW callouts actually caused it to create the wrong arcs. Now I will have some fun playing with different planes and finding exactly when and why I would use the CW/CCW call-outs from the file! Thank-you again for your time and expertise!

Hmm, I guess in that case that all of the arcs were in the same plane and less than or equal to 180° - maybe… The CW and CCW in the file are perhaps just indications of whether the original command was G2 or G3.