.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

C# code without start external program

25 REPLIES 25
SOLVED
Reply
Message 1 of 26
pipu123
7689 Views, 25 Replies

C# code without start external program

Hi everyone
I am looking for a code.
Without loading and unloading,without start external program (debug)  
C# code searches active file ,for example c:\home.dwg.
I wrote in this: netload and so on.
It saves many hours.
I read articles about it but I couldn't find a solution.
I read all help about programming in c# for vs.
Time which I have to spend waiting for starting cad every time
takes many minutes. I wrote in vba for autocad, there is a big difference
in waiting for a result.
Thank You in advance
 

25 REPLIES 25
Message 2 of 26
Alfred.NESWADBA
in reply to: pipu123

Hi,

 

can you ask again with a little bit more clearness?

I can't interpret your question to something that I can understand, I don't see what you are searching for (as you found something that saves you hours)?

 

If (just as one guess) you just want to have your dotNET-app automatically loaded, so you don't want to load it by hand) you might have a look to >>>this devcast<<<.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 3 of 26
pipu123
in reply to: Alfred.NESWADBA

I will try to explain.

I create a new code (windows form or class)  in visual studio c#.

Solution Explorer/ right mouse on namespace / properties

Debug / start external program / here we choose file to autocad.

So when I press F5 new autocad file opens, it takes about 30seconds.

I want to write a program withou setting external program in a debug – is it possible.

 

Instead of starting external program I would like myself open

autocad file e:\strop.dwg

When I press F5 C# code catches this active cad file  (strop.dwg) ,

I wrote myself netload or put command in c#

SendCommand("_Netload");

I choose my dll file, I write name of command method.

When the c# finishes, I Stop debugging and the house.dwg is still

open. 

 

 

I read about it on this forum , I wrote this program, please correct this

I use visual studio 2010, autocad 2009.

 

I read this article, it doesn't work. I missed something

 

http://forums.autodesk.com/t5/NET/using-COM-API-in-net-dll/m-p/1334401/highlight/true#M153

 

 

This is my code  visual 2010  c#

Please correct and enclose  visual studio files as a solution.

 

 

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.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;

using Autodesk.AutoCAD.Interop.Common;

 

using Aplikacja = Autodesk.AutoCAD.ApplicationServices.Application;

 

namespace CadConnectwf

{

    public partial class HitAcad : Form

    {       

        public AcadApplication cadApp;

        public AcadDocument cadDoc;

       

       

        public HitAcad()

        {

            InitializeComponent();

        }

 

        private void Form1_Load(object sender, EventArgs e)

        {

            Connect2Acad();

        }

 

 

        public bool Connect2Acad()

        {

          //  Autodesk.AutoCAD.Interop.AcadApplication _AcadApp = (AcadApplication)Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;

          

 

        try

        {

           

            cadApp =(Autodesk.AutoCAD.Interop.AcadApplication)

            Marshal.GetActiveObject("AutoCAD.Application.17");

        }

        catch

        {

            try

                {

                cadApp =new Autodesk.AutoCAD.Interop.AcadApplication();

                cadApp.Visible = true;

                }

                catch (System.Exception AcadEx)

                {

                string sMsg = AcadEx.Message + " from: " + AcadEx.Source;

                MessageBox.Show(sMsg, "AutoCAD_BasicCalls|Connect2Acad",

                MessageBoxButtons.OK, MessageBoxIcon.Error);

                return false;

                }

        }           

            return true;

        }

 

 

    }

}

 

 

 

 

In help from autocad I found this but  I can’t run it I suppose it is windows form.

Please enclose a vs studio file as a solution.

 

        [CommandMethod("ConnectToAcad")]

        public static void  ConnectToAcad()

        {

        AcadApplication acAppComObj = null;

        // "AutoCAD.Application.17" uses 2007 or 2008,

 

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

       

          // Get a running instance of AutoCAD

        try

        {

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

        }

       catch // An error occurs if no instance is running

        {

            try

            {

            // Create a new instance of AutoCAD

            acAppComObj = (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

            acAppComObj.Visible = true;

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

 

            // Get the active document

            AcadDocument acDocComObj;

            acDocComObj = acAppComObj.ActiveDocument;

 

            // Optionally, load your assembly and start your command or if your assembly

            // is demandloaded, simply start the command of your in-process assembly.

            acDocComObj.SendCommand("(command " + (char)34 + "NETLOAD" + (char)34 + " " + (char)34 + "g:/nauka c# cad/CsMgd1/bin/debug/CsMgd1.dll" + (char)34 + ") ");

            acDocComObj.SendCommand("MyCommand ");

            } 

Message 4 of 26
Alfred.NESWADBA
in reply to: pipu123

Hi,

 

ok, three options:

 

A) as long as you want to define own application-commands (as you use it in CommandMethod(....) ) you have to use the project-type = DLL and you have to use _NETLOAD (or the plugin-methods starting with AutoCAD 2012 or registry-settings to get the DLL automatically loaded without using command _NETLOAD shown >>>here<<<). To start debugging such a project you have two options:

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

A2) attach your project (to be found under menu "debug" of Visual Studio) to a running instance of acad.exe ==> that sounds close to what you are looking for. BUT: as AutoCAD can't unload managed code you have the problem that when you first start this attach to process and NETLOAD your DLL you don't get the code unloaded. So stopping debugging, rewrite the code and again attaching to acad.exe will not load the new modificated version of your DLL. So also with this method you have to restart the acad.exe

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.

C) your code is an external EXE the connects to AutoCAD and AutoCAD plays the ActiveX-server. Exept of that you cannot define then commands as under A) you will have the option to start and stop your EXE to connect to AutoCAD and to disconnect from AutoCAD without stopping the AutoCAD-process itself. But as the EXE runs outside of the process-memory of AutoCAD that's the worst performance way to go.

 

