Valued Contributor
Posts: 61
Registered: ‎09-27-2010
Message 1 of 2 (368 Views)
Accepted Solution

C# ActiveX

368 Views, 1 Replies
08-30-2012 03:06 AM

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.

1)      How to define  Pkt1, Pkt2 to create a line ?

2)      Is there any documentation for activeX C# ?

3)      Which forum is appropriate for ActiveX C# and other external programming languages


Thank You In advance


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





        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



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


       catch // An error occurs if no instance is running




            // Create a new instance of AutoCAD

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





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





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

   // please define these points 

Pkt1 = ....

Pkt2 = ....

        acLine = Mspace.AddLine(pk1, pk2);     







Valued Contributor
Posts: 61
Registered: ‎09-27-2010
Message 2 of 2 (365 Views)

Re: C# ActiveX

08-30-2012 03:22 AM in reply to: pipu123
double[] tPkt1 = {10,10,0};
double[] tPkt2 = {20,15,0};
acLine = tMSpace.AddLine((object)tPkt1, (object)tPkt2);

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

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 to get help installing your software.

Ask the Community