.NET

Reply
*perry
Message 1 of 2 (129 Views)

Jigging a table-again

129 Views, 1 Replies
05-24-2007 10:24 AM
Well, I finally figured out how to jig a table, guess I'm the only one
who ever wanted to do this.
Even though a Table is a block, the constructors are different. The
table has to be created in the jig class constructor. You cant just pass
in a block table record of a table like you can with a block.
Anyways, heres the simplified version of my code in case there is one
other person on the planet who wants to do this...

using System;
using System.Collections.Generic;
using System.Text;

using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.ApplicationServices;
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

[assembly: CommandClass(typeof(YourNamespaceHere.JigTable))]

namespace YourNamespaceHere
{
///
/// Entity jig derivative
///

public class TableJig : EntityJig
{
Point3d position;
///
/// Insert jig
///

public TableJig()
: base (new Table())
{
Table table = Entity as Table;
table.Position = position;
table.InsertRows(0, 0.25, 1);
table.InsertColumns(1, 1.0, 1);
table.SetTextString(1, 1, "test");
}
///
/// Sampler override
///

///
protected override SamplerStatus Sampler(JigPrompts prompts)
{
JigPromptPointOptions jigOpts = new JigPromptPointOptions();
jigOpts.UserInputControls =
UserInputControls.Accept3dCoordinates;
jigOpts.Message = "\nInsertion point: ";
PromptPointResult res = prompts.AcquirePoint(jigOpts);
Point3d curPoint = res.Value;
if (position.DistanceTo(curPoint) > 1.0e-4)
position = curPoint;
else
return SamplerStatus.NoChange;

if (res.Status == PromptStatus.Cancel)
return SamplerStatus.Cancel;
else
return SamplerStatus.OK;
}
///
/// Update override
///

protected override bool Update()
{
try
{
Table table = Entity as Table;
if (table.Position.DistanceTo(position) > 1.0e-4)
{
table.Position = position;
return true;
}
}
catch (System.Exception)
{
}
return false;
}
///
/// return
///

public Entity GetEntity()
{
return Entity;
}
}


//======================================================================================================================

///
/// driver function
///

public class JigTable
{
///
/// table jig command
///

[CommandMethod("tablejig")]
public static void TableJig()
{
Database db =
AcadApp.DocumentManager.MdiActiveDocument.Database;
Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
using (DocumentLock docLock = ed.Document.LockDocument())
{
TableJig jig = new TableJig();
PromptResult res = ed.Drag(jig);
if (res.Status == PromptStatus.OK)
{
using (Transaction tr =
db.TransactionManager.StartTransaction())
{
BlockTable bt =
(BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead, false);
BlockTableRecord btr =
(BlockTableRecord)tr.GetObject(bt[BlockTableRecord.PaperSpace],
OpenMode.ForWrite, false);
btr.AppendEntity(jig.GetEntity());
tr.AddNewlyCreatedDBObject(jig.GetEntity(), true);
tr.Commit();
}
}
}
}
}
}
*perry
Message 2 of 2 (129 Views)

Re: Jigging a table-again

05-24-2007 10:26 AM in reply to: *perry
PS.
now if I can just figure out how to get hyperlinks on the table text
I'll be a happy camper.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.