Transforming seperate objects using Display Conduit


I am attempting to use the Display Conduit to load several mesh objects from separate .3dm files. Once loaded I would like to apply different transformations to each of the mesh objects then display them. I have started with and an example script from @Mk​MrA​2

import rhinoscriptsyntax as rs
import scriptcontext
import Rhino
import System
import System.Drawing
import time

def Main():
    # The 3dm file to open and read
    pathname = "C:\Test_Box.3dm"
    # Open it and get the objects
    drawObjs = Load3DMFile(pathname)
    # Make the display conduit object for drawing
    dc = DisplayConduit(drawObjs)
    for i in range(Rotate):
        # Draw
        dc.xform = Xform
        dc.Enabled = True
    # Stop drawing
    dc.Enabled = False
    print "Display Frames/Second: "+str((end-start)/Rotate)

# Read the 3dm file and return a list of the objects within it
def Load3DMFile(pathname):
    f3dm = Rhino.FileIO.File3dm.Read(pathname)
    if (f3dm):
        objs = f3dm.Objects
        return objs

# Display Conduit class to draw in the viewports
class DisplayConduit(Rhino.Display.DisplayConduit):
    def __init__(self, objs):
        # Store the objects we are to draw
        self.drawObjs = objs
        print self.drawObjs
        # Store the transformation to apply - initially none
        self.xform = Rhino.Geometry.Transform.Identity
        # Get the bounding box for all the objects passed
        self.drawObjsBBox = Rhino.Geometry.BoundingBox(Rhino.Geometry.Point3d(-1,-1,-1), Rhino.Geometry.Point3d(1,1,1))
        for item in self.drawObjs:
            bbox = item.Geometry.GetBoundingBox(False)
            if (bbox):
        # Expand the bbox by 5% of the diagonal length for use in zoom extents
        amount = self.drawObjsBBox.Diagonal.Length*0.05
        # Init the material to draw with
        self.material = Rhino.Display.DisplayMaterial()
        self.material.Diffuse = System.Drawing.Color.OrangeRed # Kuka robot color!
        self.material.Shine = 0.8
    # Called to quickly return the bounding box for the scene including our objects
    def CalculateBoundingBox(self, calculateBoundingBoxEventArgs):
    # Called to quickly return the zoom extents bounding box including our objects
    def CalculateBoundingBoxZoomExtents(self, calculateBoundingBoxEventArgs):
    # Called to draw the objects to the viewport. This is done before any Rhino
    # objects which will be drawn over ours.
    def PreDrawObjects(self, drawEventArgs):
        drawEventArgs.Display.DrawBox(self.drawObjsBBox, System.Drawing.Color.White)
        drawEventArgs.Display.PushModelTransform(self.xform) # Apply the transform
        for item in self.drawObjs:
            if item.Geometry.ObjectType == Rhino.DocObjects.ObjectType.Curve:
                drawEventArgs.Display.DrawCurve(item.Geometry, System.Drawing.Color.Green)
            elif item.Geometry.ObjectType == Rhino.DocObjects.ObjectType.Brep:
                drawEventArgs.Display.DrawBrepWires(item.Geometry, System.Drawing.Color.Red)
            elif item.Geometry.ObjectType == Rhino.DocObjects.ObjectType.Mesh:
                #drawEventArgs.Display.DrawMeshWires(item.Geometry, System.Drawing.Color.Blue)
                drawEventArgs.Display.DrawMeshShaded(item.Geometry, self.material)
            elif item.Geometry.ObjectType == Rhino.DocObjects.ObjectType.Point:
                drawEventArgs.Display.DrawPoint(item.Geometry.Location, System.Drawing.Color.White)
        drawEventArgs.Display.PopModelTransform() # Remove the transformation

# Run it...
if (__name__ == "__main__"):

I can load multiple files using Rhino.FileIO.File3dm.Read(file).Objects
But I am unsure how I might go about applying separate transformation matrices to each loaded mesh (say to rotate on clockwise and one counter clockwise). This seems like this should be possible using the display conduit but I have not been able to decipher a solution from the documentation.

If anyone has any advice on this subject I would greatly appreciate it.

Test_Box.3dm (46.4 KB) (3.5 KB)

Old topic, but the way we solve this is to store each mesh individually on import as an object, with an xform property. As we calculate the transforms we store them. Then we push, draw, pop inside a loop through all those objects. Its fast, even with hundreds of meshes(with thousands of faces). Would love to hear ways to make it faster, as we always want to be faster…

Does my updated version of your script help any? (3.7 KB)