.NET
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Draw lines from WinForm.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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 ![]()
Re: Draw lines from WinForm.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Take look at this thread
~'J'~
C6309D9E0751D165D0934D0621DFF27919
Re: Draw lines from WinForm.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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.CurrentSpaceI d, 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.RememberPreviousLaye r)
{
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.Applic
Re: Draw lines from WinForm.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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