Hope that answers your questions, - alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 5 of 26
pipu123
in reply to: Alfred.NESWADBA

Thank You for answer
I read almost all help/ tutorial c# for autocad.
I am beginner with visual studio so I don't know
is it posibble to do this.

I will write sample code for point "A" after friday.

I will write again my aim maybe, I will try more clearly
 step by step.

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

Debug / start external program / here we choose file to autocad.
If it is necessery I add external program "cad.exe"

In visual studio c# I press F5 code
1) catches active autocad file if it is possible
( I wrote on hdd a file, d:\strop.dwg, I opened it before
pressing F5 )
or
2) opens new autocad file
In command line I write netload, choose dll file, write name of command
method, it opens the file d:\strop.dwg,
On the model space creats some drawing.
I stopping debugging
3) is it possible, cad file strop.dwg will be still open
 after finishing of debugging?

Afterthat I add some lines in my c# code,I press F5
(now I would like to save time on opening second time new autocad file
 is it possible ? or new autocad file has to be open)
new dll will rewrite old one. In command line of autocad I write
netload,I load dll, write command method.  

Nowadays every time when I want to check my code new autocad file
is opening, I stop debugging autocad is closing.
If I want debugging often, opening and closing autocad takes about 70 seconds
for every time.
I would like to omit this opening and closing.
I wonder is it possible, to save time.

Message 6 of 26
Alfred.NESWADBA
in reply to: pipu123

Hi,

 

all answered with a short statement: use an 32bit os and so also a 32bit AutoCAD and you have the option "write while debugging" available in Visual Studio. As long as you work on 64bit you can just debug but not modify the code while debugging. Thats a limitation of Visual Studio.

If you have already setup your workstation then you may use something like VmWare or any other virtual-pc alternativ so you can run a 32bit environment.

 

All the other options will have to close and restart AutoCAD to get a modified DLL (as long as it has the same name) reloaded.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 7 of 26
pipu123
in reply to: Alfred.NESWADBA

Thank You very much for showing me a solution. I will read more about "write while debugging" within next weeks.

 

Message 8 of 26
pipu123
in reply to: pipu123

A  Please explain me how this works "write while debugging". Maybe send an example. I searched on internet and I couldn’t find this therm.

 

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

During writing code in c# visual studio for autocad  , doesn’t have connection between them. How to debug code ?  I wrote an example.

How people cope with checking a code( debugging) when they write huge codes in c# / vb in visual studio.

 

I enclose vs files.

Thank You in Advance

 

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.";

 

                acBlkTblRec.AppendEntity(acMText);

                acTrans.AddNewlyCreatedDBObject(acMText, true);

 

                // Save the changes and dispose of the transaction

                acTrans.Commit();

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

            }

        }

       

    }

}

Message 9 of 26
dgorsman
in reply to: pipu123

Not being able to edit code on the fly while AutoCAD is open is mildly annoying, but what is, is.  I take a logical, procedural approach to development so its not really a problem.  Flailing away at code as its running instead of test/diagnose/implement/test isn't a very rigourous development environment, making it difficult to produce well organized code (at least, in my experience - *extremely* experienced coders can get away with this).

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


Message 10 of 26
Alfred.NESWADBA
in reply to: dgorsman

Hi,

 

>> Not being able to edit code on the fly while AutoCAD is open is mildly annoying, but what is, is

As mentioned, that is only valid for 64bit. If you run a 32bit os you can edit-while-debug - and of course - it's a big advantage and makes development much faster.

And if you don't have a 32bit os then install a virtual-pc environment on your system that runs a 32bit os and AutoCAD.

 

>> Please explain me how this works "write while debugging". Maybe send an example

I can't send a sample for that because you can do that with every code as long as the debugged session runs in 32bit mode.

If the problem is that you can't set the acad.exe to be started for debugging then you use the Express-release of Visual Studio. Therefor you'll find two options to get that running:

a) check the Wizards within that ObjectARX-kit. I don't use them but I'm quite sure that using them you will have the correct settings within your project-user-file. Great source for that and around AutoCAD and dotNET is >>>here<<<.

 

>> 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.

For 32bit session you can now modify the code, for a 64bit session a breakpoint or exception also stops the code (before you can continue), so you have the chance for getting information about variables, stack, .... but you can't edit.

 

HTH, - alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 11 of 26
dgorsman
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.
"I don't know" is the beginning of knowledge, not the end.


Message 12 of 26
pipu123
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);

        }

    }

}

 

Message 13 of 26
pipu123
in reply to: pipu123

I don't use express edition of visual studio.

Message 14 of 26
pipu123
in reply to: pipu123

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

Message 15 of 26
Alfred.NESWADBA
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 ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 16 of 26
Alfred.NESWADBA
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. 😉

 

@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 ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 17 of 26
pipu123
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.

 

Message 18 of 26
Alfred.NESWADBA
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 ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 19 of 26
pipu123
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 🙂

 

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);

        }

    }

}

 

 

 

 

 

Message 20 of 26
Alfred.NESWADBA
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. 😉

 

>> 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 ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost