我是AutoCad Plugins
的初学者。我使用以下代码创建了一个圆形数组。现在,我必须在阵列中孵化这些圈子。如何做到这一点?如何一次孵化所有圈子?此外,我怎样才能从方法中返回孵化并用它来孵化物体。对于语言。请提前谢谢。
[assembly: CommandClass(typeof(BeamSection.Class1))]
namespace BeamSection
{
public class Class1
{
//Class1 obj = new Class1();
[CommandMethod("BeamAtSupport")]
public void AddLightweightPolyline()
{
// Get the current document and database
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
PromptPointResult ppr = acDoc.Editor.GetPoint("\nSelect starting point ");
var ucs = acDoc.Editor.CurrentUserCoordinateSystem;
Point3d StartingPt = ppr.Value.TransformBy(ucs);
List<double> radius = new List<double>();
radius.Add(0.5);
radius.Add(1);
double[] pickPont = new double[3];
pickPont = new double[3];
pickPont[0] = StartingPt[0];
pickPont[1] = StartingPt[1];
pickPont[2] = StartingPt[2];
double w = 12.0;
double b = 18.0;
double t = 1.0;
double c = 1.0;
int nb = 3;
// Start a transaction
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
// Open the Block table for read
BlockTable acBlkTbl;
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
OpenMode.ForRead) as BlockTable;
//Open the Block table record Model space for write
BlockTableRecord acBlkTblRec;
acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
OpenMode.ForWrite) as BlockTableRecord;
pickPont[0] = StartingPt[0];
pickPont[1] = StartingPt[1];
pickPont[2] = StartingPt[2];
Application.ShowAlertDialog(pickPont[0].ToString());
double x = calculate(w, b, c, radius, nb);
Circle acCircle = new Circle();
acCircle.Radius = 1.5 * 0.5;
acCircle.Center = new Point3d(pickPont[0] - (w / 2 - 2 * c) - x - 0.1, pickPont[1] + 2 * c, 0);
//acBlkTblRec.AppendEntity(acCircle);
//acTrans.AddNewlyCreatedDBObject(acCircle, true);
/* ObjectIdCollection objColls = new ObjectIdCollection();
objColls.Add(acCircle.ObjectId);
Hatch oHatch = new Hatch();
oHatch.Elevation = 0.0;
oHatch.PatternScale = 2.0;
oHatch.SetHatchPattern(HatchPatternType.PreDefined, "Solid");
oHatch.ColorIndex = 4;
oHatch.Associative = true;
oHatch.AppendLoop(HatchLoopTypes.Outermost, objColls);
oHatch.EvaluateHatch(true);*/
//ObjectIdCollection objColls = new ObjectIdCollection();
//objColls.Add(acCircle.ObjectId);
/* Matrix3d curUCSMatrix = acDoc.Editor.CurrentUserCoordinateSystem;
CoordinateSystem3d curUCS = curUCSMatrix.CoordinateSystem3d;
Vector2d acVec2dAng = new Vector2d(curUCS.Xaxis.X, curUCS.Xaxis.Y);*/
//dArrayAng = dArrayAng; //+ acVec2dAng.Angle;
int nRows = 1;
int nColumns = nb;
double dRowOffset = 1;
double dColumnOffset = x;
Application.ShowAlertDialog(x.ToString());
double dArrayAng = 0;
for (int i = 0; i < 2; i++)
{
Extents3d acExts = acCircle.Bounds.GetValueOrDefault();
Point2d acPt2dArrayBase = new Point2d(acExts.MinPoint.X, acExts.MaxPoint.Y);
if (i == 1)
{
acCircle.Center = new Point3d(pickPont[0] - (w / 2 - 2 * c) - x - 0.1, pickPont[1] + 2 * c, 0);
}
else
{
acCircle.Center = new Point3d(pickPont[0] - (w / 2 - 2 * c) - x - 0.1, pickPont[1] + (b - 3 * t) + 1, 0);
}
DBObjectCollection acDBObjCollCols = new DBObjectCollection();
acDBObjCollCols.Add(acCircle);
int nColumnsCount = 1;
while (nColumns >= nColumnsCount)
{
Entity acEntClone = acCircle.Clone() as Entity;
acDBObjCollCols.Add(acEntClone);
// Caclucate the new point for the copied object (move)
Point2d acPt2dTo = PolarPoints(acPt2dArrayBase, dArrayAng, dColumnOffset * nColumnsCount);
Vector2d acVec2d = acPt2dArrayBase.GetVectorTo(acPt2dTo);
Vector3d acVec3d = new Vector3d(acVec2d.X, acVec2d.Y, 0);
acEntClone.TransformBy(Matrix3d.Displacement(acVec3d));
acBlkTblRec.AppendEntity(acEntClone);
acTrans.AddNewlyCreatedDBObject(acEntClone, true);
nColumnsCount = nColumnsCount + 1;
}
double dAng = Math.PI / 2;
DBObjectCollection acDBObjCollLvls = new DBObjectCollection();
foreach (DBObject acObj in acDBObjCollCols)
{
acDBObjCollLvls.Add(acObj);
}
foreach (Entity acEnt1 in acDBObjCollCols)
{
int nRowsCount = 1;
while (nRows > nRowsCount)
{
Entity acEntClone = acEnt1.Clone() as Entity;
acDBObjCollLvls.Add(acEntClone);
// Caclucate the new point for the copied object (move)
Point2d acPt2dTo = PolarPoints(acPt2dArrayBase, dArrayAng + dAng, dRowOffset * nRowsCount);
Vector2d acVec2d = acPt2dArrayBase.GetVectorTo(acPt2dTo);
Vector3d acVec3d = new Vector3d(acVec2d.X, acVec2d.Y, 0);
acEntClone.TransformBy(Matrix3d.Displacement(acVec3d));
acBlkTblRec.AppendEntity(acEntClone);
acTrans.AddNewlyCreatedDBObject(acEntClone, true);
nRowsCount = nRowsCount + 1;
}
}
}
//acBlkTblRec.AppendEntity(oHatch);
// acTrans.AddNewlyCreatedDBObject(oHatch, true);
acTrans.Commit();
}
acDoc.SendStringToExecute("._zoom _e ", true, false, false);
}