如何在Autocad中使用c# Wpf创建线条?(致命错误)



我正在尝试使用 c# wpf 在 Autocad 上创建我的扩展 (.dll)。现在,我测试基本的东西:我尝试使用 c# 创建行,但我从 Autocad 收到致命错误。互联网说它可能来自我的显卡(Nvidia GeForce GTX 1060),但我更新了它,但它仍然不起作用。

(VS 2017 和 Autocad 2018)

"致命错误:d23aa388h 处出现未处理的 e0434352h 异常"

法典:

命令.cs :

using System.Windows.Forms;
using System.Windows.Forms.Integration;
using Autodesk.AutoCAD.Windows;
using Autodesk.AutoCAD.Runtime;
namespace ClassLibrary1
{
public class Commands
{
static PaletteSet _ps = null;
[CommandMethod("wpf")]
public void ShowWPFPalette()
{
if (_ps == null)
{
// Create the palette set
_ps = new PaletteSet("WPF Palette");
_ps.Size = new System.Drawing.Size(400, 600);
_ps.DockEnabled = (DockSides)((int)DockSides.Left + (int)DockSides.Right);
// Create our user control instance and host it in an ElementHost, which allows interop between WinForms and WPF
UserControl1 uc = new UserControl1();
ElementHost host = new ElementHost();
host.AutoSize = true;
host.Dock = DockStyle.Fill;
host.Child = uc;
_ps.Add("Add ElementHost", host);
}
// Display our palette set
_ps.KeepFocus = true;
_ps.Visible = true;
}
}
}

UserControl1.xaml.cs:

using System.Windows;
using System.Windows.Controls;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Application = Autodesk.AutoCAD.ApplicationServices.Application;
namespace ClassLibrary1
{
/// <summary>
/// Logique d'interaction pour UserControl1.xaml
/// </summary>
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
public void ClickOK(object sender, RoutedEventArgs e)
{
string __S_NomProjet = _TB_NomProjet.Text;
MessageBox.Show("Nom du projet : " + __S_NomProjet, "Nom Projet", MessageBoxButton.YesNo);
}
private void _B_BoutonCartouche_Click(object sender, RoutedEventArgs e)
{
// Get the current document and database
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
// Start a transaction
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
// Open the Block table for read
BlockTable acBlkTbl;
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
OpenMode.ForRead) as BlockTable;
// Open the Block table record Model space for write
BlockTableRecord acBlkTblRec;
acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
OpenMode.ForWrite) as BlockTableRecord;
// Create a line that starts at 5,5 and ends at 12,3
using (Line acLine = new Line(new Point3d(5, 5, 0),
new Point3d(12, 3, 0)))
{
// Add the new object to the block table record and the transaction
acBlkTblRec.AppendEntity(acLine);
acTrans.AddNewlyCreatedDBObject(acLine, true);
}
// Save the new object to the database
acTrans.Commit();
}
}
}
}

我必须在交易前锁定我的文档

using (acdoc.LockDocument())

相关内容

最新更新