How to obtain the current KB, or Model

Unofficial Content
IKBService kbserv = UIServices.KB; 

if (kbserv != null && kbserv.CurrentModel != null)  // If the kb is open and current model is selectioned
{ 
string kbDirectory = kbserv.CurrentKB.Location;  // Take path KB Folder(Root)
} 

// Another Examples
string vrLocation = UIServices.KB.CurrentKB.Location;                   // KB(Root)
string vrTargetPath = UIServices.KB.CurrentKB.WorkingModel.TargetPath;  // Web folder
string vrEnderecoCompleto = vrLocation + "\\" + vrTargetPath + "\\web\\"