TheSwamp

Code Red => .NET => Topic started by: Jeff_M on April 17, 2007, 07:37:42 PM

Title: MS Visual Studio C# or SharpDevelop?
Post by: Jeff_M on April 17, 2007, 07:37:42 PM
I've been (ab)using, er learning, MSVS for some time and have grown accustomed to the display. Wanting to add a few commands to Sinc's quite useful Civil3D commands I tried to place his Project into my VS Projects folder. HA! I get lots of warnings on opening, namely "The file 'AutocadUtilities\C3DUtil.cs' could not be added to the project.  Cannot add a link to the file C:\Documents and Settings\Master\My Documents\Visual Studio 2005\Projects\Sincpac\Sincpac\AutocadUtilities\C3DUtil.cs. This file is within the project directory tree." etc. Being about as bright as a brick in this VS stuff I cannot figure out how to edit Sinc's code in VS.

OK, no problem, I'll just download and install SharpDevelop! Great, everything goes as planned, unzip the project to the SD Projects folder and AH HA! I can open and edit without any problems. Except.......the interface is a bit different, the (excuse my ignorance in the correct terminology) known types are not highlighted, the code dosen't seem to want to auto format itself, and some other things I'm not recalling right now. Oh, and I got 2 Fatal Errors while just looking around at Sinc's code and 1 more when attempting to build it.  So I'm finding it is giving me headaches looking at the code in SD.

So, can anyone give me step by step instructions on How-To either use this code in VS2005 OR get SD to appear similar to VS2005?

Thanks!
Jeff "the brick"
Title: Re: MS Visual Studio C# or SharpDevelop?
Post by: LE on April 17, 2007, 07:56:30 PM
Jeff;

Is Sinc's a SLN or just the class file for a C# project?

I use VS2005
Title: Re: MS Visual Studio C# or SharpDevelop?
Post by: MickD on April 17, 2007, 08:06:57 PM
The easiest way would be to create a class library project, copy the source files and paste them into the new project folder and add them to the project (removing any existing project files if needed) and 'ref' in any lib's you need to link against and you should be right to go.
This applies to both ide's.

The import feature is nice but there is work arounds.
hth
Title: Re: MS Visual Studio C# or SharpDevelop?
Post by: Jeff_M on April 17, 2007, 08:13:22 PM
There's a SLN. The complete source code can be found near the bottom of  THIS  (http://www.ejsurveying.com/sincpacc3d.htm) page.

I'm about to head for a dinner engagement but I'll be back later tonight. So if you don't hear from me for a while it's not because I'm ignoring anyone. :-)

Oops, Mick snuck in there. Thanks, I was hoping to be able to avoid that as he has quite a number of CS files and forms. But if I must.....
Title: Re: MS Visual Studio C# or SharpDevelop?
Post by: LE on April 17, 2007, 08:30:38 PM
To bad I do not use C3D, but you can remove those References and do the manual reference again... that's what I do/did for example with acdbmgd.dll and acmgd.dll, then do it with the other ones showing the little yellow error icon on the solution explorer tree
Title: Re: MS Visual Studio C# or SharpDevelop?
Post by: Jeff_M on April 18, 2007, 01:21:41 AM
Hi Luis, thanks. Yes, I can set the references OK. But see the AutocadUtilities folder is empty? It should have 3 classes in it. These 3 are all listed under the Errors & Warnings as not being able to be referenced due to being withing the project folder. These, and others like them, are what I'm having trouble with.

I just downloaded the VC#Express to work on this on my wife's PC (no Autocad or Civil3D). I have tried importing Existing objects, new Import for each Folder in the project. I'm still getting other errors. But now my head is swimming with other issues I've thought of. Must take a break and restart this in the morning with some fresh eyeballs.

