Get and Set 3D Solid Position and Path
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Greetings,
I'm trying to create a plugin that automates the insertion of 3D steel bent bars based on user-defined variable dimensions but I couldn't find any exposed methods in the .NET API that can get and set the 3D Solid Geometry properties (such as radius, position, and extrusion path segments). Is there any way to complete the following code? Is there a better way to do this?
[CommandMethod("CustomBar", CommandFlags.Modal)]
public void InsertCustomBar()
{
//OverrulingManager.EnableOverruling();
Document doc = Application.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var element = new ElementBL();//ElementBL is a local class contains user defined values
using (var tr = db.TransactionManager.StartTransaction())
{
Solid3d bar = new Solid3d();
bar.RecordHistory = true;
bar.CreateFrustum(element.Height, element.Diameter * .5, element.Diameter * .5, element.Diameter * .5);
var currentSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
bar.TransformBy(Matrix3d.Displacement(element.InitialPosition.ToAcadPoint()- Point3d.Origin);
currentSpace.AppendEntity(bar);
tr.AddNewlyCreatedDBObject(bar, true);
bar.SetXDataAsGuid("Dummy Text To Enable Overrulling");
bar.SetElementInXDictionaryXrecord(element);//User can modify this element properties from a custom propertygrid and it will be stored as XRecord in the 3D Solid
tr.Commit();
}
}
public class Solid3DDrawingOverrule : DrawableOverrule
{
public Solid3DDrawingOverrule()
{
SetXDataFilter(XDataExtensions.RegAppName);
}
public override bool WorldDraw(Drawable drawable, WorldDraw wd)
{
var bar = (AcDb.Solid3d)drawable;
using (var tr = bar.Database.TransactionManager.StartTransaction())
{
ElementBL element = bar.GetElementFromXDictionaryXrecord();
if (element == null)
return base.WorldDraw(drawable, wd);
//Point3d oldPosition = bar.GetPosition();//TODO: How to get current 3D Solid position
bar.CreateFrustum(element.Height, element.Diameter * .5, element.Diameter * .5, element.Diameter * .5);//Modified successfully but at origin(0,0,0)
//bar.SetPosition(oldPosition);//TODO: How to set 3D Solid position
//bar.SetExtrusionPath(element.GetExtrusionPolyline());//TODO: How to set 3D Solid path
base.WorldDraw(bar, wd);
tr.Commit();
}
return true;
}
}