Anyway to edit the control point directly?

Hi Guys!
I’m trying to edit the control point of NURBS and T-spline directly by script.
For example, changing n th control point to a specific coordinate i want.
Is there any way to do it?

THX

@ayoshi, i asume you’re using python.

You can change control points (grips) of NURBS surfaces using a script. Below is a simple example changing the first control point (the grip with index = 0) of a surface by adding a value of 10.0 units to the z coordinate:

import rhinoscriptsyntax as rs
    
srf = rs.GetObject("Select surface", rs.filter.surface)
if srf:
    rs.EnableObjectGrips(srf)
    grip_index = 0
    point = rs.ObjectGripLocation(srf, grip_index)
    
    point[0] = point[0] 
    point[1] = point[1]
    point[2] = point[2] + 10.0
    
    rs.ObjectGripLocation(srf, grip_index, point)
    rs.EnableObjectGrips(srf, False)

c.

1 Like

Not directly related to this topic, but is it possible to “lock screen” while manipulating the objects? (I have a case where I need to do many dirty tricks as to find out next coordinates etc, and I’d like to hide what the code does during execution).

// Rolf

Hi Rolf,

normally you can use this to disable the viewport redraw:

rs.EnableRedraw(False)

and set it to True after you’re done. But the problem with some of the rs methods is often that they envoke a view refresh once they are done. In this case the method used above:

rs.ObjectGripLocation(srf, grip_index, point)

redraws the viewport after every call. There are ways around it, eg. using:

rs.ObjectGripLocations(srf, points)

which allows to pass multiple point locations and redraws only once after they where changed. Note that the number of points passed here has to be equal to the number of grips.

Alternatively you can use RhinoCommon to change an objects grip location like so:

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs
...
# convert surface to rhino object
rhobj = rs.coercerhinoobject(srf, True, True)

# get the grip objects
grips = rhobj.GetGrips()

# change a grip location
grips[grip_index].CurrentLocation = point

# update the object and redraw
scriptcontext.doc.Objects.GripUpdate(rhobj, True)
scriptcontext.doc.Views.Redraw()

c.

Thanks @clement, I think EnableDraw will do in my case because I wouldn’t change the object until I have figured out all the point locations (It is all the tricks before that very change that causes updates & flickering).

Possibly also other commands will redraw without giving the option to disable it, but so be it.

I will try using Python to start with (newbie on both Rhino & Python). Hopefully I can call python scripts from my own html dialogs? (or does that work only for VBScripts?)

// Rolf

@RIL, if you mean rs.HtmlBox() to create the html based dialog, that is not yet implemented in python rhinoscript, so yes it only runs from VBScripts.

Using Python scripting it is easier to create dialogs through WinForms or maybe ETO if it has to run cross platform…

c.

Arghhh. Wasn’t that what I suspected…

Could you point me to some info about how to get started with WinForms or ETO in context of Rhino? (what is ETO btw? :slight_smile: )

// Rolf

You might check out this for info on how to build dialogs with WinForms using a visual editor like SharpDevelop.

For ETO there is only a small amount of python examples yet…

c.

Many thanks, I’ll have a look at SharpDevelop (I have only used Delphi 4–XE5 before).

// Rolf

Thank you @clement !
That’s what I wanted to know.
You made my day.

ayoshi

The methods in the py script library should have had an optional parameter to suppress redraw, like so (copied from the py library)

def ObjectGripLocation(object_id, index, point=None, redraw=True):
"""Returns or modifies the location of an object's grip
Parameters:
  ...
  redraw [opt] = Set to False will suppress redraw (Default=True)

do you think that there’s any chance that the script library would ever be updated with this kind of changes?

// Rolf

Hi Rolf,

2 thing to consider:

You can wrap your code inbetween EnableRedraw methods to disable all redrawing like so:


rs.EnableRedraw(False)

foo = runcodehere()
bar = prosess(foo)
create_geometry(bar)

rs.EnableRedraw(True)

Yet there when you script commands you will at least get Commandline feedback (= flickering)
There is an option to not echo on the commandline, but some commands will still create commandline updates.

rs.Command(command_string, echo=False)

HTH
-Willem