My First Skill Program

  • Thread starter sridhartv25@gmail.com
  • Start date
S

sridhartv25@gmail.com

Guest
Hello all,
***************************Program to convert Rectangle and Regular
Polygon to path****************************

The program given below converts rectangle and regular polygon to
path, I had tried to cover many cases but still some strange cases may
fail to create the path. After writing the complete script I could say
that still a better
program can be written in a much shorter version, surely I will update
that script with in few days which could convert
any regular polygon to path.
One important condition while converting a polygon to path is the
polygon width must be same all along its length what ever may be the
direction or the no of bends it have.
I thank all the members of this forum especially Andrew and Riad Kaced
for thier support.
here it is

;Skill starts here

/*
Usage: Just Select a Polygon or a Rectangle in your Layout window to
be converted to path then copy the code into the icfb that's it else
copy the code in a file say path.il and then use the following command
in the icfb loadi("path of the file").
*/

procedure( polytopath()
win=hiGetCurrentWindow()
cv = deGetCellView()
db = car( geGetSelectedSet(cv))
test=0
if( db~>objType == "rect" then
mo=db~>layer
lo=leftEdge(db)
ro=rightEdge(db)
bo=bottomEdge(db)
to=topEdge(db)
cn1=to-bo
cn2=ro-lo
if(cn1>cn2 then
co=(lo+ro)/2
width=abs(lo-ro)
list1=co:bo
list2=co:to
full=list(list1 list2)
test=dbCreatePath(cv mo full width)
geDeleteSelSet(win)
)
if(cn2>=cn1 then
co1=(bo+to)/2
widthl1=abs(to-bo)
listl1=lo:co1
listl2=ro:co1
fulll=list(listl1 listl2)
test=dbCreatePath(cv mo fulll widthl1)
geDeleteSelSet(win)
)
)
if( db~>objType == "polygon" then ;;;;;;;;Case 1
mo=db~>layer
h=list(0 0)
s=db~>points
w=length(s)/2
;w=3
p=w-1
for(i 0 (length(s)/2)-1
;for(i 0 2
m=car(nth(w s))
n=car(nth(p s))
q=car(cdr(nth(w s)))
f=car(cdr(nth(p s)))
z=(m+n)/2
x=(q+f)/2
stack=list(z x)
h=append(h list(stack))
w=w+1
p=p-1
i=i+1
)
a=cddr(h)
;if( evenp(length(s)) then
;dep=car(cdr(nth((length(s)/2)-1 s)))
;dep1=car(cdr(nth(length(s)/2 s)))
;wid = abs(dep1-dep))
;if( oddp(length(s)) then

wid=abs(f-q)
if(wid!=0 then
id1=dbCreatePath(cv mo a wid)
bboxrec=db~>bBox
bboxpoly=id1~>bBox

if( bboxrec == bboxpoly then
;geDeleteSelSet(win)
test=dbDeleteObject(db)
)
if( db~>objType == "polygon" then
if( bboxrec != bboxpoly then
geDeselectAllFig()
geSelectFig(id1)
dbDeleteObject(id1)
;geDeleteSelSet(win)
))
))
if( db~>objType == "polygon" then ;;;;;;case2
mo=db~>layer
h2=list(0 0)
s2=db~>points
w2=(length(s2)/2) +1
p2=w2-1
for(i2 0 (length(s2)/2)-2
m2=car(nth(w2 s2))
n2=car(nth(p2 s2))
q2=car(cdr(nth(w2 s2)))
f2=car(cdr(nth(p2 s2)))
z2=(m2+n2)/2
x2=(q2+f2)/2
stack2=list(z2 x2)
h2=append(h2 list(stack2))
w2=w2+1
p2=p2-1
i2=i2+1
)
a2=cddr(h2)
wid2=abs(f2-q2)
firgetp21=car(nth(0 s2))
firgetw21=car(nth(1 s2))
firmix1=(firgetp21+firgetw21)/2
firgetp22=car(cdr(nth(0 s2)))
firgetw22=car(cdr(nth(1 s2)))
firmix2=(firgetp22+firgetw22)/2
mix12=list(firmix1 firmix2)
a2=append(a2 list(mix12))
if(wid2!=0 then
id2=dbCreatePath(cv mo a2 wid2)
bboxrec2=db~>bBox
bboxpoly2=id2~>bBox
if( bboxrec2 == bboxpoly2 then
;geDeleteSelSet(win)
test=dbDeleteObject(db)
)
if( db~>objType == "polygon" then
if( bboxrec2 != bboxpoly2 then
geDeselectAllFig()
geSelectFig(id2)
dbDeleteObject(id2)
;geDeleteSelSet(win)
))
))
if( db~>objType == "polygon" then ;;;;;;;case3
mo=db~>layer
s3=db~>points
w3=length(s3)-3
p3=0
;dummyh3=list(0 0)
;h3=append(h3 list(dummyh3))
h3=list(0 0)
ldw3=length(s3)-1
ldp3=length(s3)-2 ;;;or ldw3-1
lasgetp31=car(nth(ldp3 s3))
lasgetw31=car(nth(ldw3 s3))
lasmix31=(lasgetp31+lasgetw31)/2
lasgetp32=car(cdr(nth(ldp3 s3)))
lasgetw32=car(cdr(nth(ldw3 s3)))
lasmix32=(lasgetp32+lasgetw32)/2
mix312=list(lasmix31 lasmix32)
;h3=mix312
h3=append(h3 list(mix312))
for(i3 0 (length(s3)/2)-2
m3=car(nth(w3 s3))
n3=car(nth(p3 s3))
q3=car(cdr(nth(w3 s3)))
f3=car(cdr(nth(p3 s3)))
z3=(m3+n3)/2
x3=(q3+f3)/2
stack3=list(z3 x3)
h3=append(h3 list(stack3))
w3=w3-1
p3=p3+1
i3=i3+1
)
;dummyh3=list(0 0)
;h3=append(h3 list(dummyh3))
;a3=remove( list(0 0) h3 )
a3=cddr(h3)
wid3=abs(n3-m3)
widr=abs(f3-q3)
if( wid3 == 0 then
id3=dbCreatePath(cv mo a3 widr)
)
if( widr == 0 then
;'else
id3=dbCreatePath(cv mo a3 wid3))
bboxrec3=db~>bBox
bboxpoly3=id3~>bBox
if( bboxrec3 == bboxpoly3 then
;geDeleteSelSet(win)
test=dbDeleteObject(db)
)
if( db~>objType == "polygon" then
if( bboxrec3 != bboxpoly3 then
geDeselectAllFig()
geSelectFig(id3)
dbDeleteObject(id3)
;geDeleteSelSet(win)
)
))

if( db~>objType == "polygon" then ;;;;;;;case4
mo=db~>layer
s4=db~>points
pl4=(length(s4)/2)
el4=pl4/2
p4=(el4+pl4)-1
w4=(el4+pl4)
y4=(length(s4)/2)-1
t4=0
h4=list(0 0)
for(i4 0 el4-1
m4=car(nth(w4 s4))
n4=car(nth(p4 s4))
q4=car(cdr(nth(w4 s4)))
f4=car(cdr(nth(p4 s4)))
z4=(m4+n4)/2
x4=(q4+f4)/2
stack4=list(z4 x4)
h4=append(h4 list(stack4))
w4=w4+1
p4=p4-1
i4=i4+1
)
for(il4 0 el4-1
mn4=car(nth(t4 s4))
nn4=car(nth(y4 s4))
qn4=car(cdr(nth(t4 s4)))
fn4=car(cdr(nth(y4 s4)))
zn4=(mn4+nn4)/2
xn4=(qn4+fn4)/2
stackn4=list(zn4 xn4)
h4=append(h4 list(stackn4))
y4=y4-1
t4=t4+1
il4=il4+1
)
a4=cddr(h4)
wid4=abs(f4-q4)
if(wid4!=0 then
id4=dbCreatePath(cv mo a4 wid4)
bboxrec4=db~>bBox
bboxpoly4=id4~>bBox
if( bboxrec4 == bboxpoly4 then
;geDeleteSelSet(win)
test=dbDeleteObject(db)
)
if( db~>objType == "polygon" then
if( bboxrec4 != bboxpoly4 then
geDeselectAllFig()
geSelectFig(id4)
dbDeleteObject(id4)
;geDeleteSelSet(win)
))
))

if( db~>objType == "polygon" then ;;;;;;;case5
mo=db~>layer
s5=db~>points
w5=(length(s5)/2)-2
p5=w5-1
wo5=length(s5)-1
po5=(length(s5)/2)+1
h5=list(0 0)
for(i5 0 (length(s5)/2)-3
m5=car(nth(w5 s5))
n5=car(nth(p5 s5))
q5=car(cdr(nth(w5 s5)))
f5=car(cdr(nth(p5 s5)))
z5=(m5+n5)/2
x5=(q5+f5)/2
stack5=list(z5 x5)
h5=append(h5 list(stack5))
w5=w5+1
p5=p5-1
i5=i5+1
)
for(io5 0 (length(s5)/2)-4
mo5=car(nth(wo5 s5))
no5=car(nth(po5 s5))
qo5=car(cdr(nth(wo5 s5)))
fo5=car(cdr(nth(po5 s5)))
zo5=(mo5+no5)/2
xo5=(qo5+fo5)/2
stacko5=list(zo5 xo5)
h5=append(h5 list(stacko5))
wo5=wo5-1
po5=po5+1
io5=io5+1
)
a5=cddr(h5)
wid5=abs(n5-m5)
;widr=abs(f5-q3)
if(wid5!=0 then
id5=dbCreatePath(cv mo a5 wid5)
bboxrec5=db~>bBox
bboxpoly5=id5~>bBox
if( bboxrec5 == bboxpoly5 then
;geDeleteSelSet(win)
test=dbDeleteObject(db)
)
if( db~>objType == "polygon" then
if( bboxrec5 != bboxpoly5 then
geDeselectAllFig()
geSelectFig(id5)
dbDeleteObject(id5)
))
))
if( db~>objType == "polygon" then
mo=db~>layer
s6=db~>points
v=(length(s6)/2)+1
v1=((length(s6)-v)/2)-1
w6=length(s6)-1
p6=(length(s6)/2)+1
wo6=(length(s6)/2)
po6=0
h6=list(0 0)
for(io6 0 (length(s6)/2)-4
mo6=car(nth(wo6 s6))
no6=car(nth(po6 s6))
qo6=car(cdr(nth(wo6 s6)))
fo6=car(cdr(nth(po6 s6)))
zo6=(mo6+no6)/2
xo6=(qo6+fo6)/2
stacko6=list(zo6 xo6)
h6=append(h6 list(stacko6))
wo6=wo6-1
po6=po6+1
io6=io6+1
)
h6=reverse(cddr(h6))
for(i6 0 v1
m6=car(nth(w6 s6))
n6=car(nth(p6 s6))
q6=car(cdr(nth(w6 s6)))
f6=car(cdr(nth(p6 s6)))
z6=(m6+n6)/2
x6=(q6+f6)/2
stack6=list(z6 x6)
h6=append(h6 list(stack6))
w6=w6-1
p6=p6+1
i6=i6+1
)
wid6=abs(n6-m6)
if(wid6!=0 then
id6=dbCreatePath(cv mo h6 wid6)
bboxrec6=db~>bBox
bboxpoly6=id6~>bBox
if( bboxrec6 == bboxpoly6 then
;geDeleteSelSet(win)
test=dbDeleteObject(db)
)
if( db~>objType == "polygon" then
if( bboxrec6 != bboxpoly6 then
geDeselectAllFig()
geSelectFig(id6)
dbDeleteObject(id6)
))
))
if( db~>objType == "polygon" then
mo=db~>layer
s7=db~>points
v=(((length(s7)/2)-1)/2)-1
w7=(length(s7)/2)-2
p7=0
wo7=length(s7)-1
po7=(length(s7)/2)-1
h7=list(0 0)
for(i7 0 v
m7=car(nth(w7 s7))
n7=car(nth(p7 s7))
q7=car(cdr(nth(w7 s7)))
f7=car(cdr(nth(p7 s7)))
z7=(m7+n7)/2
x7=(q7+f7)/2
stack7=list(z7 x7)
h7=append(h7 list(stack7))
w7=w7-1
p7=p7+1
i7=i7+1
)
h7=cddr(h7)
h7=reverse(h7)
for(io7 0 (length(s7)/2)-3
mo7=car(nth(wo7 s7))
no7=car(nth(po7 s7))
qo7=car(cdr(nth(wo7 s7)))
fo7=car(cdr(nth(po7 s7)))
zo7=(mo7+no7)/2
xo7=(qo7+fo7)/2
stacko7=list(zo7 xo7)
h7=append(h7 list(stacko7))
wo7=wo7-1
po7=po7+1
io7=io7+1
)
wid7=abs(no7-mo7)
if(wid7!=0 then
id7=dbCreatePath(cv mo h7 wid7)
bboxrec7=db~>bBox
bboxpoly7=id7~>bBox
if( bboxrec7 == bboxpoly7 then
;geDeleteSelSet(win)
test=dbDeleteObject(db)
)
if( db~>objType == "polygon" then
if( bboxrec7 != bboxpoly7 then
geDeselectAllFig()
geSelectFig(id7)
dbDeleteObject(id7)
))
))
if( db~>objType == "path" then
;geDeselectAllFig()
hiDisplayAppDBox(

?name 'Error

?dboxBanner "Error"

?dboxText sprintf(nil "Cannot convert Path to
Path")

?buttonLayout 'UserDefined

?buttons list("Close")

))

if( db~>objType == "inst" then
;geDeselectAllFig()
hiDisplayAppDBox(

?name 'Errtor

?dboxBanner "Error"

?dboxText sprintf(nil "Cannot convert Instance to
Path")

?buttonLayout 'UserDefined

?buttons list("Close")

))

;sel=geGetSelectedSet()
;if( sel == nil then
;hiDisplayAppDBox(

; ?name 'Eroot

; ?dboxBanner "Error"

;?dboxText sprintf(nil " No object is selected \n
\n Please select one")

; ?buttonLayout 'UserDefined

;?buttons list("Close")
;))
if(test==0 then
hiDisplayAppDBox(

?name 'ERT

?dboxBanner "Error"

?dboxText sprintf(nil "Path not Created, Still the
script need tobe updated\n To create the path see the hints given
above")

?buttonLayout 'UserDefined

?buttons list("Close") )
))
polytopath()

;Skill ends here



I will try to update the script by using the local variables.
Any suggestions and comments please to make it perfect.
 
sridhartv25@gmail.com wrote, on 01/20/09 08:39:
Hello all,
***************************Program to convert Rectangle and Regular
Polygon to path****************************

The program given below converts rectangle and regular polygon to
path, I had tried to cover many cases but still some strange cases may
fail to create the path. After writing the complete script I could say
that still a better
program can be written in a much shorter version, surely I will update
that script with in few days which could convert
any regular polygon to path.
One important condition while converting a polygon to path is the
polygon width must be same all along its length what ever may be the
direction or the no of bends it have.
I thank all the members of this forum especially Andrew and Riad Kaced
for thier support.
here it is

;Skill starts here
.... snipped code with no formatting ...
;Skill ends here



I will try to update the script by using the local variables.
Any suggestions and comments please to make it perfect.
It's rather hard to comment on your code, because there was virtually no
formatting - I don't know whether it went missing when you pasted the code (not
sure how), or whether you had no indentation in the code - either way, a key
part of good programming is clear and consistent indentation of the code
(without this it is virtually impossible to follow what the code does),
commenting (there were very few non-obvious comments in your code), use of local
variables (there were no local variables in the code).

Unfortunately the later post with the "compressed" code is even harder to
understand...

Sorry to be a little critical, but you did ask for suggestions and comments ;-)

Regards,

Andrew.
 
/*
Usage: Just Select a Polygon or a Rectangle in your Layout window to
be converted to path then copy the code into the icfb that's it else
copy the code in a file say path.il and then use the following command
in the icfb loadi("path of the file").
*/
Hello all,
Just to inform you that ps donot copy the code directly to the icfb,
Copy the code into a file and then load the file in to the icfb using
loadi command
 
Sorry while copying the code from my gvim editor to this page some
alteration as been done.
So you may get sysntax errors because of that. So I am copying the
compressed code for which I think there should not be any problem.


;Skill starts here

(procedure (polytopath) (setq win (hiGetCurrentWindow)) (setq cv
(deGetCellView)) (setq db (car (geGetSelectedSet cv))) (setq test 0)
(if (equal (getSGq db objType) "rect") then (setq mo (getSGq db
layer)) (setq lo (leftEdge db)) (setq ro (rightEdge db)) (setq bo
(bottomEdge db)) (setq to (topEdge db)) (setq cn1 (difference to bo))
(setq cn2 (difference ro lo)) (if (greaterp cn1 cn2) then (setq co
(quotient (plus lo ro) 2)) (setq width (abs (difference lo ro))) (setq
list1 (range co bo)) (setq list2 (range co to)) (setq full (list list1
list2)) (setq test (dbCreatePath cv mo full width)) (geDeleteSelSet
win)) (if (geqp cn2 cn1) then (setq co1 (quotient (plus bo to) 2))
(setq widthl1 (abs (difference to bo))) (setq listl1 (range lo co1))
(setq listl2 (range ro co1)) (setq fulll (list listl1 listl2)) (setq
test (dbCreatePath cv mo fulll widthl1)) (geDeleteSelSet win))) (if
(equal (getSGq db objType) "polygon") then (setq mo (getSGq db layer))
(setq h (list 0 0)) (setq s (getSGq db points)) (setq w (quotient
(length s) 2)) (setq p (difference w 1)) (for i 0 (difference
(quotient (length s) 2) 1) (setq m (car (nth w s))) (setq n (car (nth
p s))) (setq q (car (cdr (nth w s)))) (setq f (car (cdr (nth p s))))
(setq z (quotient (plus m n) 2)) (setq x (quotient (plus q f) 2))
(setq stack (list z x)) (setq h (append h (list stack))) (setq w (plus
w 1)) (setq p (difference p 1)) (setq i (plus i 1))) (setq a (cddr h))
(setq wid (abs (difference f q))) (if (nequal wid 0) then (setq id1
(dbCreatePath cv mo a wid)) (setq bboxrec (getSGq db bBox)) (setq
bboxpoly (getSGq id1 bBox)) (if (equal bboxrec bboxpoly) then (setq
test (dbDeleteObject db))) (if (equal (getSGq db objType) "polygon")
then (if (nequal bboxrec bboxpoly) then (geDeselectAllFig)
(geSelectFig id1) (dbDeleteObject id1))))) (if (equal (getSGq db
objType) "polygon") then (setq mo (getSGq db layer)) (setq h2 (list 0
0)) (setq s2 (getSGq db points)) (setq w2 (plus (quotient (length s2)
2) 1)) (setq p2 (difference w2 1)) (for i2 0 (difference (quotient
(length s2) 2) 2) (setq m2 (car (nth w2 s2))) (setq n2 (car (nth p2
s2))) (setq q2 (car (cdr (nth w2 s2)))) (setq f2 (car (cdr (nth p2
s2)))) (setq z2 (quotient (plus m2 n2) 2)) (setq x2 (quotient (plus q2
f2) 2)) (setq stack2 (list z2 x2)) (setq h2 (append h2 (list stack2)))
(setq w2 (plus w2 1)) (setq p2 (difference p2 1)) (setq i2 (plus i2
1))) (setq a2 (cddr h2)) (setq wid2 (abs (difference f2 q2))) (setq
firgetp21 (car (nth 0 s2))) (setq firgetw21 (car (nth 1 s2))) (setq
firmix1 (quotient (plus firgetp21 firgetw21) 2)) (setq firgetp22 (car
(cdr (nth 0 s2)))) (setq firgetw22 (car (cdr (nth 1 s2)))) (setq
firmix2 (quotient (plus firgetp22 firgetw22) 2)) (setq mix12 (list
firmix1 firmix2)) (setq a2 (append a2 (list mix12))) (if (nequal wid2
0) then (setq id2 (dbCreatePath cv mo a2 wid2)) (setq bboxrec2 (getSGq
db bBox)) (setq bboxpoly2 (getSGq id2 bBox)) (if (equal bboxrec2
bboxpoly2) then (setq test (dbDeleteObject db))) (if (equal (getSGq db
objType) "polygon") then (if (nequal bboxrec2 bboxpoly2) then
(geDeselectAllFig) (geSelectFig id2) (dbDeleteObject id2))))) (if
(equal (getSGq db objType) "polygon") then (setq mo (getSGq db layer))
(setq s3 (getSGq db points)) (setq w3 (difference (length s3) 3))
(setq p3 0) (setq h3 (list 0 0)) (setq ldw3 (difference (length s3)
1)) (setq ldp3 (difference (length s3) 2)) (setq lasgetp31 (car (nth
ldp3 s3))) (setq lasgetw31 (car (nth ldw3 s3))) (setq lasmix31
(quotient (plus lasgetp31 lasgetw31) 2)) (setq lasgetp32 (car (cdr
(nth ldp3 s3)))) (setq lasgetw32 (car (cdr (nth ldw3 s3)))) (setq
lasmix32 (quotient (plus lasgetp32 lasgetw32) 2)) (setq mix312 (list
lasmix31 lasmix32)) (setq h3 (append h3 (list mix312))) (for i3 0
(difference (quotient (length s3) 2) 2) (setq m3 (car (nth w3 s3)))
(setq n3 (car (nth p3 s3))) (setq q3 (car (cdr (nth w3 s3)))) (setq f3
(car (cdr (nth p3 s3)))) (setq z3 (quotient (plus m3 n3) 2)) (setq x3
(quotient (plus q3 f3) 2)) (setq stack3 (list z3 x3)) (setq h3 (append
h3 (list stack3))) (setq w3 (difference w3 1)) (setq p3 (plus p3 1))
(setq i3 (plus i3 1))) (setq a3 (cddr h3)) (setq wid3 (abs (difference
n3 m3))) (setq widr (abs (difference f3 q3))) (if (equal wid3 0) then
(setq id3 (dbCreatePath cv mo a3 widr))) (if (equal widr 0) then (setq
id3 (dbCreatePath cv mo a3 wid3))) (setq bboxrec3 (getSGq db bBox))
(setq bboxpoly3 (getSGq id3 bBox)) (if (equal bboxrec3 bboxpoly3) then
(setq test (dbDeleteObject db))) (if (equal (getSGq db objType)
"polygon") then (if (nequal bboxrec3 bboxpoly3) then
(geDeselectAllFig) (geSelectFig id3) (dbDeleteObject id3)))) (if
(equal (getSGq db objType) "polygon") then (setq mo (getSGq db layer))
(setq s4 (getSGq db points)) (setq pl4 (quotient (length s4) 2)) (setq
el4 (quotient pl4 2)) (setq p4 (difference (plus el4 pl4) 1)) (setq w4
(plus el4 pl4)) (setq y4 (difference (quotient (length s4) 2) 1))
(setq t4 0) (setq h4 (list 0 0)) (for i4 0 (difference el4 1) (setq m4
(car (nth w4 s4))) (setq n4 (car (nth p4 s4))) (setq q4 (car (cdr (nth
w4 s4)))) (setq f4 (car (cdr (nth p4 s4)))) (setq z4 (quotient (plus
m4 n4) 2)) (setq x4 (quotient (plus q4 f4) 2)) (setq stack4 (list z4
x4)) (setq h4 (append h4 (list stack4))) (setq w4 (plus w4 1)) (setq
p4 (difference p4 1)) (setq i4 (plus i4 1))) (for il4 0 (difference
el4 1) (setq mn4 (car (nth t4 s4))) (setq nn4 (car (nth y4 s4))) (setq
qn4 (car (cdr (nth t4 s4)))) (setq fn4 (car (cdr (nth y4 s4)))) (setq
zn4 (quotient (plus mn4 nn4) 2)) (setq xn4 (quotient (plus qn4 fn4)
2)) (setq stackn4 (list zn4 xn4)) (setq h4 (append h4 (list stackn4)))
(setq y4 (difference y4 1)) (setq t4 (plus t4 1)) (setq il4 (plus il4
1))) (setq a4 (cddr h4)) (setq wid4 (abs (difference f4 q4))) (if
(nequal wid4 0) then (setq id4 (dbCreatePath cv mo a4 wid4)) (setq
bboxrec4 (getSGq db bBox)) (setq bboxpoly4 (getSGq id4 bBox)) (if
(equal bboxrec4 bboxpoly4) then (setq test (dbDeleteObject db))) (if
(equal (getSGq db objType) "polygon") then (if (nequal bboxrec4
bboxpoly4) then (geDeselectAllFig) (geSelectFig id4) (dbDeleteObject
id4))))) (if (equal (getSGq db objType) "polygon") then (setq mo
(getSGq db layer)) (setq s5 (getSGq db points)) (setq w5 (difference
(quotient (length s5) 2) 2)) (setq p5 (difference w5 1)) (setq wo5
(difference (length s5) 1)) (setq po5 (plus (quotient (length s5) 2)
1)) (setq h5 (list 0 0)) (for i5 0 (difference (quotient (length s5)
2) 3) (setq m5 (car (nth w5 s5))) (setq n5 (car (nth p5 s5))) (setq q5
(car (cdr (nth w5 s5)))) (setq f5 (car (cdr (nth p5 s5)))) (setq z5
(quotient (plus m5 n5) 2)) (setq x5 (quotient (plus q5 f5) 2)) (setq
stack5 (list z5 x5)) (setq h5 (append h5 (list stack5))) (setq w5
(plus w5 1)) (setq p5 (difference p5 1)) (setq i5 (plus i5 1))) (for
io5 0 (difference (quotient (length s5) 2) 4) (setq mo5 (car (nth wo5
s5))) (setq no5 (car (nth po5 s5))) (setq qo5 (car (cdr (nth wo5
s5)))) (setq fo5 (car (cdr (nth po5 s5)))) (setq zo5 (quotient (plus
mo5 no5) 2)) (setq xo5 (quotient (plus qo5 fo5) 2)) (setq stacko5
(list zo5 xo5)) (setq h5 (append h5 (list stacko5))) (setq wo5
(difference wo5 1)) (setq po5 (plus po5 1)) (setq io5 (plus io5 1)))
(setq a5 (cddr h5)) (setq wid5 (abs (difference n5 m5))) (if (nequal
wid5 0) then (setq id5 (dbCreatePath cv mo a5 wid5)) (setq bboxrec5
(getSGq db bBox)) (setq bboxpoly5 (getSGq id5 bBox)) (if (equal
bboxrec5 bboxpoly5) then (setq test (dbDeleteObject db))) (if (equal
(getSGq db objType) "polygon") then (if (nequal bboxrec5 bboxpoly5)
then (geDeselectAllFig) (geSelectFig id5) (dbDeleteObject id5))))) (if
(equal (getSGq db objType) "polygon") then (setq mo (getSGq db layer))
(setq s6 (getSGq db points)) (setq v (plus (quotient (length s6) 2)
1)) (setq v1 (difference (quotient (difference (length s6) v) 2) 1))
(setq w6 (difference (length s6) 1)) (setq p6 (plus (quotient (length
s6) 2) 1)) (setq wo6 (quotient (length s6) 2)) (setq po6 0) (setq h6
(list 0 0)) (for io6 0 (difference (quotient (length s6) 2) 4) (setq
mo6 (car (nth wo6 s6))) (setq no6 (car (nth po6 s6))) (setq qo6 (car
(cdr (nth wo6 s6)))) (setq fo6 (car (cdr (nth po6 s6)))) (setq zo6
(quotient (plus mo6 no6) 2)) (setq xo6 (quotient (plus qo6 fo6) 2))
(setq stacko6 (list zo6 xo6)) (setq h6 (append h6 (list stacko6)))
(setq wo6 (difference wo6 1)) (setq po6 (plus po6 1)) (setq io6 (plus
io6 1))) (setq h6 (reverse (cddr h6))) (for i6 0 v1 (setq m6 (car (nth
w6 s6))) (setq n6 (car (nth p6 s6))) (setq q6 (car (cdr (nth w6 s6))))
(setq f6 (car (cdr (nth p6 s6)))) (setq z6 (quotient (plus m6 n6) 2))
(setq x6 (quotient (plus q6 f6) 2)) (setq stack6 (list z6 x6)) (setq
h6 (append h6 (list stack6))) (setq w6 (difference w6 1)) (setq p6
(plus p6 1)) (setq i6 (plus i6 1))) (setq wid6 (abs (difference n6
m6))) (if (nequal wid6 0) then (setq id6 (dbCreatePath cv mo h6 wid6))
(setq bboxrec6 (getSGq db bBox)) (setq bboxpoly6 (getSGq id6 bBox))
(if (equal bboxrec6 bboxpoly6) then (setq test (dbDeleteObject db)))
(if (equal (getSGq db objType) "polygon") then (if (nequal bboxrec6
bboxpoly6) then (geDeselectAllFig) (geSelectFig id6) (dbDeleteObject
id6))))) (if (equal (getSGq db objType) "polygon") then (setq mo
(getSGq db layer)) (setq s7 (getSGq db points)) (setq v (difference
(quotient (difference (quotient (length s7) 2) 1) 2) 1)) (setq w7
(difference (quotient (length s7) 2) 2)) (setq p7 0) (setq wo7
(difference (length s7) 1)) (setq po7 (difference (quotient (length
s7) 2) 1)) (setq h7 (list 0 0)) (for i7 0 v (setq m7 (car (nth w7
s7))) (setq n7 (car (nth p7 s7))) (setq q7 (car (cdr (nth w7 s7))))
(setq f7 (car (cdr (nth p7 s7)))) (setq z7 (quotient (plus m7 n7) 2))
(setq x7 (quotient (plus q7 f7) 2)) (setq stack7 (list z7 x7)) (setq
h7 (append h7 (list stack7))) (setq w7 (difference w7 1)) (setq p7
(plus p7 1)) (setq i7 (plus i7 1))) (setq h7 (cddr h7)) (setq h7
(reverse h7)) (for io7 0 (difference (quotient (length s7) 2) 3) (setq
mo7 (car (nth wo7 s7))) (setq no7 (car (nth po7 s7))) (setq qo7 (car
(cdr (nth wo7 s7)))) (setq fo7 (car (cdr (nth po7 s7)))) (setq zo7
(quotient (plus mo7 no7) 2)) (setq xo7 (quotient (plus qo7 fo7) 2))
(setq stacko7 (list zo7 xo7)) (setq h7 (append h7 (list stacko7)))
(setq wo7 (difference wo7 1)) (setq po7 (plus po7 1)) (setq io7 (plus
io7 1))) (setq wid7 (abs (difference no7 mo7))) (if (nequal wid7 0)
then (setq id7 (dbCreatePath cv mo h7 wid7)) (setq bboxrec7 (getSGq db
bBox)) (setq bboxpoly7 (getSGq id7 bBox)) (if (equal bboxrec7
bboxpoly7) then (setq test (dbDeleteObject db))) (if (equal (getSGq db
objType) "polygon") then (if (nequal bboxrec7 bboxpoly7) then
(geDeselectAllFig) (geSelectFig id7) (dbDeleteObject id7))))) (if
(equal (getSGq db objType) "path") then (hiDisplayAppDBox ?name (quote
Error) ?dboxBanner "Error" ?dboxText (sprintf nil "Cannot convert Path
to Path") ?buttonLayout (quote UserDefined) ?buttons (list "Close")))
(if (equal (getSGq db objType) "inst") then (hiDisplayAppDBox ?name
(quote Errtor) ?dboxBanner "Error" ?dboxText (sprintf nil "Cannot
convert Instance to Path") ?buttonLayout (quote UserDefined) ?buttons
(list "Close"))) (if (equal test 0) then (hiDisplayAppDBox ?name
(quote ERT) ?dboxBanner "Error" ?dboxText (sprintf nil "Path not
Created, Still the script need tobe updated\n To create the path see
the hints given above") ?buttonLayout (quote UserDefined) ?buttons
(list "Close"))))
(polytopath)

;Skill ends here

;ps copy the code into a file and then load the file
 
Sorry once again,
There is a problem while copying the code,
That's why I think the code of Andrew's for polygon to path conversion
is giving syntax errors.

This should work fine,

;Skill starts here

(procedure (polytopath) (setq win (hiGetCurrentWindow)) (setq cv
(deGetCellView)) (setq db (car (geGetSelectedSet cv))) (setq test 0)
(if (equal (getSGq db objType) "rect") then (setq mo (getSGq db
layer)) (setq lo (leftEdge db)) (setq ro (rightEdge db)) (setq bo
(bottomEdge db)) (setq to (topEdge db)) (setq cn1 (difference to bo))
(setq cn2 (difference ro lo)) (if (greaterp cn1 cn2) then (setq co
(quotient (plus lo ro) 2)) (setq width (abs (difference lo ro))) (setq
list1 (range co bo)) (setq list2 (range co to)) (setq full (list list1
list2)) (setq test (dbCreatePath cv mo full width)) (geDeleteSelSet
win)) (if (geqp cn2 cn1) then (setq co1 (quotient (plus bo to) 2))
(setq widthl1 (abs (difference to bo))) (setq listl1 (range lo co1))
(setq listl2 (range ro co1)) (setq fulll (list listl1 listl2)) (setq
test (dbCreatePath cv mo fulll widthl1)) (geDeleteSelSet win))) (if
(equal (getSGq db objType) "polygon") then (setq mo (getSGq db layer))
(setq h (list 0 0)) (setq s (getSGq db points)) (setq w (quotient
(length s) 2)) (setq p (difference w 1)) (for i 0 (difference
(quotient (length s) 2) 1) (setq m (car (nth w s))) (setq n (car (nth
p s))) (setq q (car (cdr (nth w s)))) (setq f (car (cdr (nth p s))))
(setq z (quotient (plus m n) 2)) (setq x (quotient (plus q f) 2))
(setq stack (list z x)) (setq h (append h (list stack))) (setq w (plus
w 1)) (setq p (difference p 1)) (setq i (plus i 1))) (setq a (cddr h))
(setq wid (abs (difference f q))) (if (nequal wid 0) then (setq id1
(dbCreatePath cv mo a wid)) (setq bboxrec (getSGq db bBox)) (setq
bboxpoly (getSGq id1 bBox)) (if (equal bboxrec bboxpoly) then (setq
test (dbDeleteObject db))) (if (equal (getSGq db objType) "polygon")
then (if (nequal bboxrec bboxpoly) then (geDeselectAllFig)
(geSelectFig id1) (dbDeleteObject id1))))) (if (equal (getSGq db
objType) "polygon") then (setq mo (getSGq db layer)) (setq h2 (list 0
0)) (setq s2 (getSGq db points)) (setq w2 (plus (quotient (length s2)
2) 1)) (setq p2 (difference w2 1)) (for i2 0 (difference (quotient
(length s2) 2) 2) (setq m2 (car (nth w2 s2))) (setq n2 (car (nth p2
s2))) (setq q2 (car (cdr (nth w2 s2)))) (setq f2 (car (cdr (nth p2
s2)))) (setq z2 (quotient (plus m2 n2) 2)) (setq x2 (quotient (plus q2
f2) 2)) (setq stack2 (list z2 x2)) (setq h2 (append h2 (list stack2)))
(setq w2 (plus w2 1)) (setq p2 (difference p2 1)) (setq i2 (plus i2
1))) (setq a2 (cddr h2)) (setq wid2 (abs (difference f2 q2))) (setq
firgetp21 (car (nth 0 s2))) (setq firgetw21 (car (nth 1 s2))) (setq
firmix1 (quotient (plus firgetp21 firgetw21) 2)) (setq firgetp22 (car
(cdr (nth 0 s2)))) (setq firgetw22 (car (cdr (nth 1 s2)))) (setq
firmix2 (quotient (plus firgetp22 firgetw22) 2)) (setq mix12 (list
firmix1 firmix2)) (setq a2 (append a2 (list mix12))) (if (nequal wid2
0) then (setq id2 (dbCreatePath cv mo a2 wid2)) (setq bboxrec2 (getSGq
db bBox)) (setq bboxpoly2 (getSGq id2 bBox)) (if (equal bboxrec2
bboxpoly2) then (setq test (dbDeleteObject db))) (if (equal (getSGq db
objType) "polygon") then (if (nequal bboxrec2 bboxpoly2) then
(geDeselectAllFig) (geSelectFig id2) (dbDeleteObject id2))))) (if
(equal (getSGq db objType) "polygon") then (setq mo (getSGq db layer))
(setq s3 (getSGq db points)) (setq w3 (difference (length s3) 3))
(setq p3 0) (setq h3 (list 0 0)) (setq ldw3 (difference (length s3)
1)) (setq ldp3 (difference (length s3) 2)) (setq lasgetp31 (car (nth
ldp3 s3))) (setq lasgetw31 (car (nth ldw3 s3))) (setq lasmix31
(quotient (plus lasgetp31 lasgetw31) 2)) (setq lasgetp32 (car (cdr
(nth ldp3 s3)))) (setq lasgetw32 (car (cdr (nth ldw3 s3)))) (setq
lasmix32 (quotient (plus lasgetp32 lasgetw32) 2)) (setq mix312 (list
lasmix31 lasmix32)) (setq h3 (append h3 (list mix312))) (for i3 0
(difference (quotient (length s3) 2) 2) (setq m3 (car (nth w3 s3)))
(setq n3 (car (nth p3 s3))) (setq q3 (car (cdr (nth w3 s3)))) (setq f3
(car (cdr (nth p3 s3)))) (setq z3 (quotient (plus m3 n3) 2)) (setq x3
(quotient (plus q3 f3) 2)) (setq stack3 (list z3 x3)) (setq h3 (append
h3 (list stack3))) (setq w3 (difference w3 1)) (setq p3 (plus p3 1))
(setq i3 (plus i3 1))) (setq a3 (cddr h3)) (setq wid3 (abs (difference
n3 m3))) (setq widr (abs (difference f3 q3))) (if (equal wid3 0) then
(setq id3 (dbCreatePath cv mo a3 widr))) (if (equal widr 0) then (setq
id3 (dbCreatePath cv mo a3 wid3))) (setq bboxrec3 (getSGq db bBox))
(setq bboxpoly3 (getSGq id3 bBox)) (if (equal bboxrec3 bboxpoly3) then
(setq test (dbDeleteObject db))) (if (equal (getSGq db objType)
"polygon") then (if (nequal bboxrec3 bboxpoly3) then
(geDeselectAllFig) (geSelectFig id3) (dbDeleteObject id3)))) (if
(equal (getSGq db objType) "polygon") then (setq mo (getSGq db layer))
(setq s4 (getSGq db points)) (setq pl4 (quotient (length s4) 2)) (setq
el4 (quotient pl4 2)) (setq p4 (difference (plus el4 pl4) 1)) (setq w4
(plus el4 pl4)) (setq y4 (difference (quotient (length s4) 2) 1))
(setq t4 0) (setq h4 (list 0 0)) (for i4 0 (difference el4 1) (setq m4
(car (nth w4 s4))) (setq n4 (car (nth p4 s4))) (setq q4 (car (cdr (nth
w4 s4)))) (setq f4 (car (cdr (nth p4 s4)))) (setq z4 (quotient (plus
m4 n4) 2)) (setq x4 (quotient (plus q4 f4) 2)) (setq stack4 (list z4
x4)) (setq h4 (append h4 (list stack4))) (setq w4 (plus w4 1)) (setq
p4 (difference p4 1)) (setq i4 (plus i4 1))) (for il4 0 (difference
el4 1) (setq mn4 (car (nth t4 s4))) (setq nn4 (car (nth y4 s4))) (setq
qn4 (car (cdr (nth t4 s4)))) (setq fn4 (car (cdr (nth y4 s4)))) (setq
zn4 (quotient (plus mn4 nn4) 2)) (setq xn4 (quotient (plus qn4 fn4)
2)) (setq stackn4 (list zn4 xn4)) (setq h4 (append h4 (list stackn4)))
(setq y4 (difference y4 1)) (setq t4 (plus t4 1)) (setq il4 (plus il4
1))) (setq a4 (cddr h4)) (setq wid4 (abs (difference f4 q4))) (if
(nequal wid4 0) then (setq id4 (dbCreatePath cv mo a4 wid4)) (setq
bboxrec4 (getSGq db bBox)) (setq bboxpoly4 (getSGq id4 bBox)) (if
(equal bboxrec4 bboxpoly4) then (setq test (dbDeleteObject db))) (if
(equal (getSGq db objType) "polygon") then (if (nequal bboxrec4
bboxpoly4) then (geDeselectAllFig) (geSelectFig id4) (dbDeleteObject
id4))))) (if (equal (getSGq db objType) "polygon") then (setq mo
(getSGq db layer)) (setq s5 (getSGq db points)) (setq w5 (difference
(quotient (length s5) 2) 2)) (setq p5 (difference w5 1)) (setq wo5
(difference (length s5) 1)) (setq po5 (plus (quotient (length s5) 2)
1)) (setq h5 (list 0 0)) (for i5 0 (difference (quotient (length s5)
2) 3) (setq m5 (car (nth w5 s5))) (setq n5 (car (nth p5 s5))) (setq q5
(car (cdr (nth w5 s5)))) (setq f5 (car (cdr (nth p5 s5)))) (setq z5
(quotient (plus m5 n5) 2)) (setq x5 (quotient (plus q5 f5) 2)) (setq
stack5 (list z5 x5)) (setq h5 (append h5 (list stack5))) (setq w5
(plus w5 1)) (setq p5 (difference p5 1)) (setq i5 (plus i5 1))) (for
io5 0 (difference (quotient (length s5) 2) 4) (setq mo5 (car (nth wo5
s5))) (setq no5 (car (nth po5 s5))) (setq qo5 (car (cdr (nth wo5
s5)))) (setq fo5 (car (cdr (nth po5 s5)))) (setq zo5 (quotient (plus
mo5 no5) 2)) (setq xo5 (quotient (plus qo5 fo5) 2)) (setq stacko5
(list zo5 xo5)) (setq h5 (append h5 (list stacko5))) (setq wo5
(difference wo5 1)) (setq po5 (plus po5 1)) (setq io5 (plus io5 1)))
(setq a5 (cddr h5)) (setq wid5 (abs (difference n5 m5))) (if (nequal
wid5 0) then (setq id5 (dbCreatePath cv mo a5 wid5)) (setq bboxrec5
(getSGq db bBox)) (setq bboxpoly5 (getSGq id5 bBox)) (if (equal
bboxrec5 bboxpoly5) then (setq test (dbDeleteObject db))) (if (equal
(getSGq db objType) "polygon") then (if (nequal bboxrec5 bboxpoly5)
then (geDeselectAllFig) (geSelectFig id5) (dbDeleteObject id5))))) (if
(equal (getSGq db objType) "polygon") then (setq mo (getSGq db layer))
(setq s6 (getSGq db points)) (setq v (plus (quotient (length s6) 2)
1)) (setq v1 (difference (quotient (difference (length s6) v) 2) 1))
(setq w6 (difference (length s6) 1)) (setq p6 (plus (quotient (length
s6) 2) 1)) (setq wo6 (quotient (length s6) 2)) (setq po6 0) (setq h6
(list 0 0)) (for io6 0 (difference (quotient (length s6) 2) 4) (setq
mo6 (car (nth wo6 s6))) (setq no6 (car (nth po6 s6))) (setq qo6 (car
(cdr (nth wo6 s6)))) (setq fo6 (car (cdr (nth po6 s6)))) (setq zo6
(quotient (plus mo6 no6) 2)) (setq xo6 (quotient (plus qo6 fo6) 2))
(setq stacko6 (list zo6 xo6)) (setq h6 (append h6 (list stacko6)))
(setq wo6 (difference wo6 1)) (setq po6 (plus po6 1)) (setq io6 (plus
io6 1))) (setq h6 (reverse (cddr h6))) (for i6 0 v1 (setq m6 (car (nth
w6 s6))) (setq n6 (car (nth p6 s6))) (setq q6 (car (cdr (nth w6 s6))))
(setq f6 (car (cdr (nth p6 s6)))) (setq z6 (quotient (plus m6 n6) 2))
(setq x6 (quotient (plus q6 f6) 2)) (setq stack6 (list z6 x6)) (setq
h6 (append h6 (list stack6))) (setq w6 (difference w6 1)) (setq p6
(plus p6 1)) (setq i6 (plus i6 1))) (setq wid6 (abs (difference n6
m6))) (if (nequal wid6 0) then (setq id6 (dbCreatePath cv mo h6 wid6))
(setq bboxrec6 (getSGq db bBox)) (setq bboxpoly6 (getSGq id6 bBox))
(if (equal bboxrec6 bboxpoly6) then (setq test (dbDeleteObject db)))
(if (equal (getSGq db objType) "polygon") then (if (nequal bboxrec6
bboxpoly6) then (geDeselectAllFig) (geSelectFig id6) (dbDeleteObject
id6))))) (if (equal (getSGq db objType) "polygon") then (setq mo
(getSGq db layer)) (setq s7 (getSGq db points)) (setq v (difference
(quotient (difference (quotient (length s7) 2) 1) 2) 1)) (setq w7
(difference (quotient (length s7) 2) 2)) (setq p7 0) (setq wo7
(difference (length s7) 1)) (setq po7 (difference (quotient (length
s7) 2) 1)) (setq h7 (list 0 0)) (for i7 0 v (setq m7 (car (nth w7
s7))) (setq n7 (car (nth p7 s7))) (setq q7 (car (cdr (nth w7 s7))))
(setq f7 (car (cdr (nth p7 s7)))) (setq z7 (quotient (plus m7 n7) 2))
(setq x7 (quotient (plus q7 f7) 2)) (setq stack7 (list z7 x7)) (setq
h7 (append h7 (list stack7))) (setq w7 (difference w7 1)) (setq p7
(plus p7 1)) (setq i7 (plus i7 1))) (setq h7 (cddr h7)) (setq h7
(reverse h7)) (for io7 0 (difference (quotient (length s7) 2) 3) (setq
mo7 (car (nth wo7 s7))) (setq no7 (car (nth po7 s7))) (setq qo7 (car
(cdr (nth wo7 s7)))) (setq fo7 (car (cdr (nth po7 s7)))) (setq zo7
(quotient (plus mo7 no7) 2)) (setq xo7 (quotient (plus qo7 fo7) 2))
(setq stacko7 (list zo7 xo7)) (setq h7 (append h7 (list stacko7)))
(setq wo7 (difference wo7 1)) (setq po7 (plus po7 1)) (setq io7 (plus
io7 1))) (setq wid7 (abs (difference no7 mo7))) (if (nequal wid7 0)
then (setq id7 (dbCreatePath cv mo h7 wid7)) (setq bboxrec7 (getSGq db
bBox)) (setq bboxpoly7 (getSGq id7 bBox)) (if (equal bboxrec7
bboxpoly7) then (setq test (dbDeleteObject db))) (if (equal (getSGq db
objType) "polygon") then (if (nequal bboxrec7 bboxpoly7) then
(geDeselectAllFig) (geSelectFig id7) (dbDeleteObject id7))))) (if
(equal (getSGq db objType) "path") then (hiDisplayAppDBox ?name (quote
Error) ?dboxBanner "Error" ?dboxText (sprintf nil "Cannot convert Path
to Path") ?buttonLayout (quote UserDefined) ?buttons (list "Close")))
(if (equal (getSGq db objType) "inst") then (hiDisplayAppDBox ?name
(quote Errtor) ?dboxBanner "Error" ?dboxText (sprintf nil "Cannot
convert Instance to Path") ?buttonLayout (quote UserDefined) ?buttons
(list "Close"))) (if (equal test 0) then (hiDisplayAppDBox ?name
(quote ERT) ?dboxBanner "Error" ?dboxText (sprintf nil "Path not
Created, Still the script need tobe updated\n To create the path see
the hints given above") ?buttonLayout (quote UserDefined) ?buttons
(list "Close"))))
(polytopath)

; SKill ends here
 
Ahhhh I didnot see the read more tab,
Compressed code is working fine.
 
No problem Andrew,
Actually I didnot used any comments, becuase I wanna complete the
program first.
This is the experience,
I will try to implement from the next time,
Thanks for your reply,
Cheers,
Sridhar.
 
Congratulations !
Well, it's a pretty big chunk for a first shot, well done :)

I quickly read through your script and it's not that easy to comment
on it.
I just had the chance to realise you have used one single procedure
with roughly 400 lines. I saw however that same patterns did occur
many times in your script. Why don't you create a new procedure that
makes the base calculation and then call it as much as needed from the
main script. This would make your whole program shorter, more
readable, re-usable and easier to debug. This is true for everything:
Divide and rule !

Riad.
 
Thanks Riad,

Why don't you create a new procedure that
makes the base calculation and then call it as much as needed from the
main script. This would make your whole program shorter, more
readable, re-usable and easier to debug.

Yes , I tried like that but the problem is the base calculation is
not the same for all the cases so I need to repeat the things with few
changes in each case.
But I have got another idea, I will try to implement that and make it
shorter.

Cheers,
Sridhar.
 

Welcome to EDABoard.com

Sponsor

Back
Top