Pycad ,使用定时器实现旋转圆
本帖最后由 枫叶棋语 于 2023-7-21 20:43 编辑from math import pi
from time import time
import System.Windows.Forms as Winforms
def Polar(center: Point3d, angle: float, distance: float):
import math
v1 = Vector3d(distance, 0, 0)
v1 = v1.RotateBy(angle * math.pi / 180, Vector3d.ZAxis)# 将角度转换为弧度
return center + v1
def muti_polar (cir: Entity,center:Point3d,angle: float):
import math
matrix =Matrix3d.Rotation(angle=angle*180/math.pi,axis=Vector3d.ZAxis,center=center)
cir.TransformBy(matrix)
@Command(lock= False)
def ts01(doc:Document):
res = getpoint()
if not res.ok:
return
center = res.value
angle_list =
pts =
cir_ids = []
color =1
with dbtrans(doc) as tr:
btr = tr.opencurrspace()
for x in pts :
cir:Entity =Circle()
cir.Center =x
cir.Radius =20
cir.ColorIndex =color
color +=1
tr.addentity(btr,cir)
tr.flush(cir)
cir_ids.append(cir.ObjectId)
T0 =time()
timer =Winforms.Timer()
def on_timer_tick(sender,event):
doc:Document =Application.DocumentManager.MdiActiveDocument
with doc.LockDocument():
with dbtrans (doc)as tr:
try:
T1 =time()
if T1 -T0 >20:#5秒后结束定时器
timer.Stop()
timer.Dispose()
for objid in cir_ids:
cir = tr.getobject(objid,OpenMode.ForWrite)
muti_polar(cir,center,10)
tr.flush(cir)
except Exception as ex:
prinf (ex.Message)
timer.Stop()
timer.Dispose()
timer =Winforms.Timer()
timer.Interval =50
timer.Tick += System.EventHandler(on_timer_tick)
timer.Start()
枫哥搞个动图看看呀 不错哦,{:1_1:}
页:
[1]