arghhhh!!!
i need help…
i post my script below, but can you explain me why that de preview doesn’t refresh when i change option,
i think it is when i update the stamp, i need to initialize the self.m_curve.DuplicateCurve()
.
no?
# coding: utf-8
import Rhino
from math import radians
import scriptcontext as sc
import System
def make_symbol(rot,sens):
try:
rotation=rot.CurrentValue
except:
rotation=rot
try:
sensp=sens.CurrentValue
except:
sensp=sens
points = []
if sensp:
points.append(Rhino.Geometry.Point3d(0.0, 5.0, 0.0))
points.append(Rhino.Geometry.Point3d(-5.0, 0.0, 0.0))
points.append(Rhino.Geometry.Point3d(-2.0, 0.0, 0.0))
points.append(Rhino.Geometry.Point3d(-2.0, -5.0, 0.0))
points.append(Rhino.Geometry.Point3d(2.0, -5.0, 0.0))
points.append(Rhino.Geometry.Point3d(2.0, 0.0, 0.0))
points.append(Rhino.Geometry.Point3d(5.0, 0.0, 0.0))
points.append(Rhino.Geometry.Point3d(0.0, 5.0, 0.0))
else:
points.append(Rhino.Geometry.Point3d(0.0, 1.0, 0.0))
points.append(Rhino.Geometry.Point3d(-2.5, 0.0, 0.0))
points.append(Rhino.Geometry.Point3d(-1.0, 0.0, 0.0))
points.append(Rhino.Geometry.Point3d(-1.0, -5.0, 0.0))
points.append(Rhino.Geometry.Point3d(1.0, -5.0, 0.0))
points.append(Rhino.Geometry.Point3d(1.0, 0.0, 0.0))
points.append(Rhino.Geometry.Point3d(2.5, 0.0, 0.0))
points.append(Rhino.Geometry.Point3d(0.0, 1.0, 0.0))
if rotation == 0:
pline = Rhino.Geometry.Polyline(points)
return pline.ToPolylineCurve()
elif rotation == 1:
pline = Rhino.Geometry.Polyline(points)
#Rform=Rhino.Geometry.Transform.Rotation(Rhino.Geometry.Vector3d(1,0,0),Rhino.Geometry.Vector3d(0,1,0),Rhino.Geometry.Point3d(0,0,0))
Rform=Rhino.Geometry.Transform.Rotation(radians(90),Rhino.Geometry.Point3d(0,0,0))
pline.Transform(Rform)
return pline.ToPolylineCurve()
elif rotation == 2:
pline = Rhino.Geometry.Polyline(points)
#Rform=Rhino.Geometry.Transform.Rotation(Rhino.Geometry.Vector3d(1,0,0),Rhino.Geometry.Vector3d(-1,0,0),Rhino.Geometry.Point3d(0,0,0))
Rform=Rhino.Geometry.Transform.Rotation(radians(180),Rhino.Geometry.Point3d(0,0,0))
pline.Transform(Rform)
return pline.ToPolylineCurve()
elif rotation == 3:
pline = Rhino.Geometry.Polyline(points)
#Rform=Rhino.Geometry.Transform.Rotation(Rhino.Geometry.Vector3d(1,0,0),Rhino.Geometry.Vector3d(0,-1,0),Rhino.Geometry.Point3d(0,0,0))
Rform=Rhino.Geometry.Transform.Rotation(radians(270),Rhino.Geometry.Point3d(0,0,0))
pline.Transform(Rform)
return pline.ToPolylineCurve()
class get_symbol_point(Rhino.Input.Custom.GetPoint):
def __init__(self):
self.rotation=0
self.sens=True
self.m_curve = make_symbol(self.rotation,self.sens)
self.m_xform = Rhino.Geometry.Transform.Identity
def CalculateTransform(self, point):
xform = Rhino.Geometry.Transform.Identity
dir = point - Rhino.Geometry.Point3d.Origin
if (not dir.IsTiny()):
xform = Rhino.Geometry.Transform.Translation(dir)
return xform
def OnMouseMove(self, e):
self.m_xform = self.CalculateTransform(e.Point)
GetPoint.OnMouseMove(self, e)
def MaJSymbol(self,rot,sens):
self.m_curve = make_symbol(self.rotation,self.sens)
def OnDynamicDraw(self, e):
curve = self.m_curve.DuplicateCurve()
curve.Transform(self.m_xform)
e.Display.DrawCurve(curve, System.Drawing.Color.Red)
GetPoint.OnDynamicDraw(self, e)
def test_place_symbol():
if sc.sticky.has_key('rotation'):
rotcurrentvalue=sc.sticky['rotation']
else:
rotcurrentvalue=0
if sc.sticky.has_key('sens'):
senscurrentvalue=sc.sticky['sens']
else:
senscurrentvalue=True
gp = get_symbol_point()
gp.SetCommandPrompt("Symbol location")
rot = Rhino.Input.Custom.OptionInteger(rotcurrentvalue, 0, 3)
sens = Rhino.Input.Custom.OptionToggle(senscurrentvalue, "devant", "derrière")
gp.AddOptionInteger("Rotation",rot)
gp.AddOptionToggle("Sens_Coupe",sens)
while True:
gp.Get()
if gp.CommandResult() == Rhino.Commands.Result.Cancel:
return
res=gp.Result()
if res==Rhino.Input.GetResult.Option:
gp.MaJSymbol(rot,sens)
else:
xform = gp.CalculateTransform(gp.Point())
curve = make_symbol(rot,sens)
curve.Transform(xform)
sc.doc.Objects.AddCurve(curve)
sc.doc.Views.Redraw()
if( __name__ == "__main__" ):
test_place_symbol()