Author Topic: UserConfigurationManager  (Read 3758 times)

0 Members and 1 Guest are viewing this topic.

ReneRam

  • Guest
UserConfigurationManager
« on: July 07, 2008, 11:29:19 AM »
 :oops: I'm embarrassed, I made this question off the board, and should have done public.

I have developed a few apps in Vb.Net that perform some tasks in AutoCAD, and we use them in our company where I have access to all computers. All our computers have Windows Xp Pro with AutoCAD 2008. All these apps have some support files (.lin, .mln, .lsp, .mbd, blocks, templates,...). Sometimes we give them out to our collaborators so they can give us the drawings formatted the same way we do them.
When developing, all my files are in the "C:\Documents and Settings\user\Documents\Visual Studio 2005\Projects\...\...\bin\Debug\" directory, and since I simply copy them from one PC to the other I have no problem while updating dll's or support files. By the way, all the support files are stored in the "C:\Documents and Settings\All Users\Dati applicazioni\..." directory that I can access as administrator.
The problem that rises now is the following:

In our company we're getting some Windows Vista computers, and some of our collaborators started complaining that not always our AutoCAD installation path is the same as the one they have, and they don't want, which is correct, to change the installation they have.
I was trying to solved the problem with the "UserConfigurationManager" and found these two post:


http://www.theswamp.org/index.php?topic=22942.msg275946#msg275946



http://www.theswamp.org/index.php?topic=23012.msg276589#msg276589


but I haven't been able to make this:

Quote
I have coded the following, and as tested it works - in vb.net

Code: [Select]
Public Shared Sub UpdateProfile()
            'Cast the current autocad application from .net to COM interop
            Dim oApp As Autodesk.AutoCAD.Interop.AcadApplication = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication
            'Get the user preferences on the current profile
            Dim profile As AcadPreferences = oApp.Preferences
            'Configure the default preferences
            Try
            Dim server As String = ReadSupportLocation()
'Printer configuration path
oApp.Preferences.Files.PrinterConfigPath = server + "\Plotters\Configuration"
'Printer description path
oApp.Preferences.Files.PrinterDescPath = server + "\Plotters\PMP Files"
'Printer style sheet path
oApp.Preferences.Files.PrinterStyleSheetPath = server + "\Plotters\Styles"
'Plot log file location
oApp.Preferences.Files.PlotLogFilePath = server + "\Plotters\Logs"
'Template settings
oApp.Preferences.Files.TemplateDwgPath = server + "\Templates"
'Support Paths
Dim supportpaths() As String = Split(oApp.Preferences.Files.SupportPath, ";")
Dim supportlist As New List(Of String)
For i As Integer = 0 To UBound(supportpaths)
supportlist.Add(supportpaths(i))
Next
'Add applications directory
If Not supportlist.Contains(server + "\Applications") Then
supportlist.Add(server + "\Applications")
End If
'Add images directories
If Not supportlist.Contains(server + "\Images\Internal") Then
supportlist.Add(server + "\Images\Internal")
End If
If Not supportlist.Contains(server + "\Images\External") Then
supportlist.Add(server + "\Images\External")
End If
'Format new support path string
Dim supportpath As String = Nothing
For Each item As String In supportlist
supportpath = supportpath + item + ";"
Next
'Add new support
oApp.Preferences.Files.SupportPath = supportpath
Catch ex As Exception

End Try
End SubYou can access more settings using the oApp.Preferences
 
 
work.

The idea I had was to publish the application with VS 2005 and then, after the setup, on the first run add my newly created path to AutoCAD's support search path through the "UserConfigurationManager".
Any help appreciated, thanks in advance.
René

sinc

  • Guest
Re: UserConfigurationManager
« Reply #1 on: July 07, 2008, 11:46:23 AM »
That's a little hard to follow...  I think there are a number of things you might do differently that would clean this up...

But to answer your most-important question, I think you're looking for the System.Environment class in the .NET classes.  For example, to get the equivalent of Documents and Settings/All Users on either XP or Vista, use the following:

Code: [Select]
string filePath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonApplicationData);
You'll get the correct directory, regardless of whether the user is on XP or Vista.

ReneRam

  • Guest
Re: UserConfigurationManager
« Reply #2 on: July 07, 2008, 11:57:04 AM »
That's a little hard to follow...  I think there are a number of things you might do differently that would clean this up...

But to answer your most-important question, I think you're looking for the System.Environment class in the .NET classes.  For example, to get the equivalent of Documents and Settings/All Users on either XP or Vista, use the following:

Code: [Select]
string filePath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonApplicationData);
You'll get the correct directory, regardless of whether the user is on XP or Vista.

This is what I'm doing at the moment:
Code: [Select]
myAppDataDir = My.Computer.FileSystem.SpecialDirectories.AllUsersApplicationData

and it works.
What I'm trying to do is get rid of the SpecialDirectories and put everything in a simple MyProgram directory that can be accessed with no special permission.

Glenn R

  • Guest
Re: UserConfigurationManager
« Reply #3 on: July 07, 2008, 03:16:30 PM »
First off, don't be embarrassed - I suggested posting to the board so you might get opinions other than mine and also, other members might provide a solution other than/quicker than I can at the moment.

Secondly, ditch the 'userconfigurationmanager', because as I alluded to in one of those threads you quoted (I think) and Dan confirmed in this thread, it doesn't behave as expected and gives undesirable results.

