Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 5938

Struggle with python code

$
0
0

hello:) i have a struggle with my python code. as you can see on the picture i tried to replace the functions of the pink surrounded Component ‘Surfaces’ with a python3 component and a code i wrote. now i have the problem that my code is not incorrect but it does not change anything of my surface i modelled in rhino so it looks empty there and no picture is generated. i think the problem is that out of the untrimmed surfaces (see panel) it gets to only (lists). i dont know how to change - can someone please explain ? and help me with my code! THX :slight_smile:

import Rhino.Geometry as rg
import math

# --- Eingaben in Listen umwandeln ---
if not isinstance(G, list):
    G = [G]
if not isinstance(A, list):
    A = [A]

# --- Achse vorbereiten ---
if hasattr(AX, "PointAtStart") and hasattr(AX, "PointAtEnd"):
    start = AX.PointAtStart
    end = AX.PointAtEnd
    axis_vector = end - start
else:
    raise ValueError("AX muss eine Curve sein")

result = []

for geom in G:
    if geom is None:
        continue

    # --- GH-kompatible Objekte ---
    geo = None
    if isinstance(geom, rg.Curve):
        geo = geom
    elif isinstance(geom, rg.Surface):
        geo = geom.ToBrep()  # WICHTIG: Surfaces als Brep
    elif isinstance(geom, rg.Point3d):
        geo = geom
    else:
        # Falls GH Brep direkt
        try:
            geo = rg.Brep.TryConvertBrep(geom)[0]
        except:
            geo = None

    if geo is None:
        continue

    # --- Für jeden Winkel kopieren und rotieren ---
    for angle in A:
        rad = math.radians(angle)
        xform = rg.Transform.Rotation(rad, axis_vector, start)
        dup = geo.Duplicate()
        if dup is not None:
            dup.Transform(xform)
            result.append(dup)

T = result

7 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 5938

Trending Articles