两个造滑梯的skill脚本

1.作用:把矩形分割成两个相同的滑梯多边形

用法:在CIW窗口load RectChopToLadder.il脚本,然后用绑定的快捷键数字键盘5或者RectChopToLadder()或者RectChopToLadder(stepW stepH)来调用,默认stepW=5 stepL=1,用最后一种调用方法可以改stepW stepH。

这个脚本是借用一位叫“寻雨”坛友的代码,在他的代码基础上进行了一点点的升级改进,原代码来源于下贴的10楼:
https://bbs.eetop.cn/forum.php?m ... 61&pid=11213823
image

2.作用:创建电源线常用的梯形线
用法:在CIW窗口load CreatePowerLine.il脚本,然后用绑定的快捷键数字键盘8或者CreatePowerLineForm()来调用。
image
image
image

RectChopToLadder.il
/*
effect:Chopping the rectange to two ladders
write by:??? update by:fire
date:2024/5/21
version:1.0
*/

;Divide the rectangle into two ladders
;stepW:The width of the ladder
;stepH:The height of the ladder

procedure(RectChopToLadder(@optional (stepW 5) (stepH 1))
let((shapes bBox shapeH shapeW steps minLadderWidth firstPoint chopPoints P1 P2 lastPoint)
shapes=geGetSelSet()
foreach(shape shapes
if(shape!=nil&&shape~>objType=="rect" then
bBox=shape~>bBox
shapeH=yCoord(cadr(bBox))-yCoord(car(bBox))
shapeW=xCoord(cadr(bBox))-xCoord(car(bBox))
steps=round2((shapeW-stepW)/(stepW+stepH))
minLadderWidth=(shapeH-stepH*steps)/2
firstPoint=list(xCoord(car(bBox)) yCoord(car(bBox))+minLadderWidth)
chopPoints=nil
chopPoints=append1(chopPoints firstPoint)
for(n 1 steps
P1=list(xCoord(firstPoint)+stepW yCoord(firstPoint))
chopPoints=append1(chopPoints P1)
P2=list(xCoord(firstPoint)+stepW+stepH yCoord(firstPoint)+stepH)
chopPoints=append1(chopPoints P2)
firstPoint=P2
);end for
lastPoint=list(xCoord(cadr(bBox)) yCoord(P2))
chopPoints=append1(chopPoints lastPoint)
);end if
leChopShape(shape chopPoints nil nil 10)
);end foreach
);end let
);end procedure

hiSetBindKey("Layout" "KP_5" "RectChopToLadder()")

CreatePowerLine.il
/*
effect:Create the power line
write by:fire
date:2024/5/21
version:1.0
*/

procedure(CreatePowerLineForm()
let((wideEdgeField narrowEdgeField widthField autoField stepLengthField stepHeightField stepRadioField myColorArray iconString myIcon_fire iconField fields)
wideEdgeField=hiCreateFloatField(
?name 'wideEdgeField
?prompt "wide edge length"
?defValue 100.0
?range list(1.0 nil)
?focusInCallback "createPowerLineForm->wideEdgeField->range=list(createPowerLineForm->narrowEdgeField->value nil)"
)

narrowEdgeField=hiCreateFloatField(
    ?name 'narrowEdgeField
    ?prompt "narrow edge length"
    ?defValue 20.0
    ?range list(0 nil)
    ?focusInCallback "createPowerLineForm->narrowEdgeField->range=list(0 createPowerLineForm->wideEdgeField->value-createPowerLineForm->stepHeightField->value)"
)

widthField=hiCreateFloatField(
    ?name 'widthField
    ?prompt "width"
    ?defValue 100.0
    ?range list(0 nil)
    ?focusInCallback
	"if(createPowerLineForm->autoField->value==t then
	    createPowerLineForm->widthField->range=list(createPowerLineForm->wideEdgeField->value nil)
	else
	    createPowerLineForm->widthField->range=list(0 nil)
	)"
)

autoField=hiCreateBooleanButton(
    ?name 'autoField
    ?buttonText "automatic calculation?"
    ?callback "AutoField_CB()"
    ?defValue t
)

stepLengthField=hiCreateFloatField(
    ?name 'stepLengthField
    ?prompt "step length"
    ?defValue 5.0
    ?editable nil
)

stepHeightField=hiCreateFloatField(
    ?name 'stepHeightField
    ?prompt "step height"
    ?defValue 1.0
)

stepRadioField=hiCreateRadioField(
    ?name 'stepRadioField
    ?choices list("stepL" "stepH")
    ?defValue "stepH"
    ?callback list("StepRadioField_CB(1)" "StepRadioField_CB(2)")
)

myColorArray=hiCreateColorArray()
myColorArray[0]=hiMatchColorByName("yellow");a
myColorArray[1]=hiMatchColorByName("red");b
myColorArray[2]=hiMatchColorByName("pink");c
myColorArray[3]=hiMatchColorByName("green");d
iconString=
"ddddddddddddddaaaddddddddddddddddddddddddddddaaaaadddddddddddddd\
ddddddddddddaaaaaaaddddddddddddddddddddddddaaaabbaaadddddddddddd\
dddddddddddaaaabbaaaadddddddddddddddddddddaaabbbbaaaaadddddddddd\
dddddddddaaaabbbbbaaaaadddddddddaddddddddaaabbbbbbbaaaaddddddddd\
aadddddaaaabbbbbbbbbaaaaddddddddaaaddddaaabbbbbbbbbbbaaaaddddddd\
aaadddaaaabbbbbbbbbbbbaaaddddddaaaaaddaaabbbbbbbbbbbbbbaaaddddaa\
aaaaddaaabbbbbbbbbbbbbbbaaaddaaaaaaaadaaabbbbbbbbbbbbbbbbaadaaaa\
aabbaaaaabbbbbbbbbbbbbbbbaaaaaaaaabbaaaabbbbbbbbbbbbbbbbbaaaaaaa\
aabbbaaabbbbbbbbbbbbbbbbbbaaabaaaabbbbaabbbbbbbbbbbbbbbbbbaabbaa\
aabbbbbabbbbbbbbbbbbbbbbbbabbbaaaabbbbbbbbbb11bbbbbb11bbbbbbbbaa\
cabbbbbbbbbb11bbbbbb11bbbbbbbbaacaabbbbbbbbbbbbbbbbbbbbbbbbbbbac\
caabbbbbbbbbbbbbbbbbbbbbbbbbbaacccaabbbbbbbb1bbbbbbb1bbbbbbbbaac\
ccaabbbbbbbbb1bbbbb1bbbbbbbbaacccccaabbbbbbbbb11111bbbbbbbbbaccc\
cccaabbbbbbbbbbbbbbbbbbbbbaaccccccccaaaabbbbbbbbbbbbbbbbaaaccccc\
cccccaaaaaaaabbbbbbbaaaaaacccccccccccccaaaaaaaaaaaaaaaaacccccccc\
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"
myIcon_fire=hiStringToIcon(myColorArray iconString 32 32)
iconField=hiCreateLabel(
    ?name 'iconField
    ?labelIcon myIcon_fire
)

fields=list(
    list(wideEdgeField	    0:5		    200:35	150)
    list(narrowEdgeField    0:40	    200:35	150)
    list(widthField	    0:80	    200:35	150)
    list(autoField	    0:120	    200:35	150)
    list(stepRadioField	    200:120	    100:35	80)
    list(stepLengthField    0:160	    200:35	150)
    list(stepHeightField    0:200	    200:35	150)
    list(iconField	    270:200	    32:35)
)

if(!boundp('createPowerLineForm) || (createPowerLineForm==nil) then
    createPowerLineForm=hiCreateAppForm(
	?name 'createPowerLineForm
	?fields fields
	?formTitle "CreatePowerLineForm"
	?callback "CreatePowerLineForm_CB()"
	?buttonLayout 'OKCancelDefApply
    )
);end if
hiDisplayForm(createPowerLineForm)
);end let

);end procedure

procedure(CreatePowerLineForm_CB()
let((wideEdge narrowEdge width auto stepL stepH)
wideEdge=createPowerLineForm->wideEdgeField->value
narrowEdge=createPowerLineForm->narrowEdgeField->value
width=createPowerLineForm->widthField->value
auto=createPowerLineForm->autoField->value
stepL=createPowerLineForm->stepLengthField->value
stepH=createPowerLineForm->stepHeightField->value

CreatePowerLine()
);end let

);end procedure

procedure(AutoField_CB()
if(createPowerLineForm->autoField->valuet then
createPowerLineForm->stepRadioField->invisible=nil
createPowerLineForm->narrowEdgeField->editable=t
if(createPowerLineForm->stepRadioField->value
"stepH" then
createPowerLineForm->stepLengthField->editable=nil
else
createPowerLineForm->stepHeightField->editable=nil
);end if
else
createPowerLineForm->stepLengthField->editable=t
createPowerLineForm->stepHeightField->editable=t
createPowerLineForm->narrowEdgeField->editable=nil
createPowerLineForm->stepRadioField->invisible=t
);end if
);end procedure

procedure(StepRadioField_CB(radio)
if(radio==1 then
createPowerLineForm->stepLengthField->editable=t
createPowerLineForm->stepHeightField->editable=nil
else
createPowerLineForm->stepLengthField->editable=nil
createPowerLineForm->stepHeightField->editable=t
);end if
);end procedure

procedure(CreatePowerLine()
let((cv lpp grid steps points firstPoint time point1 point2 penultPoint dy lastPoint)
cv=geGetEditCellView()
lpp=leGetEntryLayer()
grid=techGetMfgGridResolution(techGetTechFile(cv))

points=nil
points=append1(points list(0 0))
firstPoint=list(0 wideEdge)
points=append1(points firstPoint)

if(auto==t then
    if(createPowerLineForm->stepRadioField->value=="stepH" then
	steps=round2((wideEdge-narrowEdge)/stepH)
	stepL=width/steps-stepH
	stepL=round2((stepL/grid))*grid	;fix grid
    else
	stepH=stepL*(wideEdge-narrowEdge)/(width-(wideEdge-narrowEdge))
	stepH=round2((stepH/grid))*grid	;fix grid
	steps=round2(width/(stepL+stepH))
    );end if
else
    steps=round2(width/(stepL+stepH))
);end if

time=1
while(time<=steps && yCoord(firstPoint)>0
    point1=list(xCoord(firstPoint)+stepL yCoord(firstPoint))
    point2=list(xCoord(firstPoint)+stepL+stepH yCoord(firstPoint)-stepH)
    firstPoint=point2
    when(xCoord(point2)<=width && yCoord(point2)>=0
	points=append1(points point1)
	points=append1(points point2)
    );end when
    time++
);end while
if(auto==t then
    when(narrowEdge!=0
	lastPoint=car(last(points))
	if(xCoord(lastPoint)<width || (xCoord(lastPoint)==width && yCoord(lastPoint)>narrowEdge) then
	    penultPoint=car(last(remove(car(last(points)) points)))
	    dy=yCoord(penultPoint)-narrowEdge
	    penultPoint=list(width-dy yCoord(penultPoint))
	    lastPoint=list(width narrowEdge)
	    points=remove(car(last(points)) points)
	    points=remove(car(last(points)) points)
	    points=append1(points penultPoint)
	    points=append1(points lastPoint)
	else
	    lastPoint=list(width narrowEdge)
	    points=append1(points lastPoint)
	);end if
    );end when
else
    lastPoint=list(width yCoord(car(last(points))))
    points=append1(points lastPoint)
);end if
points=append1(points list(width 0))
dbCreatePolygon(cv lpp points)
);end let

);end procedure

hiSetBindKey("Layout" "KP_8" "CreatePowerLineForm()")

posted @ 2026-01-06 15:16  sdadad1  阅读(14)  评论(0)    收藏  举报