I don't know when should I use rhinoscriptsyntax, scriptcontext and rhinocommand

In GH_Python, I used scriptcontext to create some geometry, and it would create geometry directly , means I had no need to bake it. I don’t know when should I use rhinoscriptsyntax, scriptcontext and rhinocommand.

import rhinoscriptsyntax as rs 
import random as rnd
import Rhino.Geometry as rg
import scriptcontext as sc

uinc = 1/unum
vinc = 1/vnum

panels = []
for i in range(unum):
    for j in range(vnum):
        vlen = rnd.randint(1,10)
        if j + vlen > vnum:
            vlen = vnum - j
        cpts = []
        depth = rnd.randint(0,1)
        for k in range(vlen+1):
             cpts.append(srf.PointAt(i*uinc, (j + k)*vinc))
             cpts.append(srf.PointAt((i+1)*uinc, (j + k)*vinc))
       panel = rg.NurbsSurface.CreateFromPoints(cpts,2,vlen+1,1,1)
       panels.append(panel)

        materialIndex = sc.doc.Materials.Add()
        material = sc.doc.Materials[materialIndex]
        material.DiffuseColor = sd.Color.FromArgb(i/unum*255, j/vnum*255, 0)
        material.CommitChanges()
        attr = rd.ObjectAttributes()
        attr.MaterialSource = rd.ObjectMaterialSource.MaterialFromObject
        attr.MaterialIndex = materialIndex

        panels.append(sc.doc.Objects.AddSurface(panel, attr))
         #rs.ObjectColor(rs.coercesurface(panel),sd.Color.FromArgb(i/unum*255, j/vnum*255, 0)

a=panels

Another question:
rs.ObjectColor(rs.coercesurface(panel),sd.Color.FromArgb(i/unum255, j/vnum255, 0))
After I added this line, why it told me that " Runtime error (TypeErrorException): iteration over non-sequence of type NurbsSurface"?

Thanks for your patience to explain these!

Hi Daizhuo,

Not answering your question but a tip on formatting Python scripts in a topic:

To have formatted script encapusulate it like so:

```python
 your code here
```

The code avove will look like this:

import rhinoscriptsyntax as rs 
import random as rnd
import Rhino.Geometry as rg
import scriptcontext as sc

uinc = 1/unum
vinc = 1/vnum

panels = []
for i in range(unum):
for j in range(vnum):
vlen = rnd.randint(1,10)
if j + vlen > vnum:
vlen = vnum - j
cpts = []
depth = rnd.randint(0,1)
for k in range(vlen+1):
cpts.append(srf.PointAt(i*uinc, (j + k)*vinc))
cpts.append(srf.PointAt((i+1)uinc, (j + k)vinc))
panel = rg.NurbsSurface.CreateFromPoints(cpts,2,vlen+1,1,1)
panels.append(panel)

    materialIndex = sc.doc.Materials.Add()
    material = sc.doc.Materials[materialIndex]
    material.DiffuseColor = sd.Color.FromArgb(i/unum*255, j/vnum*255, 0)
    material.CommitChanges()
    attr = rd.ObjectAttributes()
    attr.MaterialSource = rd.ObjectMaterialSource.MaterialFromObject
    attr.MaterialIndex = materialIndex

    panels.append(sc.doc.Objects.AddSurface(panel, attr))
     #rs.ObjectColor(rs.coercesurface(panel),sd.Color.FromArgb(i/unum*255, j/vnum*255, 0)

a=panels

Another question:

rs.ObjectColor(rs.coercesurface(panel),sd.Color.FromArgb(i/unum*255, j/vnum*255, 0))

As for the subject; I changed the category to Grasshopper Developer as there as specifics to handle scriptcontext from within GrassHopper. I’m not familiar enough with it to answer your question.

HTH
-Willem

Thank you so much!