TheSwamp
Code Red => .NET => Topic started by: gile on June 03, 2009, 02:01:36 AM
-
Hi,
I need to get the support search pathes.
I read it can be done using COM, so I try this :
AcadPreferences prefs = (AcadPreferences)Application.Preferences;
It works fine with 2007, 2008 and 2009 versions but returns an exception with A2010:
"Impossible d'effectuer un cast d'un objet COM de type 'System.__ComObject' en
type d'interface 'Autodesk.AutoCAD.Interop.AcadPreferences'."
"Unable to make a cast of a COM object of type 'System.__ComObject' in
interface type 'Autodesk.AutoCAD.Interop.AcadPreferences."
I know I can have it also reading the registry, but I wanted to know if this problem is knowed and if ther're solutions.
Thanks.
-
an alternative method might be to p/invoke acedGetEnv, I think there are a few examples around
-
there is also a similar thread , http://www.theswamp.org/index.php?topic=20237.0
-
Thanks Daniel
p/invoke methods are still a little over my head, but I'll try.
-
did you see this entry by Master Kerry?
http://www.theswamp.org/index.php?topic=20237.msg246496#msg246496
-
Yes, it seems to be a nice way too.
Thanks again.
-
What is this Master stuff Daniel ... :-D
I'm just an old Lisp hacker trying to keep up.
///kdub
ps: but thanks for the thought :)
-
Another question to the 'masters'
Have I to dispose the IConfigurationSection object got with OpenCurrentProfile() ?
Here's how I wrote the method, is it the good way ?
private void helpButton_Click(object sender, EventArgs e)
{
try
{
using (IConfigurationSection profile = AcApp.UserConfigurationManager.OpenCurrentProfile())
{
string acadProp =(string)profile.OpenSubsection("General").ReadProperty("ACAD", string.Empty);
string[] pathes = acadProp.Split(new char[] { ';' });
string fullName = "";
for (int i = 0; fullName == "" && i != pathes.Length; i++)
{
string path = pathes[i];
if (path != "")
{
string[] files = Directory.GetFiles(path, "cadnormh.chm");
if (files.Length > 0)
fullName = files[0];
}
}
if (fullName != "")
Help.ShowHelp(this, fullName);
else
ed.WriteMessage("Le fichier \"CADnormH.chm\" est introuvable.\n");
}
}
catch (System.Exception ex)
{
ed.WriteMessage(ex.Message);
}
}
-
personally, I don't think you need to call dispose since IConfigurationSection is just an interface class..
but if you want to be on the safe side, do it that way you have it.
just a note, IMO you should initialize empty strings with string.empty and use string.IsNullOrEmpty() to test against null or empty strings :-)
-
I need to get the support search pathes.
Hi Gile,
If you just want to extract the paths, you can use ACADPREFIX system variable - maybe.
-
Thanks again Daniel
I thaught I had to dispose because the interface is disposable.
LE,
You're the man !
Sometimes, I can't see my nose in the middle of my face :oops:
Thanks !
-
LE,
You're the man !
Sometimes, I can't see my nose in the middle of my face :oops:
Thanks !
:)
Merci, tu es le bienvenu
-
From memory, this will not pick up any changes made during the current session, as the registry is written on AutoCAD shutdown...at least that's what I recall anyway...
-
Hi Gile,
I normally find my file depencies, based on the location of my application, maybe if you use something like:
public string GetAppPath()
{
System.Reflection.Module[] modules = System.Reflection.Assembly.GetExecutingAssembly().GetModules();
string aPath = System.IO.Path.GetDirectoryName(modules[0].FullyQualifiedName);
if ((aPath != "") && (aPath[aPath.Length - 1] != '\\'))
{
aPath += '\\';
}
return aPath;
}
for example:
Command: APPATH
C:\Programming\C#\BlockManager\bin\Debug\
string file = "cadnormh.chm";
string lookFor = appPath + file;
-
Muchas gracias Luis
Most of the time the help file should be in the same folder as the dll, but if the user has moved it to another folder in the search path, I'd rather use something like the findfile LISP function.
Your snippet will be usefull for a newby like me.
-
I'd rather use something like the findfile LISP function.
then, let see if this works... not fully tested (on A2009) - maybe :)
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "acedFindFile")]
static extern int FindFile(StringBuilder fname, StringBuilder result);
[CommandMethod("TestFind")]
public void testfind()
{
Document doc = acadApp.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
StringBuilder sResult = new StringBuilder(128);
StringBuilder sSearch = new StringBuilder("acad.exe");
FindFile(sSearch, sResult);
ed.WriteMessage("{0}", sResult);
}
-
.Net has a findfile, no need to import from a dll. FYI...
HostApplicationServices.Current.FindFile
-
.Net has a findfile, no need to import from a dll. FYI...
HostApplicationServices.Current.FindFile
I saw that... and did not tested... :)
Thanks, Tim.
-
.Net has a findfile, no need to import from a dll. FYI...
HostApplicationServices.Current.FindFile
I saw that... and did not tested... :)
Thanks, Tim.
I use it in one of my codes. You're welcome Luis.
Edit: Added said code.
public static string WillLoad (string FilePath, Database db) {
string FoundAt = "";
string[] tempStrAr = FilePath.Split('.');
string FileExt = tempStrAr[tempStrAr.Length - 1];
[color=red] try { FoundAt = HostApplicationServices.Current.FindFile(FilePath, db, FindFileHint.Default); }[/color]
catch {}
if ( !string.Compare(FoundAt, string.Empty).Equals( 0 ) )
return FoundAt;
if (string.Compare(FilePath.Substring(0, 2), "..").Equals(0) || string.Compare(FilePath.Substring(0, 1), ".").Equals(0)) {
string[] XrPathArray = FilePath.Split('\\');
string PartialPath = "";
for (int i = 1; i < XrPathArray.Length; ++i) {
PartialPath = PartialPath + "\\" + XrPathArray[i];
}
FileInfo DwgInfo = new FileInfo(db.Filename);
string tempFilePath = DwgInfo.DirectoryName + PartialPath;
try { FoundAt = HostApplicationServices.Current.FindFile(tempFilePath, db, FindFileHint.Default); }
catch {}
if ( !string.Compare(FoundAt, string.Empty).Equals( 0 ) )
return FoundAt;
}
return string.Empty;
}
-
.Net has a findfile, no need to import from a dll. FYI...
HostApplicationServices.Current.FindFile
I saw that... and did not tested... :)
Thanks, Tim.
I use it in one of my codes. You're welcome Luis.
10-4
been out of the c# coding for a while until early today, that I played a little bit :)
-
Thank you both :-o
But all this is quite over my head, the only attributes I use at the moment are CommandMethod and LispFunction.
Today, I'm proud I've been able to get the support files search path folders (using COM, Registry reading, ConfigurationManager or DWGPREFIX sysvar) and iterate through them to search a file.
I'll try to study all this, but it's so far from my little LISP knowledge.
-
http://www.mccad.net/bbs/dispbbs.asp?boardID=33&ID=75736&page=2
-
Thanks :)
See if this works
http://www.microsofttranslator.com/BV.aspx?ref=IE8Activity&a=http%3a%2f%2fwww.mccad.net%2fbbs%2fdispbbs.asp%3fboardID%3d33%26ID%3d75736%26page%3d2