Я пытаюсь создать свое расширение (.dll) в Autocad, используя c # wpf. Пока я тестирую основные вещи: я пытаюсь создать строки с помощью c #, но я получаю фатальную ошибку от Autocad.
Интернет говорит, что это может происходить от моей графической карты (Nvidia GeForce GTX 1060), но я обновил ее, и она все еще не работает.
(VS 2017 и Autocad 2018)
"ФАТАЛЬНАЯ ОШИБКА: необработанное e0434352h Исключение в d23aa388h"
код:
Command.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();
}
}
}
}