Thanks for the tips guys.
Title: Re: MS Visual Studio C# or SharpDevelop?
Post by: Kerry on April 18, 2007, 01:40:17 AM
..................
I just downloaded the VC#Express to work on this on my wife's PC (no Autocad or Civil3D). I have tried importing Existing objects, new Import for each Folder in the project. I'm still getting other errors. .............

Without the installed DLL's from AC or C3D you will get a 'missing stuff' < technical term>  error.

I was going to have a try but stopped when I saw the C3D references.

You may get differing opinions on this, but I believe you'd be happier if you can get the VS2005 to load it.

Good fortune with it Jeff !
Title: Re: MS Visual Studio C# or SharpDevelop?
Post by: Jeff_M on April 18, 2007, 12:27:28 PM
OK, I got it working, thanks Mick's suggestion. Of course it took me a while to realize that the folders I copied couldn't be seen in the VS2005 IDE until I clicked the little button "show all files". There were still a few errors that crept in, namely I had to remove from each of the subfolders any AssemblyInfo.cs .

Kerry, on my wife's computer, other than the missing references (which I knew I'd get), the exact same errors/warnings were given about not being able to add certain/many of the classes in the sub-folders as I was getting on my work pc.

The good news is, It's working in VS2005..... the bad news is, The first thing I want to add is making me learn more than I have time for...... oh well. Thanks for the help, guys!
Title: Re: MS Visual Studio C# or SharpDevelop?
Post by: sinc on April 19, 2007, 09:18:36 PM
Are you using the full version of VS2005, or the Express?

I've been wondering how SharpDevelop compares with VS Express.  SharpDevelop works better than the VS that I remember, but I haven't used VS since I was doing lots of C++ programming in the late 90's, so that isn't a fair comparison.  SharpDevelop is pretty nice, but I'd switch to VS Express if there's a good reason.
Title: Re: MS Visual Studio C# or SharpDevelop?
Post by: TR on April 19, 2007, 09:24:03 PM
http://community.sharpdevelop.net/blogs/mattward/articles/VisualStudioExpressComparison.aspx

Note it says no help docs for SharpDevelop which isn't entirely true. Instead of local docs it uses MSDN which works quite well.
Title: Re: MS Visual Studio C# or SharpDevelop?
Post by: sinc on April 19, 2007, 09:29:05 PM
Hmmm...  I don't really see anything in that table that makes me want to jump over...

Anyone have experience with both and prefer one over the other for any strong reason?
Title: Re: MS Visual Studio C# or SharpDevelop?
Post by: Jeff_M on April 20, 2007, 12:43:58 PM
Hi Sinc,
Although my experience with SharpDevelop is minimal and with VS C# Express only somewhat more than that, I can say that I prefer the MS version by far. I think the IDE is cleaner, integrated help is nice, it seems like the Intellisense works better, I haven't had it crash even once, and since there is more code posted written in VS than SD it "just works" when opening/importing it in my own project.

Your SincPac3d code I finally was able to get into VS without errors. It compiled without errors, but attempting to load it in C3D2007 gives me a number of lines describing an error so it won't load. The one that starts it is "eDuplicateKey". I've searched high & low for the meaning of this but have has zero hits. I thought it may be the GUID, so I removed the reference to that but the same error persists.

It would be nice if the 2 IDE's put out code that the other could open without jumping through hoops. I haven't tried taking A VS project and opening with SD, but I'll bet it's a similar runaround.
Title: Re: MS Visual Studio C# or SharpDevelop?
Post by: sinc on April 20, 2007, 10:35:58 PM
OK, I downloaded the VS Express for C#.

I didn't just try to open the project in VS Express (although maybe I should have), because of the issues you've been having.  Instead, I created a new project in VS Express, then added the files using the "Add existing item..." option.  Everything seems to be working fine.  This post has a zip file of the VS project attached.  Since there are more people using VS Express than SharpDevelop, I'll probably post the VS version the next time I update our website.

The extra AssemblyInfo.cs files were from the early version, where I had a bunch of "subprojects".  This caused the project to compile into a bunch of seperate DLLs.  I decided I prefered a single DLL, and reorganized the project, but the extra AssemblyInfo.cs files were left behind.

The only thing I notice is that the Build and Revision numbers are not showing up in the compiled DLL.  It's showing up as version "0.6.0.0".  In SharpDevelop, that asterisk in "0.6.*" in the AssemblyInfo.cs was automatically converted to Build and Revision numbers, so I would get something like "0.6.2760.17502", but that's not happening in VS.
Title: Re: MS Visual Studio C# or SharpDevelop?
Post by: Jeff_M on April 20, 2007, 11:25:15 PM
Thanks, Sinc. I've done the same as you've described. Have you tried loading the dll in C3D?

I hadn't noticed the Build/Revision issue. If I ever get it working I'll look into that. :-)

Here's what I get when loading the DLL:
Quote from: Failed Command Line
Cannot load assembly. Error details: Autodesk.AutoCAD.Runtime.Exception: eDuplicateKey
   at Autodesk.AutoCAD.Runtime.Interop.Check(Int32 returnValue)
   at AcMgCommandClass.AddCommand(AcMgCommandClass* , ICommandLineCallable ca, MethodInfo mi)
   at Autodesk.AutoCAD.ApplicationServices.AutoCADApplicationHolder.Initialize(Assembly assembly)
   at Autodesk.AutoCAD.ApplicationServices.ExtensionLoader.ProcessAssembly(Assembly assembly)
I have been unable to determine what that eDuplicateKey refers to.
Title: Re: MS Visual Studio C# or SharpDevelop?
Post by: Kerry on April 20, 2007, 11:34:04 PM
Is there a disparity in versions .. or an Object Enabler issue ??

does sinc's solution include copies of some of the ACAD dll's ?
Title: Re: MS Visual Studio C# or SharpDevelop?
Post by: sinc on April 21, 2007, 12:41:02 AM
It works fine for me.  Everything seems to run fine, and I haven't seen any eDuplicateKey errors.  Seemed pretty painless.   :?

Are you trying to use 2008?  Ours hasn't arrived yet, so we're still on 2007.
Title: Re: MS Visual Studio C# or SharpDevelop?
Post by: sinc on April 21, 2007, 12:45:48 PM
Hi Sinc,
Although my experience with SharpDevelop is minimal and with VS C# Express only somewhat more than that, I can say that I prefer the MS version by far. I think the IDE is cleaner, integrated help is nice, it seems like the Intellisense works better, I haven't had it crash even once, and since there is more code posted written in VS than SD it "just works" when opening/importing it in my own project.

I haven't done much yet with VS C#, but I think I like it better so far.  For the most part, it's pretty similar.  I had SharpDevelop 2.0 crash on me, but so far I haven't had any issues with 2.1.  However, I think I like the code highlighting in VS better.  SharpDevelop highlights all method calls, regardless of where they are defined.  VS highlights items (type definitions in addition to methods) loaded from frameworks, making them stand out from items defined in the local code, which is more-useful.  And with SharpDevelop, I had to go into the Options and switch the active help between the ObjectARX and the .NET framework all the time, which was annoying.  In VS, both help collections are active at the same time.
Title: Re: MS Visual Studio C# or SharpDevelop?
Post by: Jeff_M on April 21, 2007, 02:53:51 PM
I'm glad you like it, Sinc. I'm also completely befuddled.....

I zipped up my version of SincPac, placed your VS version in my projects folder, compiled, and it works just fine, as you said. So I went back and did a side by side comparison, with the exception of 2 references I didn't need I couldn't find any major differences that would make yours work but not mine. /me ***<throws hands in air>***
I give up. I spent about 5 hours over the past few days chasing this error, no more. Did I metion I'm glad you switched to VS C#? :-D

So here's the whole reason I was trying this in the first place.....I just wanted to add the lisp routine I wrote last year to rotate points. Someone had posted that it was giving them the dreaded "unwind skipped on unkown exception" error. So I thought if it was written in C# I might eliminate that problem, and it would probably run quicker, too. By using your tools I figured it would cut down on the development time AND it could be added to your package, as you did ask for code contributions.

I do have both 2007 & 2008 installed and was starting to think my problem was related to that. But since yours works just fine, I've eliminated that possibility. So I've now just deleted my feeble attempts to convert your code and will just use what you posted. Thanks again!

Oh, one other reason I prefer VS C# is because I could never figure out how to run in Debug mode in SD. In VS C# it's pretty simple to setup debugging, and I learned from Kerry about using a script that opens a specific test drawing and loads the DLL.

Here's my contribution:
Code: [Select]
/*
 * User: Jeff Mishler
 * Date: 4/16/2007
 * Time: 7:24 AM
 *
 */

using System;
using Autodesk.AECC.Interop.Land;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Runtime;
using Civil3DUtilities;

namespace SincPac.RotatePoints
{
/// <summary>
/// Description of RotatePoints.  Code to set the rotation
    /// angle of C3D points. Written to be a part of Edward-James Surveying's
    /// excellent SincPac C3D routines.
    ///
    ///  To Do: determine what the current rotation value is, as defined
    ///  by the Point Marker Style, and calculate the desired angle factoring in
    ///  the style's angle. Right now it just sets the point's rotation angle to the
    ///  input value, but it may not display as desired due to the style's, both the
    ///  point and point group, angle being applied.
/// </summary>
    public class RotatePoints
    {
        public RotatePoints()
        {
        }
        public double rotpts_angle;

        [CommandMethod("ROTPTS")]
        public void RotatePointsCommand()
        {
            try
            {
                C3DUtil c3dUtil = new C3DUtil();
                Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
                AeccPoints aeccpoints = c3dUtil.AeccDb.Points;
                PromptAngleOptions prmpt = new PromptAngleOptions ("\nAngle to rotate points to:");
                prmpt.DefaultValue = rotpts_angle;
                prmpt.AllowArbitraryInput = false;
                prmpt.UseDefaultValue = true;
                PromptDoubleResult pres;
                pres = ed.GetAngle(prmpt);
                ed.WriteMessage("\nSelect points to rotate:");
                int[] ptNumList = (int[])c3dUtil.AeccDoc.SelectPoints();
                foreach (int PointNum in ptNumList)
                {
                    AeccPoint aeccpt = aeccpoints.Find(PointNum);
                    aeccpt.Rotation = pres.Value;
                }
                rotpts_angle = pres.Value;
                if (ptNumList.GetUpperBound(0) == 0)
                {
                    ed.WriteMessage("\nRotated 1 point. ");
                }
                else
                {
                    ed.WriteMessage("\nRotated {0} points. ", ptNumList.GetUpperBound(0) + 1);
                }
            }
            catch
            {
            }
        }
    }

}
Title: Re: MS Visual Studio C# or SharpDevelop?
Post by: sinc on April 21, 2007, 06:16:41 PM
So here's the whole reason I was trying this in the first place.....I just wanted to add the lisp routine I wrote last year to rotate points. Someone had posted that it was giving them the dreaded "unwind skipped on unkown exception" error. So I thought if it was written in C# I might eliminate that problem, and it would probably run quicker, too. By using your tools I figured it would cut down on the development time AND it could be added to your package, as you did ask for code contributions.

Great!  I'll add it to the pack.

Quote
Oh, one other reason I prefer VS C# is because I could never figure out how to run in Debug mode in SD. In VS C# it's pretty simple to setup debugging, and I learned from Kerry about using a script that opens a specific test drawing and loads the DLL.

I was just struggling with that.  Unlike you, I had absolutely no trouble getting debuggin working in SD - it just flat-out worked.  All I had to do was point the project to the acad.exe file (since I was creating class libraries, not complete applications), and configure the ACAD.LSP file to load the debug version of the DLL at startup.  Everything else was automatic.  I could just hit "run" from within SD, and it would startup C3D for me.

In VS, I still haven't gotten debugging working.  What's the script?  What language?  How do you create and run it?

I had found something in the VS help about adding a "test project", which could then be set to compile in debug mode, but haven't yet parsed out exactly what that means.
Title: Re: MS Visual Studio C# or SharpDevelop?
Post by: Jeff_M on April 21, 2007, 06:30:44 PM
Well, I admit I didn't spend too much time trying to get the Debug to work in SD...no wonder it didn't.  :roll:

To get to work in VS C#, with the subject project closed.... in your project folder that holds the *.csproj file edit the *.csproj.user file. This is what mine looks like for my new SincPacC3D-2008 project:
Code: [Select]
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <StartAction>Program</StartAction>
    <StartProgram>C:\Program Files\AutoCAD Civil 3D 2008\acad.exe</StartProgram>
    <StartWorkingDirectory>q:\</StartWorkingDirectory>
    <StartArguments>/b "C:\Base Maps\Jeffs Test Files\Test C#\sincpac-2008.scr"</StartArguments>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <StartAction>Program</StartAction>
    <StartProgram>C:\Program Files\AutoCAD Civil 3D 2008\acad.exe</StartProgram>
    <StartWorkingDirectory>q:\</StartWorkingDirectory>
    <StartArguments>/b "C:\Base Maps\Jeffs Test Files\Test C#\sincpac-2008.scr"</StartArguments>
  </PropertyGroup>
   <PropertyGroup>
    <ProjectView>ProjectFiles</ProjectView>
  </PropertyGroup>
</Project>
Then my sincpac-2008.scr is just an Acad Script that opens a dwg and netloads the dll
Code: [Select]
open
q:\points-3
netload
"C:\Documents and Settings\Master\My Documents\Visual Studio 2005\Projects\SincPacC3D-2008\SincPacC3D\bin\Debug\SincPacC3D-2008.dll"


HTH

I should add that I got the above to work thanks to posts by Kerry Brown and Paul Richardson in  THIS  (http://www.theswamp.org/index.php?topic=12649.msg155072#msg155072) thread.
Title: Re: MS Visual Studio C# or SharpDevelop?
Post by: sinc on April 21, 2007, 08:03:39 PM
Thanks.  I got it working now.

That's one up for SD... It was significantly simpler there, and took me all of a few minutes to get working.  It's basically the same thing, except it's possible to configure the builds from the project settings inside of SD, rather than by hand-creating a text file.
Title: Re: MS Visual Studio C# or SharpDevelop?
Post by: Jeff_M on April 21, 2007, 08:09:18 PM
From the screen shots that Kerry has posted recently, I think the full version, i.e. non-Express, of VS works the same way as SD. This is just one of the crippled areas they placed in Express.
Title: Re: MS Visual Studio C# or SharpDevelop?
Post by: sinc on April 21, 2007, 08:58:01 PM

I hadn't noticed the Build/Revision issue. If I ever get it working I'll look into that. :-)


Seems to be caused by having an asterisk for the build/revision in the AssemblyFileVersion line in the AssemblyInfo.cs file.

Removing the declaration for AssemblyFileVersion fixes the problem.  As far as I can tell, this is OK, and causes the AssemblyFileVersion to be the same as the AssemblyVersion.
Title: Re: MS Visual Studio C# or SharpDevelop?
Post by: sinc on May 20, 2007, 09:35:24 AM
After using MS VS Express for a while, I like the Intellisense a little better - SharpDevelop does not automatically highlight elements defined in other classes the way VS Express does, and all-in-all, I find the VS Express intellisense a bit more useful.  And I like the Help in VS Express significantly better, because I can see the .NET SDK help and the ObjectARX help simultaneously.  In SharpDevelop, I had to constantly go into the Options and switch the active help file between the two, which got old really fast.

