.NET

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

C# ActiveX

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

        {

            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;                

   // please define these points 

Pkt1 = ....

Pkt2 = ....

        acLine = Mspace.AddLine(pk1, pk2);     

 

            ThisDrawing.Application.ZoomAll();

            ThisDrawing.Regen(AcRegenType.acAllViewports);

        }

    }

}

double[] tPkt1 = {10,10,0};
double[] tPkt2 = {20,15,0};
acLine = tMSpace.AddLine((object)tPkt1, (object)tPkt2);
Valued Contributor
pipu123
Posts: 61
Registered: ‎09-27-2010
Message 2 of 2 (414 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);
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!