This will be an ongoing thread with functions added as I get a chance.
Refer to the attached Zip for the full solution.
The routines are noted for functionality.
There are some gotcha's and traps in these incomplete samples.
The intent was to proceed step by step to explore the concepts involved.
//---------------------------------------------------------------
Jeff H has volunteered to convert these Methods to VB.net
Thanks Jeff.
gile has volunteered to convert these Methods to F#
Thanks gile.
//---------------------------------------------------------------
NOTE Solutions updated //------------------------------- Sample Blocks
3DBlock.dwg - block with no attibutes is attached to this first post :
3DBlock_A.dwg - block with one attibute is attached to this first post :
3DBlock_4A.dwg - block with 4 attibutes is attached to this post :
http://www.theswamp.org/index.php?topic=37686.msg427676#msg427676 //------------------------------- C# Solutions
BlockTesting2011 _20110331.1115.zip is attached to this first post :
BlockTesting2011 _20110401.0936.zip is attached to this post :
http://www.theswamp.org/index.php?topic=37686.msg427348#msg427348BlockTesting2011 _ 20110405.1206.zip is attached to this post :
http://www.theswamp.org/index.php?topic=37686.msg427833#msg427833//------------------------------- VB Solutions
BlockTesting2011VB_04012011.zip is attached to this post :
http://www.theswamp.org/index.php?topic=37686.msg427562#msg427562BlockTesting2011VB_04042011.zip is attached to this post :
http://www.theswamp.org/index.php?topic=37686.msg427562#msg427562//------------------------------- F# Solutions
BlockTesting2011FS_20110403.zip is attached to this post :
http://www.theswamp.org/index.php?topic=37686.msg427619#msg427619BlockTesting2011FS_20110405.zip is attached to this post :
http://www.theswamp.org/index.php?topic=37686.msg427843#msg427843//---------------------------------------------------------------
Container :
// CodeHimBelonga kdub@theSwamp 20110331
//
using System;
using System.IO;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
//
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;
using AcUtils = Autodesk.AutoCAD.Internal.Utils;
[assembly
: CommandClass
(typeof(KdubTesting
.BlockTesting2011))]
namespace KdubTesting
{
public class BlockTesting2011
{
Document doc;
Database db;
Editor ed;
public BlockTesting2011()
{
ActiveDoc = AcadApp.DocumentManager.MdiActiveDocument;
}
Document ActiveDoc
{
get { return doc; }
set
{
doc = value;
if( doc == null ) {
db = null;
ed = null;
} else {
db = doc.Database;
ed = doc.Editor;
}
}
}
//=======================================================================
// Methods go here < snip>
//=======================================================================
}
}
//=======================================================================
// add the block to the ActiveDrawing blockTable
[CommandMethod("BI_1")]
public void BlockInsert_1()
{
string blockQualifiedFileName = "K:\\ToTest\\3Dblock_A.dwg";
string blockName = "3Dblock_A";
Database tmpDb
= new Database
(false,
true); tmpDb.ReadDwgFile(blockQualifiedFileName, System.IO.FileShare.Read, true, "");
// add the block to the ActiveDrawing blockTable
db.Insert(blockName, tmpDb, true);
// add the block to the ActiveDrawing blockTable with a Temporary Name
db.Insert("TmpTest", tmpDb, true);
}
//=======================================================================
//=======================================================================
// add the block to the current space (Model or Paper).
// block is exploded IE: copy of original
// Insert will be at World 0,0,0 and transformed for Scale
[CommandMethod("BI_2")]
public void BlockInsert_2()
{
string blockQualifiedFileName = "K:\\ToTest\\3Dblock_A.dwg";
double scale = 5.0;
Database tmpDb
= new Database
(false,
true); tmpDb.ReadDwgFile(blockQualifiedFileName, System.IO.FileShare.Read, true, "");
Matrix3d Transform = Matrix3d.Identity;
Transform = Transform *
Matrix3d.Scaling(scale, Point3d.Origin);
db.Insert(Transform, tmpDb, true);
}
//=======================================================================
//=======================================================================
// add the block to the current space (Model or Paper).
// block is exploded IE: copy of original
// Insert will be at UCS 0,0,0 honouring current X, Y, Z Axis.
// and transformed for Scale
[CommandMethod("BI_3")]
public void BlockInsert_3()
{
string blockQualifiedFileName = "K:\\ToTest\\3Dblock.dwg";
double scale = 2.5;
Database tmpDb
= new Database
(false,
true); tmpDb.ReadDwgFile(blockQualifiedFileName, System.IO.FileShare.Read, true, "");
Matrix3d Transform = ed.CurrentUserCoordinateSystem;
Transform = Transform *
Matrix3d.Scaling(scale, Point3d.Origin);
db.Insert(Transform, tmpDb, true);
}
//=======================================================================
//=======================================================================
// add the block to the current space (Model or Paper).
// block is exploded IE: copy of original
// Insert will be at UCS 0,0,0 honouring current X, Y, Z Axis.
// and transformed for Scale
// and transformed for Displacement
// note that the nominated displacement will be scaled !!
[CommandMethod("BI_4")]
public void BlockInsert_4()
{
string blockQualifiedFileName = "K:\\ToTest\\3Dblock.dwg";
double scale = 3.0;
Vector3d DispacementVector
= new Vector3d
(20,
50,
0); //
Database tmpDb
= new Database
(false,
true); tmpDb.ReadDwgFile(blockQualifiedFileName, System.IO.FileShare.Read, true, "");
Matrix3d Transform = ed.CurrentUserCoordinateSystem;
Transform = Transform *
Matrix3d.Scaling(scale, Point3d.Origin) *
Matrix3d.Displacement(DispacementVector);
db.Insert(Transform, tmpDb, true);
}
//=======================================================================
//=======================================================================
// add the block to the current space (Model or Paper).
// block is exploded IE: copy of original
// Insert will be at UCS 0,0,0 honouring current X, Y, Z Axis.
// and transformed for Scale
// and transformed for Displacement
// note that the nominated displacement will be honoured
[CommandMethod("BI_5")]
public void BlockInsert_5()
{
string blockQualifiedFileName = "K:\\ToTest\\3Dblock_a.dwg";
double scale = 3.0;
Vector3d DispacementVector
= new Vector3d
(20,
50,
0); //
Database tmpDb
= new Database
(false,
true); tmpDb.ReadDwgFile(blockQualifiedFileName, System.IO.FileShare.Read, true, "");
Matrix3d Transform = ed.CurrentUserCoordinateSystem;
Transform = Transform *
Matrix3d.Scaling(scale, Point3d.Origin) *
Matrix3d.Displacement(DispacementVector / scale);
db.Insert(Transform, tmpDb, true);
}
//=======================================================================