# SubD Edge & Vertex Tags (Creasing Programmatically)

**URL:** <https://discourse.mcneel.com/t/subd-edge-vertex-tags-creasing-programmatically/125192>\
**Category:** Grasshopper Developer\
**Created:** [June 1, 2021, 6:30pm UTC](https://discourse.mcneel.com/t/subd-edge-vertex-tags-creasing-programmatically/125192 "2021-06-01T18:30:43Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![silvano](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/silvano/32/526276_2.png) [@silvano](https://discourse.mcneel.com/u/silvano)\
**Post date:** [June 1, 2021, 6:30pm UTC](https://discourse.mcneel.com/t/subd-edge-vertex-tags-creasing-programmatically/125192/1 "2021-06-01T18:30:43Z")

</div>

Hi All, @stevebaer,

I am unwelding specific mesh edges with Python in a GH component to achieve creased SubD edges. SubD conversion is done with GH’s Subd from Mesh component. The mesh has Ngons with 5 and 6 vertices. UnweldEdge() destroys the Ngons. I am trying to store the Ngons and add them again after UnweldEdge(). This results in an invalid mesh and SubD from Mesh reverts to triangulating the Ngon faces. Mesh edges look ok though. With the original mesh, Subd from Mesh respects the Ngon faces (DEBUG output). How can I keep the Ngon intact while unwelding the edges?

Any other way to crease edges programmatically? As far as I understood from @dalelear the relevant methods for this are not yet exposed in rhcommon:

> [@Is it possible to choose which mesh edges to crease for a SubD object?](https://discourse.mcneel.com/t/is-it-possible-to-choose-which-mesh-edges-to-crease-for-a-subd-object/119635/13):
>
> The problem with your geometry is that it wasn’t welded at first. I added a Combine and Clean component from Kangaroo. It does the job. Keep in mind that Mesh Topology edges are numbered in a different way than SubD or Mesh edges. If you want to see the creased SubD edges, you can use a Match Text component to filter the edges based on their edge tag. [Bazel.gh](https://discourse.mcneel.com/uploads/short-url/paFXHC6MhLE5dsieHQ07OP4n46p.gh) (155.4 KB)

Edit: I extracted the relevant part of the geometry. It is internalized in the below GH file.

Any help is highly appreciated.  
Thanks - S

[1075\_210602\_RFD-CustomCreaseTest\_SO.gh](https://discourse.mcneel.com/uploads/short-url/iS3TBVKqICzgpQj1kI7rULIRGvT.gh) (16.1 KB)

```auto
def ngon_tag(mesh, indices):
    ngs = []
    for ng in mesh.Ngons:
        if ng.BoundaryVertexCount > 4:
            ngs.append(ng)
    # After UnweldEdge Ngons are gone
    res = mesh.UnweldEdge(indices, True)
    # AddNgons recreates Ngons but results in an invalid mesh and subsequently 
    # GH SubD from Mesh component triangulates Ngons with more than 4 vertices.
    mesh.Ngons.AddNgons(ngs)
    return mesh

```

Subd from Mesh with orignal mesh, Ngons respected:

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/a/1/f/a1fc52f0c0913e67838fb06411b18ee12e6d2382.jpeg)

Subd from Mesh after above Python code, Ngons triangulated, creases as intended:

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/a/0/4/a04bd4bbe12c586347186cbbc3fd685d1a5f114d.png)

---

<div class="post-metadata">

**Author:** ![stevebaer](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/stevebaer/32/473567_2.png) [@stevebaer](https://discourse.mcneel.com/u/stevebaer)\
**Post date:** [June 2, 2021, 5:22pm UTC](https://discourse.mcneel.com/t/subd-edge-vertex-tags-creasing-programmatically/125192/2 "2021-06-02T17:22:39Z")

</div>

> [@silvano](#):
>
> Any other way to crease edges programmatically?

Creasing edges is done by setting EdgeTag information. See  
[https://developer.rhino3d.com/api/RhinoCommon/html/P\_Rhino\_Geometry\_SubDEdge\_Tag.htm](https://developer.rhino3d.com/api/RhinoCommon/html/P_Rhino_Geometry_SubDEdge_Tag.htm)

There is also a `SetEdgeTags` function on the SubDEdgeList that is available in Rhino 7.7. This function is the preferred approach to setting creases for a set of edges.

---

<div class="post-metadata">

**Author:** ![silvano](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/silvano/32/526276_2.png) [@silvano](https://discourse.mcneel.com/u/silvano)\
**Post date:** [June 2, 2021, 7:59pm UTC](https://discourse.mcneel.com/t/subd-edge-vertex-tags-creasing-programmatically/125192/4 "2021-06-02T19:59:23Z")

</div>

Hi @stevebaer, @DavidRutten

Thanks for adding `SetEdgeTags` to rhcommon. The C# component below uses it. Creasing decisions are based on points at the control polygon edges middle point (point at middle → edge is creased).  
[1075\_210602\_RFD-SubdEdgeTagWSearch\_SO.gh](https://discourse.mcneel.com/uploads/short-url/4XBvphvDZEdikEW4SPSgBUeGBJQ.gh) (11.5 KB)

* * *

Some issues persist that I cannot resolve.

Issue 1  
The SubdDEdges component generates an `Object reference not set to an instance of an object` error. I suspect this is caused by caching: When I copied the C# component in another definition and connected the inputs, SubDEdges worked. (Edit: ) Any upstream change before the C# component brings back the error. Output of the C# component superficially looks good. I tried calling `ClearEvaluationCache` and `UpdateAllTagsAndSectorCoefficients` in all possible combinations. Still getting the same error.

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/6/7/a/67ac6f647952545f45a9758ef999f4d2e91ded65.png)

Issue 2  
After baking the output of the C# component, we get weird shading behavior. Arctic mode is extremely slow and artifacts show on the SubD. This does not happen if we bake the SubD before the C# component. We have seen this before with modeled SubDs, but it was resolved by a recent update.

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/0/2/8/0289994b3b74883b03d1e7d72b3c2b8ac13e6ea1.jpeg)

Issue 3  
In Python components `SetEdgeTags` results in the `Multiple targets could match error...` . Also, `SetEdgeTags` [is undocumented](https://developer.rhino3d.com/api/RhinoCommon/html/T_Rhino_Geometry_Collections_SubDEdgeList.htm)?

---

<div class="post-metadata">

**Author:** ![stevebaer](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/stevebaer/32/473567_2.png) [@stevebaer](https://discourse.mcneel.com/u/stevebaer)\
**Post date:** [June 2, 2021, 9:02pm UTC](https://discourse.mcneel.com/t/subd-edge-vertex-tags-creasing-programmatically/125192/5 "2021-06-02T21:02:01Z")

</div>

> [@silvano](#):
>
> Also, `SetEdgeTags` [is undocumented](https://developer.rhino3d.com/api/RhinoCommon/html/T_Rhino_Geometry_Collections_SubDEdgeList.htm)?

This function was added to Rhino 7.7 which is still not the official release until next week. Once we release 7.7, we will update the RhinoCommon API docs.

---

<div class="post-metadata">

**Author:** ![silvano](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/silvano/32/526276_2.png) [@silvano](https://discourse.mcneel.com/u/silvano)\
**Post date:** [June 2, 2021, 9:03pm UTC](https://discourse.mcneel.com/t/subd-edge-vertex-tags-creasing-programmatically/125192/6 "2021-06-02T21:03:41Z")

</div>

> [@stevebaer](#):
>
> This function was added to Rhino 7.7 which is still not the official release until next week. Once we release 7.7, we will update the RhinoCommon API docs.

I forgot I am using the RC updates. Thanks for the reminder.

Just changed my post above to sum up everything regarding EdgeTags.

---

<div class="post-metadata">

**Author:** ![martinsiegrist](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/martinsiegrist/32/498369_2.png) [@martinsiegrist](https://discourse.mcneel.com/u/martinsiegrist)\
**Post date:** [June 2, 2021, 9:10pm UTC](https://discourse.mcneel.com/t/subd-edge-vertex-tags-creasing-programmatically/125192/7 "2021-06-02T21:10:13Z")

</div>

Silvano, that’s a nice way with your script!

@stevebaer this would be a useful command …

---

<div class="post-metadata">

**Author:** ![silvano](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/silvano/32/526276_2.png) [@silvano](https://discourse.mcneel.com/u/silvano)\
**Post date:** [July 13, 2021, 5:49pm UTC](https://discourse.mcneel.com/t/subd-edge-vertex-tags-creasing-programmatically/125192/8 "2021-07-13T17:49:24Z")

</div>

@stevebaer  
Is there an equivalent method to `SetEdgeTags()` for SubD.Vertices in rhinocommon?

I have to crease some vertices, but not all of them, around an open edge loop. Please see the following sketch. Vertices to be creased are encircled in red.

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/8/f/7/8f76c173d2e77dcac64254e0151c6d6a17a0ff7e.jpeg)

The following results in an invalid SubD. I guess, as with the EdgeTags, this needs an implementation from your end to call the correct C++ methods.

```plaintext
    // Crease vertices
    SubDVertex sv = S.Vertices.First;
    while (sv != null)
    {
      sv.Tag = SubDVertexTag.Corner;
      sv = sv.Next;
    }

```

Please see the following test file:  
[CreaseVertex.gh](https://discourse.mcneel.com/uploads/short-url/ft5gr1DNeLUhT88nWQz6LUIZ2Kg.gh) (8.6 KB)

Thanks

---

<div class="post-metadata">

**Author:** ![silvano](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/silvano/32/526276_2.png) [@silvano](https://discourse.mcneel.com/u/silvano)\
**Post date:** [July 13, 2021, 6:23pm UTC](https://discourse.mcneel.com/t/subd-edge-vertex-tags-creasing-programmatically/125192/9 "2021-07-13T18:23:02Z")

</div>

@stevebaer I was able to solve the invalid SubD with the below. Is this as it is supposed to be done?

`S` is a SubD object.

```cs
// Crease vertices
SubDVertex sv = S.Vertices.First;
while (sv != null)
{
    sv.Tag = SubDVertexTag.Corner;
    sv = sv.Next;
}
// Fixes invalid output caused by sv.Tag = SubDVertexTag.Corner from above
S.ClearEvaluationCache();
S.UpdateAllTagsAndSectorCoefficients();

```

---

<div class="post-metadata">

**Author:** ![lasathrs](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/lasathrs/32/493665_2.png) [@lasathrs](https://discourse.mcneel.com/u/lasathrs)\
**Post date:** [August 25, 2021, 9:58am UTC](https://discourse.mcneel.com/t/subd-edge-vertex-tags-creasing-programmatically/125192/10 "2021-08-25T09:58:57Z")

</div>

Amazing! I have been looking for this solution for a while! I added having specific points as corners.  
[CreaseVertex.gh](https://discourse.mcneel.com/uploads/short-url/xhsCeCyzCK3FOVw7dbeg06948HZ.gh) (19.4 KB)

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/0/f/d/0fd5977528ff4061d10dc95f09023c253cc4b089.jpeg)

---

<div class="post-metadata">

**Author:** ![ThomasE](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/thomase/32/516431_2.png) [@ThomasE](https://discourse.mcneel.com/u/ThomasE)\
**Post date:** [September 17, 2021, 10:50pm UTC](https://discourse.mcneel.com/t/subd-edge-vertex-tags-creasing-programmatically/125192/11 "2021-09-17T22:50:27Z")

</div>

thanks for your code @lasathrs, please is there a way to analyse the closest subD vertex or add tolerance but **within the code**? sometimes it doesn’t detect some PC points? thank you!

---

<div class="post-metadata">

**Author:** ![Rh-3d-p](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/rh-3d-p/32/485582_2.png) [@Rh-3d-p](https://discourse.mcneel.com/u/Rh-3d-p)\
**Post date:** [April 3, 2022, 4:29pm UTC](https://discourse.mcneel.com/t/subd-edge-vertex-tags-creasing-programmatically/125192/12 "2022-04-03T16:29:16Z")

</div>

hi @lasathrs@silvano in this example the First SubD make Inset but the Corner Point in your Script doesn’t work to result SubD

 ![cornerPoint](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/d/7/5/d754a6f376b77471caeae1090e97f08f2d50350e.jpeg)  
is there solution for it?  
[Crease Corner.gh](https://discourse.mcneel.com/uploads/short-url/sJgZWlwWiNrgRtIGGANlqbvEeBh.gh) (22.7 KB)

---

<div class="post-metadata">

**Author:** ![lasathrs](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/lasathrs/32/493665_2.png) [@lasathrs](https://discourse.mcneel.com/u/lasathrs)\
**Post date:** [April 4, 2022, 9:08am UTC](https://discourse.mcneel.com/t/subd-edge-vertex-tags-creasing-programmatically/125192/13 "2022-04-04T09:08:41Z")

</div>

I updated the little script to include tolerance, I tested it and it works for the one point but you might need to adjust your SubD a little  
[Crease Corner\_LS.gh](https://discourse.mcneel.com/uploads/short-url/7uMM0xFsvrWWSOfljAbGnwzGGI0.gh) (21.7 KB)

---

<div class="post-metadata">

**Author:** ![Rh-3d-p](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/rh-3d-p/32/485582_2.png) [@Rh-3d-p](https://discourse.mcneel.com/u/Rh-3d-p)\
**Post date:** [April 6, 2022, 7:19am UTC](https://discourse.mcneel.com/t/subd-edge-vertex-tags-creasing-programmatically/125192/14 "2022-04-06T07:19:29Z")

</div>

hi @lasathrs Thanks’ ;; @Mahdiyar  
i Think for Best Result To CreaseSubd Need `EdgeTag` and `VertexTag` together  
i Try it But Not results Yet

 ![cornerPoint](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/1/b/1/1b1fdb75e58b4c6112757042320489a098ec94b1.jpeg)

[Crease Corner\_LS-Rev 2.gh](https://discourse.mcneel.com/uploads/short-url/eitue4DhKmiITfcVhQuFe40bFXe.gh) (23.2 KB)

```auto
private void RunScript(SubD S, List<Point3d> PC, double T, string EdgeTag, ref object SO, ref object B)
  {
    SubDVertex sv = S.Vertices.First;
    var eg = S.Edges.First();
    for(int i = 0; i < S.Vertices.Count; i++)
    {
      if(i != 0)
      {
        sv = sv.Next;
      }
      if(PC.Exists(x => sv.ControlNetPoint.DistanceTo(x) < T))
      {
        sv.Tag = SubDVertexTag.Corner;
        eg.Tag = SubDEdgeTag.Crease;
      }
    }
    S.ClearEvaluationCache();
    S.UpdateAllTagsAndSectorCoefficients();

    SO = S;
    B = eg.GetType();}

```

in fact what’s the entrance EdgeTag?  
have you any Suggestions?
