.NET

Reply
*Expert Elite*
dgorsman
Posts: 5,277
Registered: ‎10-12-2006
Message 11 of 26 (402 Views)

Re: C# code without start external program

08-29-2012 03:58 PM in reply to: Alfred.NESWADBA

Express editions don't have edit and continue - even in 32-bit.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
Adopt. Adapt. Overcome. Or be overcome.
A good question will be halfway to a good answer.


Valued Contributor
pipu123
Posts: 61
Registered: ‎09-27-2010
Message 12 of 26 (402 Views)

Re: C# code without start external program

08-29-2012 04:28 PM in reply to: Alfred.NESWADBA

Hi

I was looking information couple of hours.

So, I have 32bit os, visual studio with possibility to add external program. 

Debug / start external program / I added external program "cad.exe"

 

I wrote a program in c# visual studio for autocad.
I added reference to  AcDbMgd.dll   AcMgd.dll acax17enu.tlb.

So point  A1)  as you mentioned it ... define an external application = acad.exe to be started 

 

I wrote a program from message 7.  I press F5 new acad.exe file opens, netload dll

Write CommandMethod  CreateMText . I see on a model space text: This is a text string for the MText object.

I stop debugging cad.exe is closing. 

Question:     I don’t know how to debug my code. You wrote about option "write while debugging".

I can’t find it. Please write more clearly on an example/

Code namespace _28._08._2012

I put toggle breakpoint on line with:  Database acCurDb = acDoc.Database; 

I press F5 cad.exe opens , Netload , next I write  CommandMethod  CreateMText

Vs doesn’t stopped on my breakpoint.

How to do to check line by line of my code using debugger. I would like to write a program with about 2000 lines and I would like to have possibility to check inside the code like in visual lisp or vba.

For example I would like to find out the properties my acMText.

In vba I put breakpint , I choose it and I had all properties in a watch window. I don’t know how

To this in visual studio in this code for autocad.

 

I read more about

B) your code works based on COM and works as ActiveX-Server ==> then you need again at least a starter-code that get's the connection to your external ActiveX-server. In this case I'm not sure, but I think that you are not allowed to rebuild your project as long as the DLL is currently connected via ActiveX to the acad.exe process.

 

 

I created windows forms , I add reference to activeX 

  The AutoCAD type library, acax17enu.tlb, located at <drive>:\Program Files\Common

Files\Autodesk Shared.

 

The AutoCAD/ObjectDBX Common 17.0 type library, axdb18enu.tlb, located at

<drive>:\Program Files\Common Files\Autodesk Shared.

 

It works the same way as vba built-in autocad application. 

I wrote that program with autodesk help.

How to define  Pkt1, Pkt2 to create a line ?

Is there any documentation for activeX C# ?

 

 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Runtime.InteropServices;

 

using Autodesk.AutoCAD.Interop;

using Autodesk.AutoCAD.Interop.Common;

 

 

namespace Wst_zelbet

{

    public partial class wst : Form

    {

        public wst()

        {

            InitializeComponent();

        }

 

        private void Form1_Load(object sender, EventArgs e)

        {

            AcadApplication objAcad;

            AcadDocuments colDocs;

            AcadModelSpace Mspace;          

            AcadLine acLine;

            AcadDocument ThisDrawing;

 

            objAcad = null;

            const string strProgId = "AutoCAD.Application.17.2";

 

          // Get a running instance of AutoCAD

        try

        {

            objAcad = (AcadApplication)Marshal.GetActiveObject(strProgId);

        }

       catch // An error occurs if no instance is running

        {

            try

            {

            // Create a new instance of AutoCAD

            objAcad = (AcadApplication)Activator.CreateInstance(Type.GetTypeFromProgID(strProgId), true);

            }

 

        catch

            {

          // If an instance of AutoCAD is not created then message and exit         

            System.Windows.Forms.MessageBox.Show("Instance of 'AutoCAD.Application'" + " could not be created.");         

          return;

             }

        }

 

            // Display the application and return the name and version

            objAcad.Visible = true;

            // System.Windows.Forms.MessageBox.Show("Now running " + acAppComObj.Name + " version " + objAcad.Version);

 

            // Get the active document

            ThisDrawing = objAcad.ActiveDocument;

 

            ThisDrawing.SendCommand("MyCommand ");

            Mspace = ThisDrawing.ModelSpace;

 

            object Pkt1;

            object Pkt2;                

 

        acLine = Mspace.AddLine(pk1, pk2);     

 

            ThisDrawing.Application.ZoomAll();

            ThisDrawing.Regen(AcRegenType.acAllViewports);

        }

    }

}

 

Valued Contributor
pipu123
Posts: 61
Registered: ‎09-27-2010
Message 13 of 26 (391 Views)

Re: C# code without start external program

08-29-2012 10:36 PM in reply to: pipu123

I don't use express edition of visual studio.

Valued Contributor
pipu123
Posts: 61
Registered: ‎09-27-2010
Message 14 of 26 (385 Views)

Re: C# code without start external program

08-30-2012 12:05 AM in reply to: pipu123

Instead of axdb18enu.tlb I added reference to: axdb17enu.tlb . I mispelled  

*Expert Elite*
Alfred.NESWADBA
Posts: 8,983
Registered: ‎06-29-2007
Message 15 of 26 (382 Views)

Re: C# code without start external program

08-30-2012 12:39 AM in reply to: pipu123

Hi,

 

>> Instead of axdb18enu.tlb I added reference to: axdb17enu.tlb . I mispelled 

You work with what version of AutoCAD?

Using 17.x means you work based on release 2007 or 2008 or 2009

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
*Expert Elite*
Alfred.NESWADBA
Posts: 8,983
Registered: ‎06-29-2007
Message 16 of 26 (383 Views)

Re: C# code without start external program

08-30-2012 12:51 AM in reply to: dgorsman

Hi,

 

@dgorsman

>> Express editions don't have edit and continue - even in 32-bit.

Sorry to disagree, see >>>this<<< showing C# in VS 2010 Express has thee option for edit-while-debug. :smileywink:

 

@pipu123

>> I was looking information couple of hours.
For looking how to use it, >>>this is especially for you<<<

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Valued Contributor
pipu123
Posts: 61
Registered: ‎09-27-2010
Message 17 of 26 (373 Views)

Re: C# code without start external program

08-30-2012 01:54 AM in reply to: Alfred.NESWADBA

Hi

use autocad 2009 english   , visual studio 2010, windows vista eng 32 bit

I read again your answers in my situation your answer:

 

>> So in visual studio I create code, I compile it do dll, this dll I open in autocad.

You set the options within your visual-studio project to start the acad.exe when you press "play" for start debugging your project. So Visual Studio starts AutoCAD for you (with some hooks) and when you NETLOAD your DLL every breakpoint or every exception (when enabled to stop on exception in your project) will stop at the code in the Visual Studio environment.

 

Hi

I write again to not forget something

I create a class in visual studio 2010. Solution Explorer/ right mouse on namespace / properties

I added reference to  AcDbMgd.dll   AcMgd.dll

Copy local: false

Debug / start external program  "C:\Program Files\AutoCAD 2009\acad.exe"

 

Tools / Options  / Debugging / Break when exceptions cross AppDomain or managed/ native boundaries (Managed only)

 

Tools / Options  / Debugging /Edit and Continue / Enable Edit and continue

 

 

 

 

This is my source code:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.IO;

 

using Autodesk.AutoCAD.ApplicationServices;

using Autodesk.AutoCAD.Colors;

using Autodesk.AutoCAD.ComponentModel;

using Autodesk.AutoCAD.DatabaseServices;

using Autodesk.AutoCAD.EditorInput;

using Autodesk.AutoCAD.Geometry;

using Autodesk.AutoCAD.GraphicsInterface;

using Autodesk.AutoCAD.GraphicsSystem;

using Autodesk.AutoCAD.LayerManager;

using Autodesk.AutoCAD.PlottingServices;

using Autodesk.AutoCAD.Publishing;

using Autodesk.AutoCAD.Runtime;

using Autodesk.AutoCAD.Windows;

using Autodesk.AutoCAD.Interop;

 

 

namespace _28._08._2012

{

    public class Class1

    {

 

        [CommandMethod("CreateMText")]

        public static void CreateMText()

        {

            // Get the current document and database

            Document acDoc = Application.DocumentManager.MdiActiveDocument;

            Database acCurDb = acDoc.Database;

 

            // Start a transaction

            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())

            {

                // Open the Block table for read

                BlockTable acBlkTbl;

                acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,

                                             OpenMode.ForRead) as BlockTable;

 

                // Open the Block table record Model space for write

                BlockTableRecord acBlkTblRec;

                acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],

                                                OpenMode.ForWrite) as BlockTableRecord;

 

                // Create a multiline text object

                MText acMText = new MText();

                acMText.SetDatabaseDefaults();

                acMText.Location = new Point3d(2, 2, 0);

                acMText.Width = 4;

                acMText.Contents = "This is a text string for the MText object  tyg uthu  .";

 

                acBlkTblRec.AppendEntity(acMText);

                acTrans.AddNewlyCreatedDBObject(acMText, true);

 

                // Save the changes and dispose of the transaction

                acTrans.Commit();

                acDoc.SendStringToExecute("._zoom _all ", true, false, false);

            }

        }

       

    }

}

 

I put a breakpoint  on a line   [CommandMethod("CreateMText")]

I put a breakpoint  on a line   acMText.Location = new Point3d(2, 2, 0);

 

I press F5 I write in autocad command line: Netload

C# doesn’t stop on breakpoints.

I would like to write programs using .NET and debug the code.

Question:

What to do with codes which creates dll to have available debugging, to check the code.

 

*Expert Elite*
Alfred.NESWADBA
Posts: 8,983
Registered: ‎06-29-2007
Message 18 of 26 (371 Views)

Re: C# code without start external program

08-30-2012 02:12 AM in reply to: pipu123

Hi,

 

