What's new

AD instance trought API

pem

Member
AD instance trought API

I'm developing a plugin for Alibre in .NET.

Is there any chance to start AD trought API?

Now I'm reading path to AD installation directory from registry
(SOFTWARE\\Alibre, Inc.\\Alibre Design\\), starting process, wait for it and
get:
AlibreX.AutomationHook ahook =
(AlibreX.AutomationHook)Marshal.GetActiveObject("AlibreX.AutomationHook");
AlibreX.IADRoot aRoot = (IADRoot)ahook.Root


Pem
 

alexfranke

Senior Member


Hi pem,

Here's an example that gets the root of the running instance of AD, or starts it in headless mode if it's not already open. I don't know if this is what you're looking for -- one thing I don't get is why you would launch it from a plug-in. (Isn't it already running if it's hosting your plug-in? Or are you doing the kind of app that I've been writing that's more of an automation driver than a plug-in?)

Hope this helps!
Cheers,
Alex

Code:
private void DoSomething() 
{
    IADRoot root = GetADRoot();
    root.OpenFile(@\"D:\\AlibreProjects\\MyPart.AD_PRT\");
    Console.WriteLine(root.Sessions.Item(0).Name);
}

private IADRoot GetADRoot()
{
    AutomationHook hook = null;
    try 
    {
        hook = (AutomationHook)Marshal.GetActiveObject(\"AlibreX.AutomationHook\");
    }
    catch 
    {
        hook = new AutomationHook();
        hook.Initialize(GetADServerAddress(), \"\", \"\", false, 0);
    }
    return (IADRoot)hook.Root;
}

private string GetADServerAddress()
{
    try
    {
        Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser;
        key = key.OpenSubKey(\"Software\");
        key = key.OpenSubKey(\"Alibre, Inc.\");
        key = key.OpenSubKey(\"Alibre Design\");
        return (string)key.GetValue(\"ServerAddress\");
    }
    catch (Exception e)
    {
        System.Diagnostics.Trace.WriteLine(\"Error reading registry. Detail: \" + e.ToString()); 
    }
    return \"\"; // default
}
 

pem

Member
Re:

Thanks, for reply.
My app is (or would be;) something more than plugin.
Your example is working very well, but I have one more question:
How to make AD UI "visible" after open it in this way?
I was trying open file by: root.OpenFileWithUI(...), but this metod isn't
working.

regards
pem
 
Top