General Question: Please advice if I can keep coding in Python for what I would like to do

Hello,

I have picked up Python and have been writing some scripts for Rhino in the last few weeks and I really like how all works in Python.

I would like to ask what more experienced programmers think, if I can stay in Python (and not learn a new language) for the things I want to program.

I want to manipulate meshes.
Selecting vertices, edges, faces, mainly modifying the geometry based on criteria for each of the selections.

As an example, looking at this page (below), I see that under syntax, there is only C# and VB listed.
Is it possible to access these features with Python?

https://developer.rhino3d.com/api/RhinoCommon/html/T_Rhino_Geometry_Collections_MeshTopologyEdgeList.htm

What I would like to work on is create a set of tools for me, to help me manage very specific terrain and landscape design tasks. And so modify quite low definition meshes in specific ways to suit my design needs.
I am mixing design and art thinking here with my coding skills and I want to write something like an algorithm that will help aid and generate designs based on very specific meshes that I will create most likely in blender or perhaps 3ds max (as I already have good skills there) but from there to work entirely in Rhino.

Few examples of small tasks that I can think of at this initial stage:

  1. I would have data points of coordinates (locations) in 3d space. Take these coordinate datapoints, and to each, add a (spherical ?) bounding area. Then take a mesh and go through each edge. If both vertices of an edge fall within any two of the initial coordinate “spheres” then add these edges to an array that I can use to select them later.
    In short I am going to use one basic mesh to extract the datapoints and later use these points as a selection aid to apply to another mesh.

  2. If I do not have sufficient faces in some areas, can I easily use a selection of edges to split them the way “split a mesh edge” does (the sizzors icon).

Thanks for reading and for eventual input I might receive from this essay : )

Main question is if I can do all in Python.
Secondary would be any advice of where I can begin… the first 1, 2 things that will get me rolling with this.

Thanks

Hi qtov,

I think what you want is all possible, I started typing an example but had to stop early.
Below is an example of how to use the MeshTopologyEdgelist in Python.
Unfortunately that’s all I can do for now, Hope it helps:
-Willem

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino




def create_mesh_and_return_id():
    #crate boudningbox
    bbox = Rhino.Geometry.BoundingBox(-100,-100,-100,100,100,100)
    mesh_box = Rhino.Geometry.Mesh.CreateFromBox(bbox,10,10,10)
    mesh_id = sc.doc.Objects.AddMesh(mesh_box)
    rs.Redraw()
    return mesh_id



def main():
    
    #create a mesh and get the id typically whet you get when
    #selecting an object with rs.GetObject
    mesh_id = create_mesh_and_return_id()
    
    #get the mesh object from an id:
    mesh = rs.coercemesh(mesh_id)
    print 'mesh is: ',mesh
    #get the edgelist from the mesh
    edgelist = mesh.TopologyEdges
    
    
    test_point = Rhino.Geometry.Point3d(80,80,80)
    #create the point as reference
    sc.doc.Objects.AddPoint(test_point)
    
    MAXIMIM_DISTANCE = 50
    
    count = edgelist.Count
    for i in range(count):
        line = edgelist.EdgeLine(i)
        pt_s = line.From
        pt_e = line.To
        
        start_dist = rs.Distance(test_point,pt_s)
        end_dist = rs.Distance(test_point,pt_e)
        print 'start_dist,end_dist',start_dist,end_dist
        
        if start_dist < MAXIMIM_DISTANCE > end_dist:
            sc.doc.Objects.AddLine(line.From,line.To)
    
    #Delete The mesh
    rs.DeleteObject(mesh_id)
    

main()
1 Like

Hello Willem,

Thanks for taking the time to help out.

I run the example code you have written and this is great. Very good starting point and brings a lot of ideas about directions to research so I can expand and modify this.

If you don’t mind I might add additional and more specific questions as I go along.
Let’s see if I can manage this on my own : )

That’s what this forum is for!
Don’t hesitate to ask for help, note that the developers are active here as well, so any issue you run into can contribute to guide the developers as well in improving the software.

Just create a new topic for each issue, you’ll find the community is always willing to help.

Good luck!
-Willem

1 Like