A quick Question about rs.redraw(bool)

HI all, i’m beginner of python, i want to know how to left the final object only, i don’t need to draw any object in process.
as my code :
=====code start=====
import rhinoscriptsyntax as rs

wt = 15
pts = rs.GetPoints(True, True, “start point”, “next point”)
pl = rs.AddPolyline(pts)

plE = rs.OffsetCurve(pl,[0,0,0],(wt/2),None, 1)
plI = rs.OffsetCurve(pl,[0,0,0],(-1*wt/2),None, 1)
PL = [plE, plI]
base = rs.AddLoftSrf(PL, loft_type=2)
edge = rs.DuplicateEdgeCurves(base, False )
outline = rs.JoinCurves(edge, delete_input=True, tolerance=None)
srf = rs.AddPlanarSrf(outline)

=====code end=====

as my question, the code what i want is “srf” although i tried rs.deleteObject() and its worked in this simple code , but i want to know any idea about how to draw the final object “srf” only, do not draw the object in process.

thanks for help.

Well, in order to create “intermediate” construction geometry like curves and surfaces without actually adding them to the document and having to delete them later requires going a level deeper than rhinoscriptsyntax - you have to use some RhinoCommon.

Most rhinoscriptsyntax methods - which are in fact routines written RhinoCommon - take inputs of object id’s of objects that already exist in the document and they output new object ids after having written these to the document as well. This is simply how it is designed to work.

Since you said you’re a beginner, I would suggest you continue to work with with rhinoscriptsyntax until you are more familiar with it. RhinoCommon is quite a bit more complicated and the help/api guides are designed for someone who understands object oriented programming.

As per your code above, I’m not quite sure what you want the result to be, but there are some improvements you can make. First, to post code here, you can make it more readable/usable with the proper code formatting:

```python (three backticks)
<paste your entire code in here>
That way it will be formatted correctly with indents, etc. and thus be more readable plus being able to be copied/pasted elsewhere to test.

It seems like you want to have the planar surface between the two offset curves as a result - if not please reply with a correction. If that is the case, your code could look like this:

import rhinoscriptsyntax as rs

wt = 15
pts = rs.GetPoints(True, True, "start point", "next point")
pl = rs.AddPolyline(pts)

plE = rs.OffsetCurve(pl,[0,0,0],(wt/2),None, 1)
plI = rs.OffsetCurve(pl,[0,0,0],(-wt/2),None, 1)
#both of the above might be more than one curve, output is a list.
#Assuming that it is only one curve, you can use plE[0] and plI[0]


#Use rs.DuplicateSurfaceBorder to get loft borders

#simply add the planar surface using the list of borders
srf = rs.AddPlanarSrf(bords)

#delete the construction objects

You do not need to code the rs.EnableRedraw(True) at the end in a python script, it is automatically executed when the script ends.

Now, if you wanted to try to do this without adding the polyline or the offset curves to the document and deleting them later, it gets quite a bit more complex:

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino

#scriptcontext is the bridge between RhinoCommon virtual geometry and document
#Rhino represents the whole of RhinoCommmon

wt = 15
pts = rs.GetPoints(True, True, "start point", "next point")

#for many methods, you need to supply a tolerance

#create a 'virtual' polyline curve

#try to get the curve plane for the offset

#or, get the active construction plane:

#you need to supply a cornerstyle for Offset

#create the offsets
#both of the above might be more than one curve, output is a list.
#Assuming that it is only one curve, you can try this:

#Loft without end points needs this:
#Plus a loft type
#create loft surface

#assuming it is one polysurface, use loft_list[0], get edges:

#join the edges
#this will be a list of joined edge curves

#finally, create your planar surface

#the result could be several surfaces, so output is a list
#add them to the document in a loop
for brep in breps: sc.doc.Objects.AddBrep(brep)

#redraw the scene (this is not automatic)

In all of the above, I have not done any error checking or anything like that. This is also important so that the script doesn’t fail with an error message if the input cannot be used to make what you want.

1 Like

Thanks for your help, it’s helpful to me, this almost answer lot of question that I’m confusing now.
Can I understand rhinoscriptsyntax and RhinoCommon in this way?

As you said, seems rhinoscriptsyntax methods is closer to modeling in rhino and it will create each item from my script so I need to delete that; RhinoCommon is such like processed in the script so I just need to define what item should be showing up when the code is ending, and in efficacy wise, RhinoCommon should be better than rhinoscriptsyntax right?

anyway, thanks for your suggestion to me, it good reminder for any bigginger.

Yes, more or less. Rhinoscriptsyntax is the closest to running native Rino commands, but it is still one level down in that in general the methods are more basic, cover fewer options/cases, don’t have much error checking and lack all the user interaction and on-screen previews that native Rhino commands have. As I said above, rhinoscriptsyntax is just a set of routines that call RhinoCommon code underneath.

Here is rhinoscriptsyntax GetPoint():

rs.GetPointGetPoint(message=None, base_point=None, distance=None, in_plane=False)

Here is the RhinoCommmon code it calls:

def GetPoint(message=None, base_point=None, distance=None, in_plane=False):

    gp = Rhino.Input.Custom.GetPoint()
    if message: gp.SetCommandPrompt(message)
    base_point = rhutil.coerce3dpoint(base_point)
    if base_point:
        if distance: gp.ConstrainDistanceFromBasePoint(distance)
    if in_plane: gp.ConstrainToConstructionPlane(True)
    if gp.CommandResult()!=Rhino.Commands.Result.Success:
        return scriptcontext.errorhandler()
    pt = gp.Point()
    return pt

15 lines of code instead of one…

RhinoCommon is the next level ‘down’ into the heart of Rhino and allows you access to far more core functions and options than rhinoscriptsyntax - but that at the expense of really understanding the complexities of how to program it. It does allow you to create and use ‘virtual’ geometry, which is not added to the document - as writing time for objects can be long compared to the actual calculation process, it can run faster, especially if you have a lot (thousands) of objects. For only a few, you probably will not notice a difference. The advantage of using virtual geometry is also that if the user aborts or there is an error, the construction objects are not left ‘stuck’ in the document. But all that comes at the expense of more knowledge and writing of much more code.

1 Like

OK, I got it, I will start from rhinoscriptsyntax first as you suggested, but I’m interesting to code in
RhinoCommon for the same goal too.
Thanks for the explanation, I will keep practicing on it.