TheSwamp
Code Red => .NET => Topic started by: Kerry on November 30, 2007, 12:18:01 AM
-
Question :
I'm trying to retrieve the Acad Search Path variable value
equivalent to (GetEnv "ACAD") in Lisp
As far as I can determine this can't be done with the NET API Library
Anyone have any ideas about a (GetEnv ... and (SetEnv ... equivalent in C# ?
Something similar to one of these :-
-
I don't see a way with reflector, or in the Arx docs, as the way you would do it in lisp, it doesn't look like you can with C#. Lisp would be
(vla-get-SupportPath
(vla-get-Files
(vla-get-Preferences
(vlax-get-Acad-Object)
)
)
)
You can get an object, from the Application object, for the Preferences, but I don't know what you can get from there.
-
Thanks Tim, that was my conclusion too.
there is AN AcedGetEnv(.. in arx that may perhaps could be PEnvoke'd ... but I'm lost there ..
.. or at a pinch, perhaps the ActiveX methods used in VLisp and vba could be addressed via COM.
My brains not working at the moment, so I'll come back to it.
-
I'm guessing here. Would info in this post be helpful?
http://www.theswamp.org/index.php?topic=10017.msg135522#msg135522
Can you access "Vl.Application.16" via C#?
-
This is trying with Autodesk.AutoCAD.Interop referenced
I'm out of my depth here ... [gurgle, gurgle, gurgle ]
the piccy to prove it :
-
like a dog at a bone ....
-
Kerry,
I was going to post up how to do the COM thing once I returned from walking the mutt, but I see you've already done it.
Here (http://www.theswamp.org/lilly_pond/GlennR/acedGetEnv.html) is an implementation of a wrapper for acedGetEnv.
If you look at the docs, it tells you that acedgetenv will look in a particular registry key for the value or failing that, the windows sys env table. You could use the built-in acad .net functions to find the product root key and then do a reg search thru .net, then the system environment variables if you wanted to implement your own.
Cheers,
Glenn.
-
Thanks Glenn.
That's the direction I wanted to head in next.
I noticed you called that 'setenvwrapper' ..
do you actually have a setenvwrapper using acedGetEnv acedSetEnv ? <<<< EDIT
-
Sorry Kerry, that was a slip of the fingers on this UK keyboard :-) It was supposed to be getenv...
-
I've heard the spelling over there is weird too !
:-D
ps: I really meant using acedSetEnv
-
Here (http://www.theswamp.org/lilly_pond/GlennR/acedGetSetEnvWrappers.html) is an updated code file with both acedGetEnv and acedSetEnv.
Is that what you're after?
Cheers,
Glenn.
-
Sorry Kerry, that was a slip of the fingers on this UK keyboard :-) It was supposed to be getenv...
Is this a permanent relocation, or are you just visiting?
-
Hey Chuck,
Permanent, or at least until we decide to go someplace else :-)
Shipped the dog and the cat as well. Max (the beagle), seems to be loving it - all the new smells and cooler weather. The cat doesn't seem to care one way or the other as long as there's food and a heater to sleep by.
Cheers,
Glenn.
-
Here (http://www.theswamp.org/lilly_pond/GlennR/acedGetSetEnvWrappers.html) is an updated code file with both acedGetEnv and acedSetEnv.
Is that what you're after?
Cheers,
Glenn.
perfectamundo !
I hope Jane was happy to see the animules.
.. I bet Surrey is a little greener than the landscape you left here.
-
Well done Kerry and Glenn.
Autodesk.AutoCAD.Interop wasn't in my cad but I did find it in Objectarx 2008\inc
-
I hope Jane was happy to see the animules.
.. I bet Surrey is a little greener than the landscape you left here.
Yes, she was, but it didn't take her long to remember what a pain the mutt can be.
Yeah, it's green here and blasted brown if not bare earth there.
Cheers,
Glenn.
-
Well done Kerry and Glenn.
Autodesk.AutoCAD.Interop wasn't in my cad but I did find it in Objectarx 2008\inc
It should be on the COM tab in the add reference dialog Bryce. Kerry should be able to post a nice piccy of the entries you need to reference seeing as he's snagit happy at the moment ;)
-
Well done Kerry and Glenn.
Autodesk.AutoCAD.Interop wasn't in my cad but I did find it in Objectarx 2008\inc
It should be on the COM tab in the add reference dialog Bryce. Kerry should be able to post a nice piccy of the entries you need to reference seeing as he's snagit happy at the moment ;)
OK
just Reference the AutoCAD 2008 Type Library
and add the using statement
using Autodesk.AutoCAD.Interop;
added:
just realised, these threads must look weird if the viewer isn't logged in ( a member) ... cause the piccys really do tell a story :-)
-
Thanks mate. Picture is worth a 1000 beers.
-
And Kerry is the king of piccies :-D
-
And Kerry is the king of piccies :-D
[you] can be as well !
http://www.theswamp.org/index.php?topic=20184.msg245455#msg245455
I'm just too lazy to write properly .. succinct is difficult.
**
[you] of course being [you the reader].
-
Duly noted my friend.
Cheers,
Glenn.
-
what about: Autodesk.AutoCAD.ApplicationServices.UserConfigurationManager ????
-
Haven't tried that Chumplybum .. have you ?
-
sorry, I was board :laugh:
AcMgdWrprs.Utilities.GetEnv("ACAD")
for 2007
-
this is the same as (getenv "ACAD")...
Dim UserConfigurationManager As Autodesk.AutoCAD.ApplicationServices.UserConfigurationManager = Autodesk.AutoCAD.ApplicationServices.Application.UserConfigurationManager
Dim ProfileBase As Autodesk.AutoCAD.ApplicationServices.IConfigurationSection = UserConfigurationManager.OpenCurrentProfile
Dim GeneralRegKey As Autodesk.AutoCAD.ApplicationServices.IConfigurationSection = ProfileBase.OpenSubsection("General")
System.Windows.Forms.MessageBox.Show(GeneralRegKey.ReadProperty("ACAD", "").ToString)
-
cool !
I'll have a play tonight ... Thanks.
-
Yes,Mark, that seems fine.
I made a method that's a little more generic
Haven't tested for invalid data in this version ...
public static object GetProfileEntry(string sSubSection, string sProperty)
{
UserConfigurationManager ucManager = Application.UserConfigurationManager;
IConfigurationSection currentProfile = ucManager.OpenCurrentProfile();
IConfigurationSection subSection = currentProfile.OpenSubsection(sSubSection);
return subSection.ReadProperty(sProperty, "");
}
A piccy for Joe ..
-
I s'pose there's really no need for a method when we can do it in-line without intermediate variable assignments ..
string sSupportPath = AcadApp.UserConfigurationManager.OpenCurrentProfile().
OpenSubsection("General").ReadProperty("ACAD", "").ToString();
-
I s'pose there's really no need for a method when we can do it in-line without intermediate variable assignments ..
string sSupportPath = AcadApp.UserConfigurationManager.OpenCurrentProfile().
OpenSubsection("General").ReadProperty("ACAD", "").ToString();code]
True, but the function looks better; is easier to read and if one property in that 'property chain' fails, it's a lot harder to debug...just some thoughts.
Cheers,
Glenn.
-
I've coded this as an exercise in answer to a question elsewhere.
The p/Envoke for GetEnv and SetEnv seemed the easiest way to handle the Variables stored in the Fixed Profile ->General section of the registry.
.. Other Variables are stored in Profiles-> <<UserProfile>> -> General
any tips for improvement appreciated.
// (C) CodeHimBelonga kdub @TheSwamp 20091017
//
using System;
using System.Text;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;
// This line is not mandatory, but improves loading performances
[assembly: CommandClass(typeof(KDUB_testing.MyTestCommands))]
namespace KDUB_testing
{
public class MyTestCommands
{
// p/Envoke from Acad.exe
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("acad.exe",
CharSet = CharSet.Auto,
CallingConvention = CallingConvention.Cdecl)]
private static extern int acedGetEnv(string envName, StringBuilder ReturnValue);
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("acad.exe",
CharSet = CharSet.Auto,
CallingConvention = CallingConvention.Cdecl)]
private static extern int acedSetEnv(string envName, StringBuilder NewValue);
//--------------
[CommandMethod("DoIt", CommandFlags.Modal)]
public void MyGetEnv()
{
Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
string mainCuiFile = AcadApp.GetSystemVariable("MENUNAME") as string;
ed.WriteMessage("\nMenuName : {0}", mainCuiFile);
const int maxResultLength = 1024;
StringBuilder sbRes = new StringBuilder(maxResultLength);
acedGetEnv("ACAD", sbRes);
ed.WriteMessage("\nValue of ACAD environment variable: {0}", sbRes.ToString());
acedGetEnv("AcetMoveBak", sbRes);
ed.WriteMessage("\n\nMoveBak Variable: {0}", sbRes.ToString());
//--------------
// assume the folder exists for this exercise
StringBuilder sbResNew = new StringBuilder("c:\\DWG-BAK\\Auto");
acedSetEnv("AcetMoveBak", sbResNew);
acedGetEnv("AcetMoveBak", sbRes);
ed.WriteMessage("\n\nMoveBak Variable is Now : {0}", sbRes.ToString());
}
}
}
-
perfect!
-
except as Tony T pointed out ... we don't need a StringBuilder for the acedSetEnv ... a String is sufficient.
[ long distance critique appreciated :) ]
-
True, I thought of that too , but then again depends on the usage, example;
if I wanted to append search paths to the environment "ACAD" then Stringbuilder might be more efficient.
-
you could always make it overloaded :-)
namespace ExecMethod
{
public static class Commands
{
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("acad.exe", CharSet = CharSet.Auto,
CallingConvention = CallingConvention.Cdecl)]
internal static extern int acedGetEnv(string envName, StringBuilder ReturnValue);
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("acad.exe", CharSet = CharSet.Auto,
CallingConvention = CallingConvention.Cdecl)]
internal static extern int acedGetEnv(string envName, string ReturnValue);
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("acad.exe",CharSet = CharSet.Auto,
CallingConvention = CallingConvention.Cdecl)]
internal static extern int acedSetEnv(string envName, StringBuilder NewValue);
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("acad.exe",CharSet = CharSet.Auto,
CallingConvention = CallingConvention.Cdecl)]
internal static extern int acedSetEnv(string envName, string NewValue);
[CommandMethod("doit")]
static public void doit()
{
try
{
AcEd.Editor editor =
AcAp.Application.DocumentManager.MdiActiveDocument.Editor;
string env = new string(char.MinValue, 1024);
acedGetEnv("ACAD", env);
acedSetEnv("ACAD", env);
editor.WriteMessage("{0}", env);
}
catch (System.Exception ex)
{
AcAp.Application.DocumentManager.
MdiActiveDocument.Editor.WriteMessage
("\n{0}\n{1}", ex.Message, ex.StackTrace);
}
}
}
}
-
You're a sick puppy Fronkensteen :wink: