[Python] How to get the cross-sectional area of a SolidWorks part at a reference plane using...

Discussão em 'Python' iniciado por Stack, Setembro 5, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to automate SolidWorks using Python (win32com.client) and want to compute the cross-sectional area of a part when sliced by a reference plane.

    I've successfully opened the part and located the plane, but I can't figure out how to intersect the solid body with the plane to get the area.

    My questions:


    1. How can I intersect a SolidWorks Body2 with a reference plane using Python and the COM API?


    2. How can I get the resulting section area?


    3. Are there any workarounds if CreateSectionProperties is not available in the Python COM API?

    Any working example or guidance would be greatly appreciated.

    Here's what I've tried so far:

    import win32com.client

    swApp = win32com.client.Dispatch("SldWorks.Application")
    swApp.Visible = True

    part_path = r"C:\path\to\part.SLDPRT"
    part = swApp.OpenDoc(part_path, 1) # 1 = Part

    plane_name = "Primary Sketch Plane"

    # Find plane
    feat = part.FirstFeature
    plane = None
    while feat is not None:
    if feat.Name == plane_name:
    plane = feat
    break
    feat = feat.GetNextFeature

    if plane is None:
    print(f"Plane '{plane_name}' not found")
    else:
    print("Plane found:", plane.Name)

    # Get first solid body
    bodies = part.GetBodies2(1, False) # 1 = solid bodies
    if bodies:
    body = bodies[0]
    # Attempt to get section area (this fails)
    sec_prop = body.CreateSectionProperties(plane, True)
    print("Section area:", sec_prop.GetArea())



    This fails with errors like:

    AttributeError: <unknown>.IGetBodies2.IntersectWithPlane2

    Continue reading...

Compartilhe esta Página