This works fine if the file is an stl file. But if it is a ply file then the Foot variable doesn’t get populated with the mesh of the ply file. What is the proper way to get the mesh data of a ply file?
import System
import Rhino
import scriptcontext as sc
def test_import_ply():
path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop)
filename = System.IO.Path.Combine(path, "test.ply");
filename = chr(34)+ filename + chr(34) # double-quote
# Get the runtime serial number of the next Rhino Object that will be created
start_sn = Rhino.DocObjects.RhinoObject.NextRuntimeSerialNumber
Rhino.RhinoApp.RunScript("_-import " + filename + " _weld=_yes _weldangle=22.5 _splitdisjointmeshes=_yes _modelunits=_millimeters _enter", True)
# Get the runtime serial number of the next Rhino Object that will be created
end_sn = Rhino.DocObjects.RhinoObject.NextRuntimeSerialNumber
rh_objects = []
for sn in range(start_sn, end_sn):
rh_obj = sc.doc.Objects.Find(sn)
if rh_obj:
rh_objects.append(rh_obj)
for rh_obj in rh_objects:
print(rh_obj.ObjectType)
if __name__ == "__main__":
test_import_ply()
What’s curious about my code is that the variable foot does get populated with faces and vertices. I just can’t add the mesh to the document. I even tried creating a new mesh and copying over the vertices and faces and computing normals and compacting but I still can’t add the mesh to the document.
I tried to get your method going. I’m working in VB.net and normally I can use a code converter, but for some reason converters aren’t doing a good job in this case. And I don’t quite understand what you are doing enough to write it myself. I think you have an array of meshes that somehow get appended to a new mesh… Any chance you could write this in VB.net for me?
I have the mesh object and I can do operations on it, like intersect a plane with it to get polylines. The odd thing though is that if I try to add it back to the doc, nothing happens.
Dim TestMesh = TryCast(doc.Objects.Find(rh_objects(0).Id).Geometry, Mesh)
doc.Objects.AddMesh(TestMesh)
That code does not add a mesh to the doc, despite the fact that I can take that TestMesh and get a list of vertices, do intersections, etc…