Using OpenSTAAD Application Object
Using OpenSTAAD Application Object
Connection
The following section will describe how to connect to the STAAD.Pro application using OpenSTAADUI object.
Get the StaadPro application associated with opened STAAD file,
public static OpenSTAAD GetSTAADUIInterface(string staadFilename)
{
OpenSTAAD osObject = null;
try
{
Type type = Type.GetTypeFromProgID("StaadPro.OpenSTAAD");
[DllImport("ole32.dll")]
private static extern int CreateBindCtx(int reserved, out System.Runtime.InteropServices.ComTypes.IBindCtx ppbc);
private static Hashtable GetRunningObjectTable()
{
try
{
Hashtable result = new Hashtable();
IntPtr numFetched = new IntPtr();
System.Runtime.InteropServices.ComTypes.IRunningObjectTable runningObjectTable;
System.Runtime.InteropServices.ComTypes.IEnumMoniker monikerEnumerator;
System.Runtime.InteropServices.ComTypes.IMoniker[] monikers = new System.Runtime.InteropServices.ComTypes.IMoniker[1];
GetRunningObjectTable(0, out runningObjectTable);
runningObjectTable.EnumRunning(out monikerEnumerator);
monikerEnumerator.Reset();
while (monikerEnumerator.Next(1, monikers, numFetched) == 0)
{
System.Runtime.InteropServices.ComTypes.IBindCtx ctx;
CreateBindCtx(0, out ctx);
string runningObjectName;
monikers[0].GetDisplayName(ctx, null, out runningObjectName);
object runningObjectVal;
runningObjectTable.GetObject(monikers[0], out runningObjectVal);
result[runningObjectName] = runningObjectVal;
}
return result;
}
catch (Exception)
{
throw;
}
}
}
}
catch (COMException ex)
{
return 0;
}
return 0;
}