Strange Error / python

Hello guys ,
Recently i encountered an strange error which i could not find anything about it when i searched it , at least there is not anything about it in python , all i found was about the error in C# and other languages but nothing in python , can anyone tell me something about it here !?
The error is :

Runtime error (InvalidCastException): Specified cast is not valid.

Please post your code, it is difficult to pinpoint the problem without it.

If I may hazard a guess, you are calling code from RhinoCommon, which is .NET. Then you assume an object to be of a certain type, but it is not. Then either your code, or the framework code tries to caat it to another type, which gives this error.

Hello @menno , thank you for your reply , i posted my code in Grasshopper category , i will copy the link here for more explanation on script please take a look at it .
thank you for your time .
here is the link :

Sorry, I cannot get 2 to work and I don’t understand what either script is supposed to achieve. You’re better off asking someone else I’m afraid.