rs.AddFilletCurve has me stumped

Hi All,

I really need some help from someone in McNeel if possible as I think the problem is a bug in the add fillet curve command, maybe not and someone can tell me otherwise. I will be quite happy to find out either way.

This script is run from within another script and all variables are working it does everything except insert that last fillet curve.

The problem is the rs.AddFilletCurve for curves 4 and 5, the curves appear to be made correct yet the rs.AddFilletCurve fails to add a new curve to the document. As you will see I have used this command at the start of my script and in that context it works fine, I have also been able to manually add a fillet to curves 4 and 5 along with the radius as in the script.

It just doesn’t want to play ball in the script, so please put me out of my misery I am always wanting to learn and this has been a day wasted for something I just cannot see.

Roger

#! python 3
#import rhinoscriptsyntax as rs
#import scriptcontext as sc
import math
import Rhino.UI
#import System
#import System.Collections.Generic
#import Rhino

#import Eto.Drawing as drawing
#from Eto.Drawing import Padding
#from Eto.Forms import Dialog, DropDown, DynamicLayout
#import Eto.Forms as forms


# Imports
import scriptcontext as sc
import Rhino
from Rhino.UI import RhinoEtoApp
import Eto.Drawing as drawing
from Eto.Drawing import Padding
from Eto.Forms import Dialog, DropDown, DynamicLayout
import Eto.Forms as forms
from System.Collections.ObjectModel import ObservableCollection
import configparser as cp
import System
import System.Collections.Generic
import os
from pathlib import Path
import rhinoscriptsyntax as rs


# New Rerun/Exit Dialog Class
class RerunExitDialog(forms.Dialog[bool]):
    def __init__(self):
        super().__init__()
        self.Title = "Rerun or Exit"
        self.Padding = drawing.Padding(10)
        self.Resizable = False

        # Create label
        self.m_label = forms.Label()
        self.m_label.Text = "Do you want to rerun the script or exit?"   # Fixed: Added Text argument

        # Create buttons
        self.m_rerun_button = forms.Button()
        self.m_rerun_button.Text = "Rerun"
        self.m_exit_button = forms.Button() 
        self.m_exit_button.Text = "Exit"
        # Set button actions 
        self.m_rerun_button.Click += lambda sender, e: self.Close(True)
        self.m_exit_button.Click += lambda sender, e: self.Close(False)

        # Create layout
        layout = forms.DynamicLayout()
        layout.Spacing = drawing.Size(5, 5)
        layout.AddRow(self.m_label)
        layout.AddRow(self.m_rerun_button, self.m_exit_button)

        # Set the dialog content
        self.Content = layout

# Secondary script
def ASME_B_16_5_45_Long_Radius_Elbows():

    try:

        print("Config values in secondary script:",config_values)

        rad = float(config_values.get('dim 4'))
        print("Radius1:", rad)

        curve1 = rs.GetObject("Select 1st curve to fit", rs.filter.curve, True)
        curve2 = rs.GetObject("Select 2nd curve to fit", rs.filter.curve, True)

        if not curve1 or not curve2:
            print("Object selection canceled.")
            return

        # CurveFilletPoints(curve_id_0, curve_id_1, radius, base_point_0, base_point_1, return_points)
        fillet = rs.CurveFilletPoints(curve1, curve2, rad)
        if fillet:
            rs.AddPoint(fillet[0])
            rs.ObjectName( rs.FirstObject(), 'NIP 1' )
            rs.AddPoint(fillet[1])
            rs.ObjectName( rs.FirstObject(), 'NIP 2' )
            rs.AddPoint(fillet[2])
            rs.ObjectName( rs.FirstObject(), 'NIP 3' )

        curve3 = rs.AddFilletCurve(curve1, curve2, rad)

        #point = rs.LineLineIntersection(curve1, curve2)
        #if point:
            #rs.AddPoint(point[0])
            #rs.AddPoint(point[1])
        
        

        param1 = rs.CurveClosestPoint(curve1, fillet[0])
        print("Curve parameter1: {}".format(param1))
        rs.SplitCurve(curve1, param1)

        param2 = rs.CurveClosestPoint(curve2, fillet[1])
        print("Curve parameter2: {}".format(param2))
        rs.SplitCurve(curve2, param2)

        if curve3:

            OIP = (0,0,0)
            #OIP = rs.AddPoint(0,0,0)
            #rs.coerce3dpoint(OIP)
            print(OIP)

            OIP1 = (0,float(config_values.get('dim 1')),0)
            rs.AddPoint(OIP1)
            rs.ObjectName( rs.FirstObject(), 'OIP 1' )
            print(OIP1)
            

            OIP2 = (float(config_values.get('dim 2')), float(config_values.get('dim 3')),0)
            rs.AddPoint(OIP2)
            rs.ObjectName( rs.FirstObject(), 'OIP 2' )
            print(OIP2)

            OIP3 = (float(config_values.get('dim 4')),float(config_values.get('dim 1')),0)
            rs.AddPoint(OIP3) 
            rs.ObjectName( rs.FirstObject(), 'OIP 3' )
            print(OIP3)


            curve4 = rs.AddLine(OIP, OIP1)
            print(curve4)
            curve5 = rs.AddLine(OIP, OIP2)
            print(curve5)

            if curve4 and curve5:
                print("Lines created successfully. Attempting to create fillet.")
                rs.AddFilletCurve(curve4, curve5, rad)

       

            #internal = rs.AddPipe(curve, 0, float(config_values.get('dim 3')) / 2)
            #offset = (float(config_values.get('dim 2')) - float(config_values.get('dim 3'))) / 2
            #rs.OffsetSurface(internal, offset, tolerance=None, both_sides=False, create_solid=True)
            #rs.DeleteObject(internal)

        print("End of 45 Long Radius Elbows")

    except Exception as e:
        print(f"Error in 45 Long Radius Elbows: {e}")

# Main script logic
#if __name__ == "__main__":
def RunScript():


    while True:
        # Run the Pulled Bends function
        ASME_B_16_5_45_Long_Radius_Elbows()

        # Ask the user if they want to rerun the script or exit
        rerun_dialog = RerunExitDialog()
        rerun_result = rerun_dialog.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow)

        if not rerun_result:
            print("Exiting script.")
            break

# Execute the rerun logic
RunScript()

Hi @RogerD,

This seems to work:

#! python 3
import rhinoscriptsyntax as rs

line0 = rs.AddLine([0,0,0], [5,1,0])
line1 = rs.AddLine([0,0,0], [1,5,0])
fillet = rs.AddFilletCurve(line0, line1)

rs.Redraw()

– Dale

Thanks Dale,

The only way I got the two curves in my script to fillet was to extend their lengths by 0.001 mm
which is not an issue, I could fillet the same curves manually but not with the script.

Roger