>> use autocad 2009 english   , visual studio 2010

>> [...]

>> C# doesn’t stop on breakpoints.

Ok, one reason could be you are runnung the wrong framework. When you start a new project with VS2010 it is set to use framework 4.0 by default. As AutoCAD 2009 is not based on that version of framework you should set your C#-project back to 2.0 (or 3.0 or 3.5 .....) sorry, I can't remember currently what 2009 was based on, I think 2.0 should work as 3.0 and 3.5 are based on 2.0.

 

The other steps you listed seem quite ok!

 

Good luck, - alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Valued Contributor
pipu123
Posts: 61
Registered: ‎09-27-2010
Message 19 of 26 (370 Views)

Re: C# code without start external program

08-30-2012 02:49 AM in reply to: Alfred.NESWADBA

All right I opened video DevTV from website I opened vs 2008 net framework 3.0 cad 2009

put breakpoint and it works.

When I opened vs 2010 with your idea I set framework 3.0 - breakpoint doesn't work

  framework 2.0 doesn't wan't to add acmgd.dll

I will write programs in vs 2008. 

I wonder why vs 2010 doesn't work, I am beginner and I don't know why.  It is a questiion for experts like You.

I think maybe change of

           CultureInfo _currentCulture;

            _currentCulture = Thread.CurrentThread.CurrentCulture;
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

Friend used this for connecting to excel using framework 3,5 or 4. 

 

I will use older versions of software to omit that situations in a future.

Thank You for patience and help :smileyhappy:

 

By the way do You know the answer for this  

           object Pkt1;

            object Pkt2;         

Pkt1 = ...

Pkt2 = ...

 acLine = Mspace.AddLine(pk1, pk2);   

 

I created windows forms , I add reference to activeX 

  The AutoCAD type library, acax17enu.tlb, located at <drive>:\Program Files\Common

Files\Autodesk Shared.

 

The AutoCAD/ObjectDBX Common 17.0 type library, axdb18enu.tlb, located at

<drive>:\Program Files\Common Files\Autodesk Shared.

 

It works the same way as vba built-in autocad application. 

I wrote that program with autodesk help.

How to define  Pkt1, Pkt2 to create a line ?

Is there any documentation for activeX C# ?

 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Runtime.InteropServices;

 

using Autodesk.AutoCAD.Interop;

using Autodesk.AutoCAD.Interop.Common;

 

 

namespace Wst_zelbet

{

    public partial class wst : Form

    {

        public wst()

        {

            InitializeComponent();

        }

 

        private void Form1_Load(object sender, EventArgs e)

        {

            AcadApplication objAcad;

            AcadDocuments colDocs;

            AcadModelSpace Mspace;          

            AcadLine acLine;

            AcadDocument ThisDrawing;

 

            objAcad = null;

            const string strProgId = "AutoCAD.Application.17.2";

 

          // Get a running instance of AutoCAD

        try

        {

            objAcad = (AcadApplication)Marshal.GetActiveObject(strProgId);

        }

       catch // An error occurs if no instance is running

        {

            try

            {

            // Create a new instance of AutoCAD

            objAcad = (AcadApplication)Activator.CreateInstance(Type.GetTypeFromProgID(strProgId), true);

            }

 

        catch

            {

          // If an instance of AutoCAD is not created then message and exit         

            System.Windows.Forms.MessageBox.Show("Instance of 'AutoCAD.Application'" + " could not be created.");         

          return;

             }

        }

 

            // Display the application and return the name and version

            objAcad.Visible = true;

            // System.Windows.Forms.MessageBox.Show("Now running " + acAppComObj.Name + " version " + objAcad.Version);

 

            // Get the active document

            ThisDrawing = objAcad.ActiveDocument;

 

            ThisDrawing.SendCommand("MyCommand ");

            Mspace = ThisDrawing.ModelSpace;

 

            object Pkt1;

            object Pkt2;                

 

        acLine = Mspace.AddLine(pk1, pk2);     

 

            ThisDrawing.Application.ZoomAll();

            ThisDrawing.Regen(AcRegenType.acAllViewports);

        }

    }

}

 

 

 

 

 

*Expert Elite*
Alfred.NESWADBA
Posts: 8,983
Registered: ‎06-29-2007
Message 20 of 26 (367 Views)

Re: C# code without start external program

08-30-2012 03:04 AM in reply to: pipu123

Hi,

 

>> I wonder why vs 2010 doesn't work

At the moment my ideas run out (except of doing some search in www as there are a lot of options when breakpoints don't get active while debugging). It's sometimes quite hard to know the correct modification if not sitting in front of the workstation that has the problem.

 

>> I opened vs 2008 net framework 3.0 cad 2009 put breakpoint and it works.

That's good to know for you, so your steps are principle ok and there is no global problem. :smileywink:

 

>> By the way do You know the answer for this [...]

I'm no C#-man, but try that:

double[] tPkt1 = {10,10,0};
double[] tPkt2 = {20,15,0};
acLine = tMSpace.AddLine((object)tPkt1, (object)tPkt2);

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.