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”)
rs.EnableRedraw(False)
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)
rs.DeleteObject(pl)
rs.DeleteObjects(PL)
rs.DeleteObjects(edge)
rs.DeleteObjects(outline)
rs.DeleteObject(base)
rs.EnableRedraw(True)

=====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")
rs.EnableRedraw(False)
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]

base=rs.AddLoftSrf([plE[0],plI[0]],loft_type=2)

#Use rs.DuplicateSurfaceBorder to get loft borders
bords=rs.DuplicateSurfaceBorder(base,0)

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

#delete the construction objects
rs.DeleteObjects([pl,plE,plI,base])
rs.DeleteObjects(bords)

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
tol=rs.UnitAbsoluteTolerance()

#create a 'virtual' polyline curve
pl=Rhino.Geometry.PolylineCurve(pts)

#try to get the curve plane for the offset
rc,plane=pl.TryGetPlane(tol)

#or, get the active construction plane:
plane=rs.ViewCPlane()

#you need to supply a cornerstyle for Offset
cs=Rhino.Geometry.CurveOffsetCornerStyle.Sharp

#create the offsets
offsetsE=pl.Offset(plane,wt/2,tol,cs)
offsetsI=pl.Offset(plane,-wt/2,tol,cs)
#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:
plE=offsetsE[0]
plI=offsetsI[0]

#Loft without end points needs this:
us_pt=Rhino.Geometry.Point3d.Unset
#Plus a loft type
lt=Rhino.Geometry.LoftType.Straight
#create loft surface
loft_list=Rhino.Geometry.Brep.CreateFromLoft([plE,plI],us_pt,us_pt,lt,False)

#assuming it is one polysurface, use loft_list[0], get edges:
edges=loft_list[0].DuplicateNakedEdgeCurves(True,True)

#join the edges
joined=Rhino.Geometry.Curve.JoinCurves(edges)
#this will be a list of joined edge curves

#finally, create your planar surface
breps=Rhino.Geometry.Brep.CreatePlanarBreps(joined,tol)

#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)
sc.doc.Views.Redraw()

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:
        gp.DrawLineFromPoint(base_point,True)
        gp.EnableDrawLineFromPoint(True)
        if distance: gp.ConstrainDistanceFromBasePoint(distance)
    if in_plane: gp.ConstrainToConstructionPlane(True)
    gp.Get()
    if gp.CommandResult()!=Rhino.Commands.Result.Success:
        return scriptcontext.errorhandler()
    pt = gp.Point()
    gp.Dispose()
    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.