Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 5938

Scripting Cage_Edit function

$
0
0

Hello everyone,

I’m currently working on a problem related to automated surface deformation in Rhino.

Initially, I developed a Grasshopper model to achieve this, but I wasn’t completely satisfied with the result since it was essentially based on the surface control points that I wanted to modify.

To improve this deformation model, I’d like to use Rhino’s _CageEdit function in a Python script running in Rhino. The problem I’m currently having is that once the geometry has been deformed by the _CageEdit function, I can’t get it back into the Rhino file, to export it for example. I seem to have to commit it after deforming it. The deformed geometry is visible as a gauge in Rhino’s graphical interface (see Photo), but it disappears as soon as I press ESC or anything else.

So I’d like to know how to “commit” or “Bake” the surface I’ve just modified?

You’ll see my current script down below.

Thanks in advance for your feedback,

Best regards,

Etienne

# -*- coding: utf-8 -*-
import rhinoscriptsyntax as rs
import Rhino
from Rhino import Geometry as rg
import scriptcontext as sc
import math as m

# There is only one geometry in my .3dm file
objects = rs.AllObjects()
if not objects:
    print("No object found")
surface_guid= objects[0] # Pick the one and only geometry

# Select the surface
rs.SelectObject(bateau_guid)
# CageEdit set up
cmd = '_CageEdit \n _B \n G \n _Enter \n _G \n'
rs.Command(cmd, echo=True)
cage_ids=rs.LastCreatedObjects()
cage_id=cage_ids[0]

rh_obj = rs.coercerhinoobject(cage_id)
if not rh_obj:
    print("Impossible to convert the cage in rhicommon object")
    exit()
# Step 5 : Enable grips
rh_obj.GripsOn = True

# Select grips
grips = rh_obj.GetGrips()
# Move grips (example : vec(200,100,0))
for grip in grips:
    grip.Move(Rhino.Geometry.Vector3d(200, 100, 0))

2 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 5938

Trending Articles