Hello guys .
I am just learning how to use the WPF in AutoCAD and hope someone could help me to learn how to do this process to allow me to do future programs on my own later on.
This is the simple dialog with one button entitled "Draw Line"
I need to press the button then the program should draw the line from 0,0,0 to 10,10,0
What is the format that I should build the program with to be able to run it in Autocad ?
Many thanks in advance
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="100" Width="250" HorizontalAlignment="Left" VerticalAlignment="Top">
<Grid Margin="0,0,-8,-3">
<Button x:Name="Draw" Content="Draw Line" HorizontalAlignment="Left" Margin="65,18,0,0" VerticalAlignment="Top" Width="100" Height="30" Click="Draw_Click"/>
</Grid>
And this is the C# codes that I use to draw a line via dll files .
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Text;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using App = Autodesk.AutoCAD.ApplicationServices.Application;
namespace WindowsFormsApplication1
{
class DrawLine
{
[CommandMethod("Drline")]
static public void line()
{
Document acDoc = App.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
BlockTable acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
Line acLine
= new Line
(new Point3d
(0,
0,
0),
new Point3d
(10,
10,
0)); acBlkTblRec.AppendEntity(acLine);
acTrans.AddNewlyCreatedDBObject(acLine, true);
acTrans.Commit();
}
}
}
}