Type error with OffsetMany

I’m getting an unexpected error while trying to call either of the methods Curve.OffsetMany or PolyCurve.OffsetMany in python

def rebuffer_polycurve(pc, offset=OFFSET_BUFFER):
    # so this needs to 'over/under' offset to remove inconsequential features
    # work in + and - directions
    # + (outer curve): + then -. no edge cases here
    # - (inner curve): - then +.  offsetting inward can cause two conditions
    # a: offset degenerates into multiple curves
    # b: offset degenerates completely, and cannot yield a valid curve.
    print(f"try: {pc}")
    print(f"type: {type(pc)}, {type(offset)}")
        
    try:
        while (True):
            try_pc_over_buffer = pc.OffsetMany(offset, True)
            print(try_pc_over_buffer)
            if len(try_pc_over_buffer) == 1:
                pc_over_buffer = try_pc_over_buffer[0]
                break
            else:
                offset -= 0.05*offset
        print(f"pc_over_buffer: {pc_over_buffer}")
        pc_under_buffer = Curve.OffsetMany(pc_over_buffer, -1*offset)[0]
        print(f"pc_under_buffer:{pc_under_buffer}")
    except Exception as e:
        print(e)
        pc_under_buffer = None
    return pc_under_buffer

i’m trying to translate some code from DesignScript to python so i have some more control over what happens, but i’m getting a TypeError on the call

No method matches given arguments for OffsetMany: (<class ‘float’>, <class ‘bool’>)

my trace shows pc as PolyCurve and offset as float. I know the protogeometry library technically expects ‘double’ as an input. I thought maybe this is some weird CPython3 type issue, but normally i don’t have any issues with numeric types as arguments in python.

the fuget doesn’t show any info on OffsetMany so i’m sort of stumped. I tried casting it to System.Double but it doesn’t accept that either. maybe i’m missing something here?

thoughts?

I believe offset many also has a required normal input, which in node form is often left as null.

OffsetMany is a design script method. The Revit API doesn’t have a OffsetMany method. Just Curve.CreateOffset(XYZ) method. Have you referenced the design script library?

Then there is this issue:
https://www.autodesk.com/support/technical/article/caas/sfdcarticles/sfdcarticles/The-PolyCurve-OffsetMany-Dynamo-node-does-not-work-for-a-straight-PolyCurve-in-Revit.html

You are probably best off sticking with the Revit API as this is less likely to change than the Dynamo desgn script.

the ‘docs’ (Node help) indicate this defaults to null, so i didn’t pass an argument. i thought you don’t have to wire args that have default values, but i’ll give this as shot.

ok. this was it! pass in None as the last argument and it works. I guess i was somewhat confident that’s how arguments with default values are supposed to work, so is the default setting only handled on the dynamo side, and not in the definition in the protogeometry library?

just trying to clarify my misunderstanding here.

The node is written for nodes, not DesignScript or Python. If you place the node and then do NodeToCode you’ll see the null input applied. Default values aren’t actually applied via the Dynamo API (itself a wrapper of the ASM geometry library), but by the Dynamo node itself.

1 Like

The disadvantage of the Revit API is you can only use it in the context of Revit - this means no Generative Design, no Civil 3D, no Dynamo Core… you’re beyond limited.

And fortunately that link you provided appears to have been resolved too!

You can certainly mix the API thru python with all that Dynamo offers…

1 Like

Correct - but moving to straight Revit API is problematic as it misses a LOT of core geometry features (intersecting a point with a solid as one example).