+ Reply to Thread
Results 1 to 3 of 3

Thread: MeshClash results to Object User Text

  1. #1

    MeshClash results to Object User Text

    Hi All,

    I'm trying to store the results (IDs) from MeshClash as User Text (or Dictionary) to the MeshA Objects. Then I could easily analyze the clashes later with additional scripts. Below is a simple script.

    Actually I'm having problems to get the object IDs (so this must be a pretty dumb question

    Python Code:
      import rhinoscriptsyntax as rs
      import Rhino
       
      def clashtest():
          mesh_set1 = rs.GetObjects("First set of meshes", rs.filter.mesh)
          if not mesh_set1: return
          mesh_set2 = rs.GetObjects("Second set of meshes", rs.filter.mesh)
          if not mesh_set2: return
          # convert the Guids into actual RhinoCommon mesh objects
          mesh_set1 = [rs.coercemesh(m) for m in mesh_set1]
          mesh_set2 = [rs.coercemesh(m) for m in mesh_set2]
       
          distance = rs.GetReal("Distance to consider a clash", 0, 0)
          if distance is None: return
          clashes = Rhino.Geometry.Intersect.MeshClash.Search(mesh_set1,mesh_set2, distance, 0)
          if not clashes:
              print "no clashes"
          else:
              print len(clashes), "clashes detected"
              for clash in clashes:
                  point = clash.ClashPoint
                  rs.AddPoint(point)
                 
                  # How to assign the ID of MeshB as user text/dictionary to MeshA ??????
       
       
      if __name__=="__main__":
          clashtest()

    Thanks for any help!
    Jess

  2. #2
    Senior Member Steve Baer's Avatar
    Join Date
    Apr 2010
    Location
    Seattle
    Posts
    1,464
    Blog Entries
    19
    Hi Jess,
    I need to add a few things to RhinoCommon to make this work a little cleaner, but this should work for you for now
    Python Code:
      import rhinoscriptsyntax as rs
      import Rhino
       
      def clashtest():
          mesh_ids1 = rs.GetObjects("First set of meshes", rs.filter.mesh)
          if not mesh_ids1: return
          mesh_ids2 = rs.GetObjects("Second set of meshes", rs.filter.mesh)
          if not mesh_ids2: return
          # convert the Guids into actual RhinoCommon mesh objects
          meshes1 = [rs.coercemesh(m) for m in mesh_ids1]
          meshes2 = [rs.coercemesh(m) for m in mesh_ids2]
       
          distance = rs.GetReal("Distance to consider a clash", 0, 0)
          if distance is None: return
          clashes = Rhino.Geometry.Intersect.MeshClash.Search(meshes1, meshes2, distance, 0)
          if not clashes:
              print "no clashes"
          else:
              print len(clashes), "clashes detected"
              for clash in clashes:
                  point = clash.ClashPoint
                  rs.AddPoint(point)
                 
                  # How to assign the ID of MeshB as user text/dictionary to MeshA ??????
                  for i, mesh in enumerate(meshes2):
                      if clash.MeshB == mesh:
                          s = clash.MeshA.GetUserString("clash")
                          if len(s)>0: s = s + ", "
                          s = s + str(mesh_ids2[i])
                          clash.MeshA.SetUserString("clash", s)
                          break
       
       
      if __name__=="__main__":
          clashtest()

  3. #3
    Hi Steve,

    Thanks for your quick help! It got the job done

    Best,
    Jess

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts