macroScript deleteoutlineedges
category:"ZX_工具箱"
tooltip:"3D_RnD_删除轮廓两端"
buttontext:"3D_RnD_删除轮廓两端"
(
global msgRollPopup
fn msgRollPopup =
(
rollout fixing "fixing"
(
timer clock "testClock" interval:1 --tick once a second
label test "1"
on clock tick do
(
valUp = (test.text as integer)+1
test.text = valUp as string
if valup == 2 do (
destroydialog fixing
)
)
)
createDialog fixing modal:true
)
spl = getSplineSelection $
allspl = numSplines $
for i = 1 to allspl do (
setSegSelection $ i #()
)
for j =1 to spl.count do(
if spl != undefined and (isClosed $ spl[j] == true) do (
try(
subobjectLevel = 2
todel = numSegments $ spl[j]
todel2= todel/2
setSegSelection $ spl[j] #()
setSegSelection $ spl[j] #(todel, todel2)
splineOps.delete $
updateshape $
msgRollPopup()
subobjectLevel = 3
)
catch ()
))
)
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
macroScript SplineFilletCORNER
category:"ZX_工具箱"
tooltip:"3D_RnD_延长交合_CORNER"
buttontext:"3D_RnD_延长交合_CORNER"
(
state = false
mult = 100 ---file unit
kntsel = #()
num = numSplines $
fn intersect a b c d = (
local r = b +-a
local s = d+-c
local d = r[1] * s[2] - r[2] * s[1]
local u = ((c[1]-a[1])* r[2] - (c[2]-a[2]) * r[1]) /d
local t = ((c[1]-a[1])* s[2] - (c[2]-a[2]) * s[1]) /d
return a + t *r
)
fn getsecondpoint pont = (
if pont[2] +- 1 == 0 then return 2
else return pont[2] +- 1
)
thebase =$.baseObject
modPanel.setCurrentObject $.baseObject
if classOf thebase == line or classOf thebase == splineShape and subObjectLevel == 1 then (
with undo on (
modPanel.addModToSelection (Edit_Spline ()) ui:on
nummod = $.modifiers.count
maxOps.CollapseNodeTo $ nummod true
modPanel.setCurrentObject $.baseObject
for st = 1 to (num) do
(
sel = getKnotSelection $ st
if sel.count != 0 do(
for i in sel do (
knttemp = #()
append knttemp st
append knttemp i
append kntsel knttemp))
)
if kntsel.count == 2 then (
PointA = getKnotPoint $ kntsel[1][1] kntsel[1][2]---point A Coordinates
PointB = getKnotPoint $ kntsel[2][1] kntsel[2][2]---point B Coordinates
secondA = getsecondpoint kntsel[1] --get A2 point number
secondB = getsecondpoint kntsel[2] --get B2 point number
PointAA = getKnotPoint $ kntsel[1][1] secondA ---point A2 Coordinates
PointBB = getKnotPoint $ kntsel[2][1] secondB ---point B2 Coordinates
poi = intersect PointA PointAA PointB PointBB---point of intersection
--format "pointa= % | pointaa = % | pointb = % | pointbb = % | poi= % \n" pointa pointaa pointb pointbb poi
cpa1 = PointAA - PointA
cpat = cross cpa1 [0,0,1]
cpb1 = PointBB - PointB
cpbt = cross cpb1 [0,0,1]
cpa = cpat + PointA
cpb = cpbt + PointB
poitest = poi as string
poitest2 = findString poitest "nan"
poitest3 = findString poitest "e"
poitest4 = findString poitest "inf"
if (poitest2 == undefined and poitest3 == undefined and poitest4 == undefined) then (
print"intersect"
----------------------unifiying length----------------------------
-------------------------------------------------------------------
setKnotPoint $ kntsel[1][1] kntsel[1][2] poi
setKnotPoint $ kntsel[2][1] kntsel[2][2] poi
setKnotType $ kntsel[1][1] kntsel[1][2] #Corner
setKnotType $ kntsel[2][1] kntsel[2][2] #Corner
)
else (
print "paraller"
va1 = intersect PointA cpa PointB PointBB
va2 = intersect PointA PointAA PointB cpb
-- va1ex = va1 - PointB
-- va2ex = va2- PointA
-- va1exl = PointB + va1ex
-- va2exl = PointA + va2ex
--+format "intersect A : % || intersect B : %\n" va1 va2
if state then (
PointA = va2
setKnotPoint $ kntsel[1][1] kntsel[1][2] PointA
)
else (
PointB = va1
setKnotPoint $ kntsel[2][1] kntsel[2][2] PointB
)
)
----------------------end of unifiying length-------------------------
------------------------------------------------------------------------
--------------- find center of the circle -------------------
------------------------------------------------------------------------
--------------- end of find center of the circle -----------
------------------------------------------------------------------------
------------------- calculate angle of arc and handles ------------------
--format "n = % | rad = % |bezht = % | bezh = %\n" n rad bezht bezh
subobjectLevel = 1
)
else (print "选择 2个顶点")
updateShape $
forceCompleteRedraw()
)
)
else print "此操作仅适用于样条线"
modPanel.setCurrentObject $.baseObject
)
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
macroScript SplineFilletAB
category:"ZX_工具箱"
tooltip:"3D_RnD_延长圆角长边_AtoB"
buttontext:"3D_RnD_延长圆角长边_AtoB"
(
state = true
mult = 100 ---file unit
kntsel = #()
num = numSplines $
fn intersect a b c d = (
local r = b +-a
local s = d+-c
local d = r[1] * s[2] - r[2] * s[1]
local u = ((c[1]-a[1])* r[2] - (c[2]-a[2]) * r[1]) /d
local t = ((c[1]-a[1])* s[2] - (c[2]-a[2]) * s[1]) /d
return a + t *r
)
fn getsecondpoint pont = (
if pont[2] +- 1 == 0 then return 2
else return pont[2] +- 1
)
thebase =$.baseObject
modPanel.setCurrentObject $.baseObject
if classOf thebase == line or classOf thebase == splineShape and subObjectLevel == 1 then (
with undo on (
modPanel.addModToSelection (Edit_Spline ()) ui:on
nummod = $.modifiers.count
maxOps.CollapseNodeTo $ nummod true
modPanel.setCurrentObject $.baseObject
for st = 1 to (num) do
(
sel = getKnotSelection $ st
if sel.count != 0 do(
for i in sel do (
knttemp = #()
append knttemp st
append knttemp i
append kntsel knttemp))
)
if kntsel.count == 2 then (
PointA = getKnotPoint $ kntsel[1][1] kntsel[1][2]---point A Coordinates
PointB = getKnotPoint $ kntsel[2][1] kntsel[2][2]---point B Coordinates
secondA = getsecondpoint kntsel[1] --get A2 point number
secondB = getsecondpoint kntsel[2] --get B2 point number
PointAA = getKnotPoint $ kntsel[1][1] secondA ---point A2 Coordinates
PointBB = getKnotPoint $ kntsel[2][1] secondB ---point B2 Coordinates
poi = intersect PointA PointAA PointB PointBB---point of intersection
--format "pointa= % | pointaa = % | pointb = % | pointbb = % | poi= % \n" pointa pointaa pointb pointbb poi
cpa1 = PointAA - PointA
cpat = cross cpa1 [0,0,1]
cpb1 = PointBB - PointB
cpbt = cross cpb1 [0,0,1]
cpa = cpat + PointA
cpb = cpbt + PointB
poitest = poi as string
poitest2 = findString poitest "nan"
poitest3 = findString poitest "e"
poitest4 = findString poitest "inf"
--format "poitest:% | pointest2:% | pointest3:%\n" poitest poitest2 poitest3
if (poitest2 == undefined and poitest3 == undefined and poitest4 == undefined) then (
--print"intersect"
ex1 = PointA - poi ---vector from intersection to point A
ex1l = length ex1
tex1 = normalize ex1
ex2 = PointB - poi ---vector from intersection to point B
ex2l = length ex2
tex2 = normalize ex2
ex1n = tex1 * ex2l ---vector from intersection to point A same length as point B
ex2n = tex2 * ex1l---vector from intersection to point B same length as point A
--format "poi = % |ex1n = %| ex2n = % \n" poi ex1n ex2n
lenaaa = length (PointA - PointAA)
lenbbb= length (PointB - PointBB)
lenaapoi= length (PointAA - poi)
lenbbpoi= length (PointBB - poi)
----------------------unifiying length----------------------------
-------------------------------------------------------------------
if state then (
if lenaaa > lenaapoi then (
PointA = poi + (ex1n * -1)--if the spline is extended beyond intersection
)
else(
PointA = poi + ex1n
)
setKnotPoint $ kntsel[1][1] kntsel[1][2] PointA
if lenbbb > lenbbpoi do (
-------------------------
PointB = (PointB + (ex2 * -2))
-------------------------------
setKnotPoint $ kntsel[2][1] kntsel[2][2] PointB)--if the spline is extended beyond intersection
)
else (
if lenbbb > lenbbpoi then (
PointB = poi + (ex2n * -1)--if the spline is extended beyond intersection
)
else (
PointB = poi + ex2n
)
setKnotPoint $ kntsel[2][1] kntsel[2][2] PointB
if lenaaa > lenaapoi do(
----------------------
PointA = (PointA + (ex1 * -2))
----------------------
setKnotPoint $ kntsel[1][1] kntsel[1][2] PointA --if the spline is extended beyond intersection
)
)
)
else (
--print "paraller"
va1 = intersect PointA cpa PointB PointBB
va2 = intersect PointA PointAA PointB cpb
-- va1ex = va1 - PointB
-- va2ex = va2- PointA
-- va1exl = PointB + va1ex
-- va2exl = PointA + va2ex
--+format "intersect A : % || intersect B : %\n" va1 va2
if state then (
PointA = va2
setKnotPoint $ kntsel[1][1] kntsel[1][2] PointA
)
else (
PointB = va1
setKnotPoint $ kntsel[2][1] kntsel[2][2] PointB
)
)
----------------------end of unifiying length-------------------------
------------------------------------------------------------------------
--------------- find center of the circle -------------------
cpa1 = PointAA - PointA
cpat = cross cpa1 [0,0,1]
cpb1 = PointBB - PointB
cpbt = cross cpb1 [0,0,1]
cpa = cpat + PointA
cpb = cpbt + PointB
coc = intersect PointA cpa PointB cpb
rad = distance coc PointA
distab = distance PointA PointB
--print ("test:" + (coctest2 as string))
if (poitest2 != undefined or poitest3 != undefined or rad > (distab *10)) then (
--print "changing"
newc =(PointA - PointB)/2
coc = newc + PointB
)
--format "new center is : %\n" newc2
rad = distance coc PointA
--format "cpa = % | cpb = % \n" cpa cpb
--format "center of circle = %\n" coc
------------------------------------------------------------------------
--------------- end of find center of the circle -----------
------------------------------------------------------------------------
------------------- calculate angle of arc and handles ------------------
coc1 = normalize (PointA - coc)
coc2 = normalize (PointB - coc)
ang = acos (dot coc1 coc2)
n = 360 / ang --get number of segments
bezht = (4.0/3.0)*tan((pi/(2* n)) * 57.2958 ) -- calculate arc tangent
bezh = bezht * rad -- multiply by radius
h1a = ((normalize cpa1) * -1 ) * bezh
h2a = ((normalize cpb1) * -1 ) * bezh
h1 = h1a + PointA
h2 = h2a + PointB
--format "n = % | rad = % |bezht = % | bezh = %\n" n rad bezht bezh
spp = addNewSpline $
spp1=addKnot $ spp #corner #curve PointA
spp2=addKnot $ spp #corner #curve PointB
setKnotType $ spp 1 #bezierCorner
setOutVec $ spp 1 h1
setKnotType $ spp 2 #bezierCorner
setinVec $ spp 2 h2
subobjectLevel = 1
)
else (print "选择 2个顶点")
updateShape $
forceCompleteRedraw()
)
)
else print "此操作仅适用于样条线"
modPanel.setCurrentObject $.baseObject
)
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
macroScript SplineFilletBA
category:"ZX_工具箱"
tooltip:"3D_RnD_延长圆角短边_BtoA"
buttontext:"3D_RnD_延长圆角短边_BtoA"
(
state = false
mult = 100 ---file unit
kntsel = #()
num = numSplines $
fn intersect a b c d = (
local r = b +-a
local s = d+-c
local d = r[1] * s[2] - r[2] * s[1]
local u = ((c[1]-a[1])* r[2] - (c[2]-a[2]) * r[1]) /d
local t = ((c[1]-a[1])* s[2] - (c[2]-a[2]) * s[1]) /d
return a + t *r
)
fn getsecondpoint pont = (
if pont[2] +- 1 == 0 then return 2
else return pont[2] +- 1
)
thebase =$.baseObject
modPanel.setCurrentObject $.baseObject
if classOf thebase == line or classOf thebase == splineShape and subObjectLevel == 1 then (
with undo on (
modPanel.addModToSelection (Edit_Spline ()) ui:on
nummod = $.modifiers.count
maxOps.CollapseNodeTo $ nummod true
modPanel.setCurrentObject $.baseObject
for st = 1 to (num) do
(
sel = getKnotSelection $ st
if sel.count != 0 do(
for i in sel do (
knttemp = #()
append knttemp st
append knttemp i
append kntsel knttemp))
)
if kntsel.count == 2 then (
PointA = getKnotPoint $ kntsel[1][1] kntsel[1][2]---point A Coordinates
PointB = getKnotPoint $ kntsel[2][1] kntsel[2][2]---point B Coordinates
secondA = getsecondpoint kntsel[1] --get A2 point number
secondB = getsecondpoint kntsel[2] --get B2 point number
PointAA = getKnotPoint $ kntsel[1][1] secondA ---point A2 Coordinates
PointBB = getKnotPoint $ kntsel[2][1] secondB ---point B2 Coordinates
poi = intersect PointA PointAA PointB PointBB---point of intersection
--format "pointa= % | pointaa = % | pointb = % | pointbb = % | poi= % \n" pointa pointaa pointb pointbb poi
cpa1 = PointAA - PointA
cpat = cross cpa1 [0,0,1]
cpb1 = PointBB - PointB
cpbt = cross cpb1 [0,0,1]
cpa = cpat + PointA
cpb = cpbt + PointB
poitest = poi as string
poitest2 = findString poitest "nan"
poitest3 = findString poitest "e"
poitest4 = findString poitest "inf"
--format "poitest:% | pointest2:% | pointest3:%\n" poitest poitest2 poitest3
if (poitest2 == undefined and poitest3 == undefined and poitest4 == undefined) then (
-- print"intersect"
ex1 = PointA - poi ---vector from intersection to point A
ex1l = length ex1
tex1 = normalize ex1
ex2 = PointB - poi ---vector from intersection to point B
ex2l = length ex2
tex2 = normalize ex2
ex1n = tex1 * ex2l ---vector from intersection to point A same length as point B
ex2n = tex2 * ex1l---vector from intersection to point B same length as point A
--format "poi = % |ex1n = %| ex2n = % \n" poi ex1n ex2n
lenaaa = length (PointA - PointAA)
lenbbb= length (PointB - PointBB)
lenaapoi= length (PointAA - poi)
lenbbpoi= length (PointBB - poi)
----------------------unifiying length----------------------------
-------------------------------------------------------------------
if state then (
if lenaaa > lenaapoi then (
PointA = poi + (ex1n * -1)--if the spline is extended beyond intersection
)
else(
PointA = poi + ex1n
)
setKnotPoint $ kntsel[1][1] kntsel[1][2] PointA
if lenbbb > lenbbpoi do (
-------------------------
PointB = (PointB + (ex2 * -2))
-------------------------------
setKnotPoint $ kntsel[2][1] kntsel[2][2] PointB)--if the spline is extended beyond intersection
)
else (
if lenbbb > lenbbpoi then (
PointB = poi + (ex2n * -1)--if the spline is extended beyond intersection
)
else (
PointB = poi + ex2n
)
setKnotPoint $ kntsel[2][1] kntsel[2][2] PointB
if lenaaa > lenaapoi do(
----------------------
PointA = (PointA + (ex1 * -2))
----------------------
setKnotPoint $ kntsel[1][1] kntsel[1][2] PointA --if the spline is extended beyond intersection
)
)
)
else (
--print "paraller"
va1 = intersect PointA cpa PointB PointBB
va2 = intersect PointA PointAA PointB cpb
-- va1ex = va1 - PointB
-- va2ex = va2- PointA
-- va1exl = PointB + va1ex
-- va2exl = PointA + va2ex
--+format "intersect A : % || intersect B : %\n" va1 va2
if state then (
PointA = va2
setKnotPoint $ kntsel[1][1] kntsel[1][2] PointA
)
else (
PointB = va1
setKnotPoint $ kntsel[2][1] kntsel[2][2] PointB
)
)
----------------------end of unifiying length-------------------------
------------------------------------------------------------------------
--------------- find center of the circle -------------------
cpa1 = PointAA - PointA
cpat = cross cpa1 [0,0,1]
cpb1 = PointBB - PointB
cpbt = cross cpb1 [0,0,1]
cpa = cpat + PointA
cpb = cpbt + PointB
coc = intersect PointA cpa PointB cpb
rad = distance coc PointA
distab = distance PointA PointB
--print ("test:" + (coctest2 as string))
if (poitest2 != undefined or poitest3 != undefined or rad > (distab *10)) then (
--print "changing"
newc =(PointA - PointB)/2
coc = newc + PointB
)
--format "new center is : %\n" newc2
rad = distance coc PointA
--format "cpa = % | cpb = % \n" cpa cpb
--format "center of circle = %\n" coc
------------------------------------------------------------------------
--------------- end of find center of the circle -----------
------------------------------------------------------------------------
------------------- calculate angle of arc and handles ------------------
coc1 = normalize (PointA - coc)
coc2 = normalize (PointB - coc)
ang = acos (dot coc1 coc2)
n = 360 / ang --get number of segments
bezht = (4.0/3.0)*tan((pi/(2* n)) * 57.2958 ) -- calculate arc tangent
bezh = bezht * rad -- multiply by radius
h1a = ((normalize cpa1) * -1 ) * bezh
h2a = ((normalize cpb1) * -1 ) * bezh
h1 = h1a + PointA
h2 = h2a + PointB
--format "n = % | rad = % |bezht = % | bezh = %\n" n rad bezht bezh
spp = addNewSpline $
spp1=addKnot $ spp #corner #curve PointA
spp2=addKnot $ spp #corner #curve PointB
setKnotType $ spp 1 #bezierCorner
setOutVec $ spp 1 h1
setKnotType $ spp 2 #bezierCorner
setinVec $ spp 2 h2
subobjectLevel = 1
)
else (print "选择 2个顶点")
updateShape $
forceCompleteRedraw()
)
)
else print "此操作仅适用于样条线"
modPanel.setCurrentObject $.baseObject
)