How to check if lib, cell, or view exists?

R

Reotaro Hashemoto

Guest
Hi,

I was using a SKILL code to let the use graphically browse for a cell.
I tried to check if the lib, cell, or view exists, and if not print an
error message and return nil.

This is my trial:
libName = CSForm->srcLib->value
cellName = CSForm->srcCell->value
viewName = CSForm->srcView->value

; Try to check if lib, cell, and view exists otherwise give error and
return(nil)!!!
prog(()
when( null(ddGetObj(libName))
printf("Unkown library %L" libName)
return(nil)

when( null(ddGetObj(libName cellName))
printf("Unknown cell %L" cellName)
return(nil)

when( null(ddGetObj(libName cellName viewName))
printf("Unknown view %L" viewName)
return(nil)
)
)
)
); prog

I can't catch why it is not working..

Any notice?
Thanks,
Ahmad
 
Reotaro Hashemoto wrote, on 06/25/09 08:52:
Hi,

I was using a SKILL code to let the use graphically browse for a cell.
I tried to check if the lib, cell, or view exists, and if not print an
error message and return nil.

This is my trial:
libName = CSForm->srcLib->value
cellName = CSForm->srcCell->value
viewName = CSForm->srcView->value

; Try to check if lib, cell, and view exists otherwise give error and
return(nil)!!!
prog(()
when( null(ddGetObj(libName))
printf("Unkown library %L" libName)
return(nil)

when( null(ddGetObj(libName cellName))
printf("Unknown cell %L" cellName)
return(nil)

when( null(ddGetObj(libName cellName viewName))
printf("Unknown view %L" viewName)
return(nil)
)
)
)
); prog

I can't catch why it is not working..

Any notice?
Thanks,
Ahmad
Ahmad,

Because it will never reach the second when if the library exists. The first
condition is null(ddGetObj(libName)) - that will be true if the library does not
exist, and so the whole of the code inside the when body only gets executed if
the library does not exist. The same is true for the second when.

A better approach is:

cond(
(!ddGetObj(libName)
printf("Unknown library %s\n" libName)
nil)
(!ddGetObj(libName cellName)
printf("Unknown cell %s\n" cellName)
nil)
(!ddGetObj(libName cellName viewName)
printf("Unknown view %s\n" viewName)
nil)
; it exists, so return t
(t t)
)

cond() is essentially an efficient and compact if-elseif-elseif-else type form.

Regards,

Andrew.
 

Welcome to EDABoard.com

Sponsor

Back
Top