-
Notifications
You must be signed in to change notification settings - Fork 335
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
156a0e8
commit d191e16
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
################################################################################ | ||
# SampleMoveBrepEdge.py | ||
# Copyright (c) 2019 Robert McNeel & Associates. | ||
# See License.md in the root of this repository for details. | ||
################################################################################ | ||
import Rhino | ||
import scriptcontext as sc | ||
|
||
def SampleMoveBrepEdge(): | ||
go = Rhino.Input.Custom.GetObject() | ||
go.SetCommandPrompt("Select edge to move") | ||
go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve | ||
go.GeometryAttributeFilter = Rhino.Input.Custom.GeometryAttributeFilter.EdgeCurve | ||
go.Get() | ||
if go.CommandResult() != Rhino.Commands.Result.Success: return | ||
|
||
obj_ref = go.Object(0) | ||
edge = obj_ref.Edge() | ||
if not edge: return | ||
brep = edge.Brep | ||
if not brep: return | ||
|
||
rc, p0 = Rhino.Input.RhinoGet.GetPoint("Point to move from", False) | ||
if rc != Rhino.Commands.Result.Success: return | ||
|
||
gp = Rhino.Input.Custom.GetPoint() | ||
gp.SetCommandPrompt("Point to move to") | ||
gp.DrawLineFromPoint(p0, False) | ||
gp.Get() | ||
if gp.CommandResult() != Rhino.Commands.Result.Success: return | ||
|
||
dir = gp.Point() - p0 | ||
xform = Rhino.Geometry.Transform.Translation(dir) | ||
|
||
new_brep = brep.DuplicateBrep() | ||
edge_ci = brep.Edges[edge.EdgeIndex].ComponentIndex() | ||
list = [edge_ci] | ||
|
||
rc = new_brep.TransformComponent(list, xform, sc.doc.ModelAbsoluteTolerance, 0, False) | ||
if rc: | ||
sc.doc.Objects.Replace(obj_ref.Object().Id, new_brep) | ||
sc.doc.Views.Redraw() | ||
|
||
# Check to see if this file is being executed as the "main" python | ||
# script instead of being used as a module by some other python script | ||
# This allows us to use the module which ever way we want. | ||
if __name__ == "__main__": | ||
SampleMoveBrepEdge() # Call the function defined above |