Help for (failed from Guid to Surface)


HI How can I fix the guid conversion to Surface?

This post-IF and GH Library created does not actually detect scriptsyntax output

import rhinoscriptsyntax as rs
import ghpythonlib.components as gh
from Rhino.Geometry import *
if surface:
    if direction==1 or direction==2:
       rs.ReverseSurface(surface,direction)
    elif direction==3:
       rs.ReverseSurface(surface,4)

if flip:
    tmp=gh.Flip(surface)[0]
    surface=tmp


revSrf=surface

To give you a “short” answers, you’re working with three different things here that often cause confusion when utilized together:

  • Rhino.Geometry which is the geometrical part of the API that “deals with” objects, for instance an object of type Rhino.Geometry.Surface that is stored in memory (computer). Unfortunately, you need to get an understanding of OOP (Object Oriented Programming) - meaning classes in Python -, and some memory management to really be able to fully grasp this.

  • rhinoscriptsyntax which uses GUIDs or UUIDs (universal unique identifiers) to keep track of objects in use. It is a Pythonic module of functions - a PY file -, initially indented to make Python scripting in Rhino less cumbersome.
    Anyway, it implements API code behind the scenes and uses these GUIDs to keep track of stuff that was created by using the API, and thus stored in memory.

  • since rhinoscriptsyntax was initially intended to be used in Rhino, ghpythonlib, also referred to by “node in code”, was again an attempt to implement something like this for GHPython. It was a pretty weird endeavour from the get go, since it’s an attempt to make a scripting API for a visual, node-based scripting system (i.e. Grasshopper) that was probably intended as an alternative to “real”, text-based scripting in the first place. From what I see, I believe that it’s not very popular (?) and I can’t speak on how it works behind the scenes, since I haven’t used it much myself.

OK, when you use rhinoscriptsyntax and the API in tandem, you need to differentiate between when to pass objects (by reference or copy) to API code, or GUIDs to rhinoscriptsyntax functions. You’ll get into situations, much like yours, where you need to get a geometry object from a GUID, or vis versa. This is possible though not really recommended. You could probably get the underlying surface object with the “hidden” rs.coercegeometry() function.
What I always recommend is to only use the API in GHPython. It might be more cumbersome at first but once you get a grip on it, it’s rather straightforward and elegant to work with.

Your code would look something like this:

import Rhino.Geometry as rg

if surface:
    if direction == 0 or direction == 1:
        surface.Reverse(direction, True)

revSrf = surface

You can read about Rhino.Geometry.Surface.Reverse(int direction, bool inPlace) here. inPlace refers to flipping the current, already existing surface, without making a new copy.
You need to set the Type Hint for the surface input to Surface for this to work. This means that you declare it as Rhino.Geometry.Surface, when it’s input.

2 Likes

Thanks for Succeeded by TMP = RS.coercegeometry (surface, False)

import rhinoscriptsyntax as rs
import ghpythonlib.components as gh
from Rhino.Geometry import *
import copy
if surface:
    if direction==1 or direction==2:
       rs.ReverseSurface(surface,direction)

    elif direction==3:
       rs.ReverseSurface(surface,4)

w=copy.deepcopy(surface)
if flip:
    tmp=rs.coercegeometry(w,False)
    tmp=gh.Flip(tmp)[0]
    revSrf=tmp
else:
    revSrf=surface

But about the second method of using Rhino Geometry API, the result of the Flip page about the trim Surface is wrong with an Untrim Surface? Is there a solution? I used the ScriptSyntax function for the same problem

By looking at your screenshot, I’ve noticed on line 2 that you set direction to either be 1 or 2, whereas - when you look at the documentation - , it should be 0 or 1.
I’m not sure, if this is the culprit though that causes the untrimming. It’s hard to tell without a file to take a look at.


revers.gh (14.4 KB)
i sen the ghFilerevers2.gh (17.2 KB)

My bad! For trimmed surfaces, you need to use the brep method Rhino.Geometry.Brep.Flip(), instead of the surface one.
A trimmed surface seems to be interpreted as a boundary representation.

if flip:
    brep.Flip()

revBrep = brep

I’ve renamed the component input to brep and set its type hint to a Brep for this to work.

flip.gh (12.7 KB)

1 Like

hi @diff-arch Your description was very great
My other question is about the inverse process, how can we give Type Hint from Geometry (Brep,...)type to Guide inside Code?

import rhinoscriptsyntax as rs
x=rs.coerceguid(b,False)
rs.ShrinkTrimmedSurface(x)

I used Rs.Coerceguid (B, False) that Error gave
Is there any other way and possible?

GeometryToGuid.gh (9.0 KB)

You can use this instead:

b.Faces.ShrinkFaces()

ShrinkSrf = b