简体   繁体   中英

How create lines using c# Wpf in Autocad ? (fatal error)

I'm trying to create my extension (.dll) on Autocad using c# wpf. For now, I testing basic stuffs : I try to create lines with c# but I get a fatal error from Autocad. Internet says that it may come from my Graphic card (Nvidia GeForce GTX 1060) but I updated it and it still doesn't work.

(VS 2017 and Autocad 2018)

"FATAL ERROR : Unhandled e0434352h Exception at d23aa388h"

code :

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();
}
}
}
}

与交易之前,我必须锁定我的文件

using (acdoc.LockDocument())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM