Hello,
if i create with the code below-mentioned a solid3d, i have sometimes the error "error handler re-entered".
is there a mistake in the code or is it a problem from the solid3d object?
thanks Peter
I use AutoCAD 2007 ServicePack 1.
Here the code:
using System;
using System.Collections.Generic;
using System.Text;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using DBTransMan = Autodesk.AutoCAD.DatabaseServices.TransactionManager;
[assembly: CommandClass(typeof(ClassLibrary.Zylinder))]
namespace ClassLibrary
{
public class Zylinder
{
[CommandMethod("TestZy")]
static public void Test()
{
Zylinder test = new Zylinder();
test.doit();
}
public bool doit()
{
Point3dCollection points = new Point3dCollection();
points.Add(new Point3d(10, 10, 0));
points.Add(new Point3d(100, 10, 0));
points.Add(new Point3d(150, 50, 0));
Point3d center = new Point3d(10, 10, 0);
//kreis senkrecht zum 1. Liniensegment
Vector3d normal = points[1] - points[0];
Circle dbkreis = new Circle(center, normal, 10);
//Kreis in Liste schreiben
DBObjectCollection curveSegments = new DBObjectCollection();
curveSegments.Add(dbkreis);
//Curve Segments in eine Region umwandeln
DBObjectCollection regionColl = Region.CreateFromCurves(curveSegments);
//Die Konvertierung kreis in Region darf nur ein Regionobjekt liefern
if (regionColl.Count != 1)
return false;
//Curve erzeugen
Curve pline = new Polyline3d(Poly3dType.SimplePoly, points, false);
Solid3d solid = new Solid3d();
//Zylinder als Solid3d erzeugen
solid.ExtrudeAlongPath((Region)regionColl[0], pline, 0);
Database db = Application.DocumentManager.MdiActiveDocument.Database;
DBTransMan tm = db.TransactionManager;
Transaction ta = tm.StartTransaction();
try
{
BlockTable bt = (BlockTable)ta.GetObject(db.BlockTableId, OpenMode.ForRead, false);
BlockTableRecord btr = (BlockTableRecord)ta.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false);
//Bauteil in DB schreiben und ID speichern
btr.AppendEntity(solid);
//Transaktion das neue Element zuweisen
ta.AddNewlyCreatedDBObject(solid, true);
ta.Commit();
}
catch
{
}
finally
{
ta.Dispose();
}
return true;
}
}
}