style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<uomopinza> wrote in messageHello,
href="news:6068882@discussion.autodesk.com">news:6068882@discussion.autodesk.com...
I'd like to know if it is possible, with the .NET API provided in AutoCAD
2009, to define dynamic blocks (dynamic properties and actions) completely
from .NET code (VB.NET or C#). If yes, can someone provide me a tutorial about
this issue ? Thank you.
I hope bobbydehero will not make a sense on me..
Try this slightly eedited code
{code}
[CommandMethod("DynamicPropertiesTest","dyntest", CommandFlags.Modal )]
public static void TestDynProps()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
BlockReference bref = trans.GetObject(ed.GetEntity("\nSelect dynamic block").ObjectId, OpenMode.ForRead) as BlockReference;
if (bref == null)
{
Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("Nothing or wrong object selected");
return;
}
if (!bref.IsDynamicBlock)
{
Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("selected is not dynamick block");
return;
}
BlockTable bt = (BlockTable)(trans.GetObject(db.BlockTableId, OpenMode.ForRead));
BlockTableRecord btrec = trans.GetObject(bref.DynamicBlockTableRecord, OpenMode.ForRead,false) as BlockTableRecord;
string sDynBlk = btrec.Name;
if (bt.Has(sDynBlk) == true)
{
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[sDynBlk], OpenMode.ForRead);
if (btr.IsDynamicBlock)
{
try
{
DBDictionary extDictDynBT = (DBDictionary)trans.GetObject(btr.ExtensionDictionary, OpenMode.ForRead, false);
DBObject acadEnhancedBlk = (DBObject)trans.GetObject(extDictDynBT.GetAt("ACAD_ENHANCEDBLOCK"), OpenMode.ForRead, false);
EvalGraph graph = null;
ObjectId idGraph = acadEnhancedBlk.ObjectId;
if (!idGraph.IsNull)
graph = (EvalGraph)trans.GetObject(idGraph, OpenMode.ForRead);
if (graph != null)
{
int[] iNodes = graph.GetAllNodes();
foreach (int iNode in iNodes)
{
DBObject node = graph.GetNode((uint)iNode, OpenMode.ForRead, trans);
if (node != null)
{
EvalExpr eExpr = node as EvalExpr;
if (eExpr.GetType() == typeof(BlockLookupAction))
{
BlockLookupAction blua = eExpr as BlockLookupAction;
if (blua != null)
{
Array pDataTable;
LookupColumnDescriptorCollection descArray;
blua.GetLookupTable(out pDataTable, out descArray);
if (pDataTable != null)
{
foreach (object obj in pDataTable)
{
ed.WriteMessage("\n\t{0}", obj.ToString());
}
}
}
}
if (eExpr.GetType() == typeof(BlockLookupParameter))
{
BlockLookupParameter blup = eExpr as BlockLookupParameter;
if (blup != null)
{
BlockParameterPropertyDescriptorCollection props = blup.PropertyDescription;
Array pDataTable;
foreach (BlockParameterPropertyDescriptor prop in props)
{
ed.WriteMessage("\n\t{0}", prop.PropertyName);
pDataTable = prop.ValueSetValues;
if (pDataTable != null)
{
foreach (object obj in pDataTable)
{
ed.WriteMessage("\n\t{0}", obj.ToString());
}
}
}
}
}
if (eExpr.GetType() == typeof(BlockFlipParameter))
{
BlockFlipParameter blup = eExpr as BlockFlipParameter;
if (blup != null)
{
BlockParameterPropertyDescriptorCollection props = blup.PropertyDescription;
Array pDataTable;
foreach (BlockParameterPropertyDescriptor prop in props)
{
ed.WriteMessage("\n\t{0}", prop.PropertyName);
pDataTable = prop.ValueSetValues;
if (pDataTable != null)
{
foreach (object obj in pDataTable)
{
ed.WriteMessage("\n\t{0}", obj.ToString());
}
}
}
}
}
//--------- add other actions / parameters same way here -------------------//
}
}
}
}
catch (System.Exception ex)
{
Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(ex.ToString());
}
}
}
}
}
{code}
~'J'~
ed.GetEntity("\nSelect dynamic block"
this still needs a dyna block first, not create one from scrath by program.
Hello,
I would like to edit dynamic blocks with .Net. Unfortunately I do not find much on the internet. It seems as if Autodesk did not want to publish anything.
Can I learn more about this subject? Do you have a more recent example?
Or any other info?
Many thanks in advance
Hermann White
Can't find what you're looking for? Ask the community or share your knowledge.