As I mentioned a few posts back, the debugging is fully built-in to SharpDevelop, making it much easier in there.  Sure, it's possible to get debugging working in VS Express by hand-creating the .csproj.user file, but that isn't explained in the Help, and it's not intuitive at all.  Very user-unfriendly, but I got it working.

Unfortunately, there are several other items that were also very simple in SharpDevelop, but not in VS Express.  I've still been unable to find any way to do the following tasks:

Title: Re: MS Visual Studio C# or SharpDevelop?
Post by: Chuck Gabriel on May 20, 2007, 11:48:27 AM
I know there are equivalents to a couple of the things you mentioned.

To reformat the current document, type Ctrl+E,D.  More generally, look on the Edit pulldown under Advanced.

Under Tools->Options->Projects and Solutions->General, there is an options to "show advanced build configurations."  It will add a couple of listviews to the standard toolbar where you can select build options.

I don't know about the rest.
Title: Re: MS Visual Studio C# or SharpDevelop?
Post by: It's Alive! on May 20, 2007, 12:13:01 PM
1, Chuck got this one

2, It is not necessary to “purge” the using statements. The compiler will do this for you.
I agree it does tidy up the source, but you don’t have to worry about code bloat.
http://blogs.msdn.com/csharpfaq/archive/2004/10/20/245411.aspx

3, CTRL+E,D will format the document, CTRL+E,F will format the selection

4, under the project properties->Debug, you should have a start action radio button that you can deselect.
Title: Re: MS Visual Studio C# or SharpDevelop?
Post by: sinc on May 20, 2007, 01:24:24 PM
Under Tools->Options->Projects and Solutions->General, there is an options to "show advanced build configurations."  It will add a couple of listviews to the standard toolbar where you can select build options.

AH!  After you told me where to look and I still couldn't find it, I finally noticed that little "Show all settings" checkbox in the bottom-left corner of the Options dialog.  When I checked that, a WHOLE BUNCH of things I had been looking for suddenly appeared!  I understand the desire to clean up the UI, but I don't think I really like these obscure controls that hide useful functions.  Oh well, got things turned on now.

I still don't see a "Build Clean" option...  Is that hidden in there somewhere?

It seems like I tried the CTRL+E,D thing and it didn't work for some reason, but it's working now.  Maybe I had something wrong in my code when I tried it before.

As for purging the unneeded Using statements, I *do* like to do that, because I think it makes it makes things a little clearer, particularly for newbies who are not yet familiar with the API and are trying to parse the code.  It's not a big deal, though.
Title: Re: MS Visual Studio C# or SharpDevelop?
Post by: It's Alive! on May 20, 2007, 01:50:42 PM
If you right click on the project in the solution explorer, you see a clean and rebuild option? 
Title: Re: MS Visual Studio C# or SharpDevelop?
Post by: Bryco on May 20, 2007, 03:43:14 PM
I have that on the professional  but not on the express.
Title: Re: MS Visual Studio C# or SharpDevelop?
Post by: Kerry on May 20, 2007, 05:02:14 PM
It's a while since I've used Express, but there IS a Rebuild Option either Rt Click on the Solution or from the Build Menu.
... Clean { remove ALL unneeded files} is not available in express.

Title: Re: MS Visual Studio C# or SharpDevelop?
Post by: Kerry on May 20, 2007, 05:04:52 PM
and formatting ..
Title: Re: MS Visual Studio C# or SharpDevelop?
Post by: sinc on June 02, 2007, 10:34:23 AM
How do you create or edit resource files?

The help seems to say go to the Tools menu, and startup the Add-In Manager, then use that to load the Resource Manager.  However, I can't even find the Add-In Manager, let alone the Resource Manager.