Thirdly, what part of the code you posted doesn't work? Are you getting an error or what?

Cheers,
Glenn.
« Last Edit: July 07, 2008, 03:30:14 PM by Glenn R »

Glenn R

  • Guest
Re: UserConfigurationManager
« Reply #4 on: July 07, 2008, 03:18:19 PM »
The reason I ask is that, other than setting ACAD= in a batch file to start acad (which is not an option for you as you have 3rd parties) the best way to add paths to Acad is through COM interop unfortunately...

Glenn R

  • Guest
Re: UserConfigurationManager
« Reply #5 on: July 07, 2008, 03:29:16 PM »
Rene,

After re-reading your original post in this thread, there are a LOT of different ways to configure what I think you want, but I would need you to be clearer with what exactly you are trying to accomplish.

Cheers,
Glenn.

ReneRam

  • Guest
Re: UserConfigurationManager
« Reply #6 on: July 07, 2008, 06:12:21 PM »
Sorry for the delay, I've been out for dinner :whistle:
Actually my code works, I can fix the support path in each of the AutoCAD's installed for the different users in every computer in my office, and if needed I can move to another office we have not far away, just a few hours drive (one working day!).
Since the software that I develop is not made for commercial purposes I never have the need of creating a deployment, I just copy the dll's or the exe and register, if needed, activex's.

The best thing would be to create an installer like the ones I get in some third party programs (AutoTURN or Acroplot), in which you run the setup and get everything done: support path added to AutoCAD, toolbars, menus and everything else, but that's beyond my actual knowledge, I tried with VS 2005 creating a "Setup and Deployment" Project, but haven't found out how to add "C:\Documents and Settings\All Users\Dati applicazioni\..." directory to it. By the way I had chosen this one because it was present in Windows 2000 and Windows XP, so I didn't have to add that much of a support path to AutoCAD, I already knew where to look for my support files! :wink: It  seemed a good idea before Vista changed the naming of these directories (things I learned when it was to late).
Now, since I have to change distributing method to accomplish external collaborators requests, I thought that a simple "Setup and Deployment" and a modification to the "UserConfigurationManager" adding a support path was an acceptable solution, but after your replies Glenn
Quote
Secondly, ditch the 'userconfigurationmanager', because as I alluded to in one of those threads you quoted (I think) and Dan confirmed in this thread, it doesn't behave as expected and gives undesirable results.
I guess I might been seeking in some other direction.
Thanks for your time and attention, I just love this place!
If you have any other suggestion I should try exploring, just point at it and I'll follow.
René

P.S.
I have allways accomplished my duties in VB, but after a while swimming in TheSwamp, in trying to migrate myself to C#, it seems that all you guys in here find it better, even if uncle Bill says they're the same!
 :angel:

sinc

  • Guest
Re: UserConfigurationManager
« Reply #7 on: July 07, 2008, 07:15:52 PM »
Well, "better" is a loaded term...

VB has at least one feature that I wish C# had.  In VB, it's possible to have optional parameters to methods.  In C#, this must be accomplished by overloading methods.  In some cases, it's far easier to create one method signature with optional parameters than create an overloaded signature for all the possible variations of arguments.

But other than that, I've just never really liked VB syntax, even though I started to learn to program with Basic, way back when.  It drives me batty.  I can program in VB just fine, I just don't like it.

Glenn R

  • Guest
Re: UserConfigurationManager
« Reply #8 on: July 08, 2008, 02:22:50 AM »
VB has at least one feature that I wish C# had.  In VB, it's possible to have optional parameters to methods.  In C#, this must be accomplished by overloading methods.

params keyword.

sinc

  • Guest
Re: UserConfigurationManager
« Reply #9 on: July 08, 2008, 09:02:01 AM »
The PARAMS keyword isn't the same thing.

I'm talking about the ability to do this:

Code: [Select]
void method(double d, optional string s, optional bool b)
{
   // code
}

instead of this:

Code: [Select]
void method(double d)
{ method(d, false); }

void method(double d, string s)
{ method(d, s, false); }

void method(double d, bool b)
{ method(d, "", b); }

void method(double d, string s, bool b)
{
   // code
}

[edited to fix syntax]
« Last Edit: July 08, 2008, 07:32:20 PM by sinc »

MickD

  • King Gator
  • Posts: 3637
  • (x-in)->[process]->(y-out) ... simples!
Re: UserConfigurationManager
« Reply #10 on: July 08, 2008, 06:39:42 PM »
Well...all parameters are optional really :laugh:
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: UserConfigurationManager
« Reply #11 on: July 08, 2008, 07:45:58 PM »
Well...all parameters are optional really :laugh:

:-)

and depending on the user, some are more optional than others.


sinc,
personally I prefer the discipline of  overloading .. it's not as if each method needs to be duplicated.

I'd be interested in having a look via Reflection at some VB.net code that has been compiled ... just to see how much overhead code is required behind the scenes.


kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

sinc

  • Guest
Re: UserConfigurationManager
« Reply #12 on: July 08, 2008, 11:29:21 PM »
It basically creates a bunch of overloads, the same as C#.  It's simply a short-hand, almost like a macro.  That's why I say it would be handy.  But it's not worth switching to VB over.   8-)