.NET

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

C# ActiveX

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

        }

    }

}

Valued Contributor
pipu123
Posts: 60
Registered: ‎09-27-2010
Message 2 of 2 (326 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

Announcements
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community