SubCurve from a Midpoint?

When creating a shortened section, would it be possible for an option of midpoint for the start of the subcurve? Or is there something similar available elsewhere?

Hi Jonathan - there is no tool for this - it makes sense as an option, but does not exist currently.

https://mcneel.myjetbrains.com/youtrack/issue/RH-53494

@Jonathan_Hutchinson1 - here is a script that may help for now - I posted and pulled this as I was getting a lot of crashes - if you grabbed it earlier, download the latest, I think it is better now.

Added length constraint.
Seems to work OK now - I have not had any more crashing.

To use the Python script use RunPythonScript, or a macro:

_-RunPythonScript "Full path to py file inside double-quotes"

-Pascal

2 Likes

Thank you so much Pascal - sorry to bring something up which has already a fix posted for in the past.

It’s working well on my end so far, and with surface edges too. Do you it’s something that would ever go over breakpoints/kinks? Although I guess that does kind of break with the syntax of it being a subcrv. (purely wondering out of interest)

1 Like

Hi Jonathan - it should work on joined curves with kinks but it will not on edges as these are separate curves. DupEdge and Join

-Pascal

Hi @Pascal,

Line 76 should be gp instead of go i guess. Will you add support for closed curves ?
_
c.

Hi Clement - thanks, you’re correct. I just made a differnt ‘fix’ that was intended to make things better (match the opposite side by curve length and not just parameter difference as I used initially) but I broke something along the way - or there is a bug with Curve.GetLength(Interval)… still poking.

Yeah, I have not looked at closed curves… that may be a head-scratcher if the seam falls inside the sub curve.

-Pascal

…maybe move the seam to the first point, then go in both directions ? it is tricky.

_
c.

That is what came to mind, start from a new seam point… I’ll see if I can trick Rhino into thinking I know what I’m doing.

Need to fix the length problem first… I am mystified. =)
Ah. Descending interval… can’t have those.

Updated above - that should work now. Still need to deal with closed curves.
@clement - my cheap way out for the moment:
If the curve is closed, first set the seam point at the pick point, then set the seam point at the middle of the new curve’s domain (i.e. as opposite as possible from the pick point), then get a base parameter from the pick point this new curve and proceed as before. It will all fall apart when the sub curve gets close to being the whole curve, but for now it is a quick fix.

   if crv.IsClosed:
        crv.ChangeClosedCurveSeam(basePar)
        crv.ChangeClosedCurveSeam(crv.Domain.Mid)
        baseParRC, basePar = crv.ClosestPoint(pt)

@Jonathan_Hutchinson1 - that script above is now updated to handle closed curves, a ‘MarkEnds’ mode to just drop points, like regular SubCrv does, and some bug fixes.

-Pascal

2 Likes

That’s great Pascal. Tried successfully with the mark ends mode too.

I see that, maybe an easy fix is just to change line 170 to this:

if tCrv: sc.doc.Objects.Replace(id, tCrv)

seems to stop the error. Btw. i found that by default, the conduit fails to draw anything over here because all DrawPoint calls are missing the color argument. I’ve downed from here. But this is a cool script i’ll use often.

thanks,
c.

Hi Clement -
Oh, OK - thanks, I’ll look at the things you mention - I did not test further but I guess if I set the seam of a closed curve opposite the pick point parameter , when dragging gets close to the seam, the parameter may be uneven (not match arc length) as it approaches that point and one end of the new curve could fall off the end of the input before the other.

it all draws here. I thought DrawPoint uses the current layer color if there was no color info… but I’ll check it, thanks.

Basically a bit more work to do, is what you’re saying… =)

-Pascal

Yes, sorry. It did not draw anything over here while moving the mouse. Then i added a try: except: to the conduit code and it gave me this:

DrawPoint() takes at least 2 arguments (1 given)

I found another small issue where a point on the other side as the args.CurrentPoint is displayed off the (open) curve. Not sure yet how to handle that, it should be outside the curve domain…

_
c.

Hi Clement - I know… I did not add the checkers for this - drawing off the end of the domain. I let it go, for now…

I just checked, and DrawPoint() is OK with just a Point3d as input. Thinking…

-Pascal

Hm, paste it:

    def GetPointDynamicDrawFunc( sender, args ):
        try:
            args.Display.DrawPoint(pt)
            parRC, par = crv.ClosestPoint(args.CurrentPoint)
            if parRC:
                diff = par-basePar
                par2 = basePar-diff
                p2 = crv.PointAt(par2)

                args.Display.DrawPoint(p2)
                args.Display.DrawPoint(args.CurrentPoint)

                parList = sorted([par,par2])
                tCrv = crv.Trim(parList[0], parList[1])
                if tCrv:
                    if tCrv.IsValid:
                        args.Display.DrawCurve(tCrv, crvColor)
        except Exception as ex:
            print ex

you get no error printed ?

Correction: this was V5 which prints the Error.

_
c.

Hi Clement - for the ‘over- drawing’ this seems to fix it, so far:

        if parRC:
            diff = par-basePar
            par2 = basePar-diff
            if par2> crv.Domain.Max:
                par2 = crv.Domain.Max
            elif par2 < crv.Domain.Min:
                par2 = crv.Domain.Min
         
            p2 = crv.PointAt(par2)

Your code works and draws correctly here so far - this is 6.17. I’ll try 6.15.

-Pascal

Hi @pascal, the non draw issue is only in Rhino 5.

_
c.

Oh- sorry - I see … (multitasking is not my best feature).

Fixed another bug and updates above, y’all.

-Pascal

Yes, it fixes it in the conduit, may be added to the curve creation too, without it will keep the wrong portion of the curve :wink:

_
c.

This is really such a helpful tool generally to reduce the amount of Dup Edge and Split / P I used to do for getting segments of edges to use down the line for Sweep cross sections and so on. Not this midpoint aspect per se, but just the new Out of the box tool.

Thank you again,

How about ‘from both ends’ too… or maybe that’s getting a bit too esoteric