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

Draw lines from WinForm.

3 REPLIES 3
Reply
Message 1 of 4
GrzesiekGP
981 Views, 3 Replies

Draw lines from WinForm.

Hello!


I wrote some stand+alone application (WinForm=, where user can specify dimensions.

 

Now after button click I want to switch form to current AutoCAD file and prompt user to specify point.

From this point I want to start drawing few lines.

 

And I don't know how to switch to AutoCad and get current drawing space.

 

Can anyone help me? Any articles about this would be nice for me 🙂

3 REPLIES 3
Message 2 of 4
Hallex
in reply to: GrzesiekGP

Take look at this thread

http://forums.autodesk.com/t5/NET/How-to-pass-parameter-in-interface-to-the-programe-of-dll-file/td-...

 

~'J'~

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 3 of 4
GrzesiekGP
in reply to: GrzesiekGP

Thanks, I've made something that works:

 

object obj = System.Runtime.InteropServices.Marshal.GetActiveObject("AutoCAD.Application");
AcadApplication acad = (AcadApplication)obj as AcadApplication;
acad.WindowState = AcWindowState.acMax;
AcadDocument adoc = (AcadDocument)acad.ActiveDocument as AcadDocument;
AcadUtility acutil = (AcadUtility)adoc.Utility as AcadUtility;
string prompt1 = null;
double[] pnt;
prompt1 = "Enter block insert point: ";
pnt = acutil.GetPoint(Type.Missing, prompt1);
MessageBox.Show(pnt[0].ToString());

 But tell me one more thing please.

I have also written code, which works good from AutoCAD application like:

 

using acadApp = Autodesk.AutoCAD.ApplicationServices.Application;
Editor ed = acadApp.DocumentManager.MdiActiveDocument.Editor;
Database db = HostApplicationServices.WorkingDatabase;

 using (Transaction trans = db.TransactionManager.StartTransaction())
            {

...

  Matrix3d ucs = ed.CurrentUserCoordinateSystem;
                Vector3d normal = new Vector3d(0, 0, 1);
                normal = normal.TransformBy(ucs);


                Point3d finalRodStart = new Point3d(newStartX, newStartY, 0).TransformBy(ucs);
                Point3d finalRodEnd = new Point3d(newEndX, newEndY, 0).TransformBy(ucs);

                Line Rod = new Line(finalRodStart, finalRodEnd);

                BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
                BlockTableRecord btr = (BlockTableRecord)trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);

                // get current layer
                ObjectId currentLayer = db.Clayer;
                // get layer to draw rod
                ObjectId drawingLayer = layers.SetDrawingLayer(trans, db, layersEnum.layer.K_ZBR).Id;
                Rod.LayerId = (drawingLayer == ObjectId.Null) ? db.Clayer : drawingLayer;

                // if set, go back to the previous layer
                if (!Properties.Settings.Default.RememberPreviousLayer)
                {
                    db.Clayer = Rod.LayerId;
                }

                btr.AppendEntity(Rod);
                trans.AddNewlyCreatedDBObject(Rod, true);
                trans.Commit();

}

 

 Am I able to use this code from WinForm level?

Is there any way to cast running (or start acad) application within Autodesk.AutoCAD.ApplicationServices.Application class?

 

Message 4 of 4
Hallex
in reply to: GrzesiekGP

THere are few ways how to do it

In example buiild your project as Class Library

Then add Form

Then add singleton to initialize form, i.e.

 

using System;
using System.Collections.Generic;
using System.Text;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using System.Windows.Forms;

[assembly: CommandClass(typeof(MyProject.InitForm))]

namespace MyProject
{

    public class InitForm : IExtensionApplication
    {

        public void Initialize()
        {
            Form1 myForm = new Form1();
            myForm.Show();
        }
        public void Terminate()
        {
        }
    }
}

 Then in Debug tab check radio button "Start project"

 hth

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919

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