Hi All string serverVersion=doorsInfo(3) if(serverVersion0:1 == ?9.?) { #include <addins/RMF_kitchen/utensils/modules.inc> } else { #include <addins/trek/kitchen/utensils/modules.inc> } This doesn't work, because all "#include" clauses are always called (the 'if' test is not taken into account). How can we achive this, so that the specific inc file is called as per the if condition. Thanks Priya PriyaRautray - Fri Jan 06 10:38:18 EST 2012 |
Re: How to conditionally #include inc files const string DXL_addin_path = ((getenv "DOORSHOME") "\\\\lib\\\\dxl\\\\addins"); string serverVersion=doorsInfo(3) print serverVersion0:1 if(serverVersion0:1 == "8.") { eval_(readFile(DXL_addin_path "\\\\someScript_1.dxl")) } else { eval_(readFile(DXL_addin_path "\\\\someScript_2.dxl")) } and in the someScript 1 and 2 (which will be identical apart from the include files) you include the desired .inc file. Hope this helps |
Re: How to conditionally #include inc files
The other Script_1/_2 solution may work. But you will need to use the "addins" variable if the code is on some server, and will need to cleverly parse it looking for semi-colons and trying various paths to see which Script_1.dxl actually exists.
//*****************
string fGetAttrDefDescription(string NameModFull, NameAttr)
{ // Get the 'description' property of the attribute definition.
// Return null when
// o there is no such module
// o its not open
// o there is no such attr def in that module
// o the user cannot read the module or attr def.
// Understand that this is NOT the module 'description' attr value.
// This function is needed to allow scripts that run in v8 of DOORS
// to work, even though the 'description' property was introduced
// in v9. Once scripts will never be used for v8 then this function
// won't be needed as scripts can simply issue:
// string Desc = ad.description
// which generates DXL errors in v8.
// While this is the main function, the overloaded function below:
// string fGetAttrDefDescription(Module mod , AttrDef ad)
// is probably the one most scripts will use.
// Strategy: get the Desciption using 'eval_', and trap and ignore
// any DXL interpret errors.
// Since we are using 'eval_' to which we cannot send a 'Module' parameter,
// this function accepts the module name which we can send to 'eval_'
if (null NameModFull or
null NameAttr)
return("")
string DxlCode = " // Code to get 'description' of Attr Def, generated by function fGetAttrDefDescription().
string fnGetAttrDefDesc()
{ string Results = \"\"
Item itm = item(\"" NameModFull "\")
if (null itm)
{ return(Results) // No such module
}
Module mod = module(itm)
if (null mod)
{ return(Results) // Module not open
}
AttrDef ad = find(mod, \"" NameAttr "\")
if (null ad)
{ return(Results) // No such attribute
}
noError()
Results = ad.description
lastError()
return(Results)
} // end fnGetAttrDefDesc()
return_(fnGetAttrDefDesc())
" // end definition of DxlCode
string ErrMess = checkDXL(DxlCode)
if (!null ErrMess)
{ // print ">>fGetAttrDefDescription, checkDXL ErrMess = " ErrMess ""
return("") // This is probably v8 of DOORS, checkDXL errors expected
}
noError()
string Results = eval_(DxlCode)
lastError()
return(Results)
} // end fGetAttrDefDescription()
//-----------------
string fGetAttrDefDescription(string NameModFull, AttrDef ad)
{ // Overloaded, accepts AttrDef
if (null ad) return("")
string NameAttr = ad.name
return(fGetAttrDefDescription(NameModFull, NameAttr))
} // end overloaded fGetAttrDefDescription(ad)
//-----------------
string fGetAttrDefDescription(Module mod, string NameAttr)
{ // Overloaded, accepts Module handle
if (null mod or null NameAttr) return("")
string NameModFull = fullName(mod)
return(fGetAttrDefDescription(NameModFull, NameAttr))
} // end overloaded fGetAttrDefDescription(mod)
//-----------------
string fGetAttrDefDescription(Module mod , AttrDef ad)
{ // Overloaded, accepts Module handle and AttrDef.
// This is the likely most useful version of this function.
if (null mod or null ad) return("")
string NameModFull = fullName(mod)
string NameAttr = ad.name
return(fGetAttrDefDescription(NameModFull, NameAttr))
} // end overloaded fGetAttrDefDescription(mod, ad)
//*****************
void fSetAttrDefDescription(string NameModFull, NameAttr, Description)
{ // Set the 'description' property of the attribute definition.
// Ignore any errors
// Understand that this is NOT the module 'description' attr value.
// This function is needed to allow scripts that run in v8 of DOORS
// to work, even though the 'description' property was introduced
// in v9. Once scripts will never be used for v8 then this function
// won't be needed as scripts can simply issue:
// ad.description = Description
// which generates DXL interpret errors in v8.
// While this is the main function, the overloaded function below:
// string fGetAttrDefDescription(Module mod , AttrDef ad)
// is probably the one most scripts will use.
// Strategy: set the Description using 'eval_', and trap and ignore
// any DXL interpret errors.
// Since we are using 'eval_' to which we cannot send a 'Module' parameter,
// this function accepts the module name which we can send to 'eval_'
if (null NameModFull or
null NameAttr)
return()
string DxlCode = " // Code to set 'description' of Attr Def, generated by function fSetAttrDefDescription().
string fnSetAttrDefDesc()
{ string Results = \"\"
Item itm = item(\"" NameModFull "\")
if (null itm)
{ return(Results) // No such module
}
Module mod = module(itm)
if (null mod)
{ return(Results) // Module not open
}
AttrDef ad = find(mod, \"" NameAttr "\")
if (null ad)
{ return(Results) // No such attribute
}
noError()
modify(ad, setDescription, \"" Description "\")
lastError()
return(Results)
} // end fnSetAttrDefDesc()
return_(fnSetAttrDefDesc())
" // end definition of DxlCode
string ErrMess = checkDXL(DxlCode)
if (!null ErrMess)
{ // print ">>fSetAttrDefDescription, checkDXL ErrMess = " ErrMess ""
return("") // This is probably v8 of DOORS, checkDXL errors expected
}
noError()
string Results = eval_(DxlCode)
lastError()
return(Results)
} // end fSetAttrDefDescription()
|