Grasshopper

algorithmic modeling for Rhino

Hello,

I am trying to automate a simulation and optimization workflow to generate and test artificial coral reef structures. I am trying to adapt a Rhino Python script that I found here:

http://golancourses.net/2013/projects/study-for-biomimetic-heat-sin...

https://github.com/jlopezbi/DLA_heatSink/

This script uses diffusion-limited aggregation to simulate coral growth from a seed mesh. The parameters, such as the size, speed and number of particles, are hard coded into the original script, but I will be modifying them in grasshopper, writing them into a text file, and parsing that file in my modified DLA script each time I run the simulation. I will then reference each generated coral mesh back into Grasshopper, analyze it's structural performance (among other metrics) using Karamba, and optimize using Galapagos.

I am relatively new to Python scripting though, and I am having a bit of trouble modifying the method for referencing the seed mesh. In the original script, the author does this with the following line:

rc, objRef = Rhino.Input.RhinoGet.GetOneObject("select seedMesh",False,filter)

This prompts me to select a mesh in Rhino, and it returns an ObjRef object. In order to automate the process, I will need to select the mesh another way. At the moment I am trying to use scriptcontext.docs.Objects.FindByLayer to select the mesh, and that seems to be working. However, in order to get the rest of the script to work I believe I still need an object reference. I am trying to use Rhino.DocObjects.ObjRef(RhinoObject), but when I pass in the mesh I get a message that says "'ObjRef' object is not iterable". Can anybody help me understand what is going on, or point me to a better way to do what I need? I have attached the original script, my edited version, and the Rhino file below.

Best regards,

Bill Bodell

Views: 2019

Attachments:

Replies to This Discussion

Bill,

I don't think you need the objRef as you're now using the 'FindByLayer' method.

You will need to filter everything separately though as the 'FindByLayer' method doesn't have a filter variable and will simply collect everything based on the layer name you give it. Further, the method collects 'Rhino.DocObjects.MeshObjects' as opposed to a 'Rhino.DocObjects.ObjectType.Mesh'. To get the mesh from a mesh object you can use 'MeshObject.Geometry'.

I've used  a list comprehension below to filter out the meshes from your layer but it should work.

import Rhino
import scriptcontext as sc

layername = """Insert layer name here."""

layerobjs = sc.doc.Objects.FindByLayer(layername)
meshes = [mesh.Geometry for mesh in layerobjs if type(mesh) == Rhino.DocObjects.MeshObject]

For clarity the list comprehension is the same as the following, just more 'pythonic':

meshes = []

for obj in layerobjs:

    if type(obj) == Rhino.DocObjects.MeshObject:

        meshes.append(obj.Geometry)

Good luck.

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service