RS : updating object mesh without redrawing screen?

In Rhinoscript - When Rhino.EnableRedraw = False, is it possible to update a new object’s display mesh without redrawing the screen (such as using Rhino.Redraw)? Thanks!

Rhino.Redraw does not always work either because the new RS-generated objects may not be visible in the viewport. I basically need to force a mesh generation without displaying it…

jonah

hi @jonah

The only thing I can think of is running Rhino.Command “_RefreshShade” with your objects selected.
It will NOT work while Rhino.EnableRedraw=False, but it will force to remesh selected objects if redraw is ON, even if the objects are not visible in any viewport. See below.

hth,

Jarek

Call Main()
Sub Main()

	Dim strObject
	strObject = Rhino.GetObject("Select object",, True)

	Rhino.EnableRedraw False

	Rhino.AddObjectMesh strObject, 1, True
	Rhino.ObjectMeshMaxAngle strObject, 30
	Rhino.ObjectMeshMinEdgeLength strObject, 50
	
	Rhino.SelectObject strObject
	Rhino.EnableRedraw True
	Rhino.Command "_RefreshShade"
	
End Sub

Thanks Jarek. I tried that already. But it only works work when the object is visible in at least one viewport. If you don’t mind to try this and tell me if it works : Maximize your viewport, pan the view so the origin is well outside of the view bounds. Create a small sphere (using keystrokes) at 0,0,0. Then run this script. It fails whether enabling a custom mesh or not. At least it fails for me… Also i would not be enabling redraw until several of these new objects have been created and hundreds of duplicates too. so if object has no mesh, of course i am delaying waiting for all children to create meshes…

Call Main()
Sub Main()

Dim strObject
strObject = Rhino.FirstObject

Rhino.EnableRedraw False

Rhino.AddObjectMesh strObject, 1, True
Rhino.ObjectMeshMaxAngle strObject, 30
Rhino.ObjectMeshMinEdgeLength strObject, 50

Rhino.SelectObject strObject

Rhino.Command "_RefreshShade"
Rhino.EnableRedraw True

End Sub

Hi Jonah,

You might try using Rhino.BoundingBox. For Breps, tight bounding boxes are calculated from their render meshes. So if you call the above method and the object does not have a render mesh, one will be calculated.

The same holds true of just scripting the BoundingBox command.

Does this help?

Hmm, you are right Jonah - it doesn’t seem to work here either.
@dale - when adding

Rhino.BoundingBox strObject

before RefreshShade command, command line reports Refreshed one object, but the mesh is still being regenerated only after the script is done/new object becomes visible in viewport. So no luck with this method I guess.

Perhaps I don’t understand what problem is trying to be solved. But try this:

1.) Start a new model and set all viewports to Wireframe display
2.) Run the script below
3.) Set one of the viewports to Shaded display

Notice how you do not see the Creating meshes... Press Esc to cancel message, and the viewport shades quickly.

Now, repeat the above steps but with the ‘’‘Call Rhino.BoundingBox(spheres)’’’ statement commented out. Notice how you (now) see the Creating meshes... Press Esc to cancel message, and the viewport does not shade as quickly.

Sub TestBoundingBox

  Dim spheres(), items, count, dir
  Dim x, y, z, vx, vy, vz, dx, dy, dz
  
  Call Rhino.EnableRedraw(False)
  
  items = 10:	count = 0
  
  ReDim spheres(items ^ 3 - 1)
  
  vx = Array(1, 0, 0): vy = Array(0, 1, 0): vz = Array(0, 0, 1)
  dx = 2:	dy = 2:	dz = 2
  
  spheres(count) = Rhino.AddSphere(Array(0, 0, 0), 0.5)
  
  For z = 0 To items - 1
    For y = 0 To items - 1
      For x = 0 To items - 1
        If Not (x = 0 And y = 0 And z = 0) Then
          dir = Array( _
            vx(0) * x + vy(0) * y + vz(0) * z, _
            vx(1) * x + vy(1) * y + vz(1) * z, _
            vx(2) * x + vy(2) * y + vz(2) * z)
          count = count + 1
          spheres(count) = Rhino.CopyObject(spheres(0), dir)
        End If
      Next
    Next
  Next
  
  ' This will force the creation of render meshes
  Call Rhino.BoundingBox(spheres)
  
  Call Rhino.EnableRedraw(True)

End Sub

Does this help?

1 Like

Dale - it works well over here ( no ‘Creating render meshes’ time/info - all taken care of withing script runtime before redraw). Good tip. Thanks.

–j

Perfect! Thanks! And not having the command line say “creating render meshes…” is really nice bonus too…