I don't know if you are interested in a .NET solution, but with my extremely limited skills in that domain, i was able to assemble something sort of useful.
_$ (getvar "pdmode")
1
_$ (GetVarFromFile "C:\\Test\\test1.dwg" "pdmode")
("33")
_$ (GetVarFromFile "C:\\Test\\test2.dwg" "pdmode")
("0")
_$
.NET source:
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
namespace ACAD_Test
{
public class MyCommands
{
[LispFunction("GetVarFromFile")]
public static object GetVarFromFile(ResultBuffer resbuf)
{
try
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
ResultBuffer rb = new ResultBuffer();
if (resbuf == null)
{
return null;
}
TypedValue[] args = resbuf.AsArray();
string extFile = (string)args[0].Value;
string variable = (string)args[1].Value;
using (Database extDB = new Database(false, true))
{
extDB.ReadDwgFile(extFile, System.IO.FileShare.Read, false, "");
var result = extDB.GetType().GetProperty(variable, System.Reflection.BindingFlags.IgnoreCase | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance).GetValue(extDB, null);
rb.Add(new TypedValue((int)LispDataType.Text, result.ToString()));
}
return (rb.AsArray().Length > 0) ? rb : null;
}
catch (System.Exception Ex)
{
//Application.ShowAlertDialog("System exception:\n" + Ex.Message + "\n" + Ex.Source + "\n" + Ex.StackTrace);
return null;
}
}//GetVarFromFile
}
}
I will attach a compiled dll for those who can't compile it themselves. The target framework is "Net Framework 4.6".
Use "Netload" in ACAD to load the dll. Once the file is loaded, the "GetVarFromFile" function will become available.
Also, have in mind that you need to target the .NET property names ("pstylemode" in .NET is "PlotStyleMode"). Here is a reference to the database properties:
database properties