.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Jigging a table-again

1 REPLY 1
Reply
Message 1 of 2
Anonymous
233 Views, 1 Reply

Jigging a table-again

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();
}
}
}
}
}
}
1 REPLY 1
Message 2 of 2
Anonymous
in reply to: Anonymous

PS.
now if I can just figure out how to get hyperlinks on the table text
I'll be a happy camper.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost