Problem With Rectangular Array Autocad. Net
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi All
I'm New to C# and working on a beginner project. The project is essentially asking the user a set of questions which drive integers to produce a drawing template. I would like Polylines P4 & P5 to be arrayed in the x axis but not in the Y axis. please see attached picture and code. Thanks
public class CreateElevation
{
Point2d PolarPoints(Point2d pPt, double dAng, double dDist)
{
return new Point2d(pPt.X + dDist * Math.Cos(dAng),
pPt.Y + dDist * Math.Sin(dAng));
}
[CommandMethod("DrawElevation")]
public void DrawElevation()
{
int Risers = 0, RiserWidth = 0, Floors = 0, FloorHeigth = 0, FloorVoidOffset = 0, CeilingVoidOffset = 0;
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor edt = doc.Editor;
PromptIntegerOptions Prompt1 = new PromptIntegerOptions("")
{
Message = "\nEnter Number Of Risers : Between 3 - 6",
UpperLimit = 6,
LowerLimit = 3,
AllowNone = false
};
PromptIntegerResult promptIntegerResult = doc.Editor.GetInteger(Prompt1);
if (promptIntegerResult.Status == PromptStatus.OK)
{
Risers = promptIntegerResult.Value;
}
PromptIntegerOptions Prompt2 = new PromptIntegerOptions("")
{
Message = "\nEnter Riser Width : Between 2000 - 5000",
UpperLimit = 5000,
LowerLimit = 2000,
AllowNone = false
};
promptIntegerResult = doc.Editor.GetInteger(Prompt2);
if (promptIntegerResult.Status == PromptStatus.OK)
{
RiserWidth = promptIntegerResult.Value;
}
PromptIntegerOptions Prompt3 = new PromptIntegerOptions("")
{
Message = "\nEnter Number Of Floors : Between 3 - 25",
UpperLimit = 25,
LowerLimit = 3,
AllowNone = false
};
promptIntegerResult = doc.Editor.GetInteger(Prompt3);
if (promptIntegerResult.Status == PromptStatus.OK)
{
Floors = promptIntegerResult.Value;
}
PromptIntegerOptions Prompt4 = new PromptIntegerOptions("")
{
Message = "\nEnter Distance Between Floors : Between 5000 - 9000",
UpperLimit = 9000,
LowerLimit = 5000,
AllowNone = false
};
promptIntegerResult = doc.Editor.GetInteger(Prompt4);
if (promptIntegerResult.Status == PromptStatus.OK)
{
FloorHeigth = promptIntegerResult.Value;
}
using (Transaction acTrans = doc.TransactionManager.StartTransaction())
{
BlockTable bt = acTrans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord btr = acTrans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
int Offset = 1500;
int SlabDepth = 400;
int SlabLength = 6000;
int OutterSlabLength = 9000;
Polyline p3 = new Polyline();
p3.AddVertexAt(0, new Point2d(OutterSlabLength + (RiserWidth), Offset), 0, 0, 0);
p3.AddVertexAt(1, new Point2d(OutterSlabLength + (RiserWidth), SlabDepth + Offset), 0, 0, 0);
p3.AddVertexAt(2, new Point2d(OutterSlabLength + RiserWidth + (SlabLength), SlabDepth + Offset), 0, 0, 0);
p3.AddVertexAt(3, new Point2d(OutterSlabLength + RiserWidth + (SlabLength), Offset), 0, 0, 0);
p3.Closed = true;
btr.AppendEntity(p3);
acTrans.AddNewlyCreatedDBObject(p3, true);
int nColumns = Risers-1;
int dColumnOffset = RiserWidth+6000;
double dArrayAng = 0;
Matrix3d curUCSMatrix = doc.Editor.CurrentUserCoordinateSystem;
CoordinateSystem3d curUCS = curUCSMatrix.CoordinateSystem3d;
Vector2d acVec2dAng = new Vector2d(curUCS.Xaxis.X,
curUCS.Xaxis.Y);
dArrayAng = dArrayAng + acVec2dAng.Angle;
Extents3d acExts = p3.Bounds.GetValueOrDefault();
Point2d acPt2dArrayBase = new Point2d(acExts.MinPoint.X,
acExts.MaxPoint.Y);
DBObjectCollection acDBObjCollCols = new DBObjectCollection();
acDBObjCollCols.Add(p3);
int nColumnsCount = 1;
while (nColumns > nColumnsCount)
{
Entity acEntClone = p3.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));
btr.AppendEntity(acEntClone);
acTrans.AddNewlyCreatedDBObject(acEntClone, true);
nColumnsCount = nColumnsCount + 1;
}
Polyline p1 = new Polyline();
p1.AddVertexAt(0, new Point2d(0, Offset), 0, 0, 0);
p1.AddVertexAt(1, new Point2d(0, SlabDepth + Offset), 0, 0, 0);
p1.AddVertexAt(2, new Point2d(OutterSlabLength, SlabDepth + Offset), 0, 0, 0);
p1.AddVertexAt(3, new Point2d(OutterSlabLength, Offset), 0, 0, 0);
p1.Closed = true;
btr.AppendEntity(p1);
acTrans.AddNewlyCreatedDBObject(p1, true);
Polyline p2 = new Polyline();
p2.AddVertexAt(0, new Point2d(OutterSlabLength + ((RiserWidth + SlabLength) * nColumns + RiserWidth), Offset), 0, 0, 0);
p2.AddVertexAt(1, new Point2d(OutterSlabLength + ((RiserWidth + SlabLength) * nColumns + RiserWidth), SlabDepth + Offset), 0, 0, 0);
p2.AddVertexAt(2, new Point2d(OutterSlabLength + ((RiserWidth + SlabLength) * nColumns + RiserWidth) + (OutterSlabLength), SlabDepth + Offset), 0, 0, 0);
p2.AddVertexAt(3, new Point2d(OutterSlabLength + ((RiserWidth + SlabLength) * nColumns + RiserWidth) + (OutterSlabLength), Offset), 0, 0, 0);
p2.Closed = true;
btr.AppendEntity(p2);
acTrans.AddNewlyCreatedDBObject(p2, true);
double nRows = Floors;
double dRowOffset = FloorHeigth;
// Set a value in radians for 90 degrees
double dAng = Math.PI / 2;
// Track the objects created for each row and column
DBObjectCollection acDBObjCollLvls = new DBObjectCollection();
acDBObjCollCols.Add(p1);
acDBObjCollCols.Add(p2);
foreach (DBObject acObj in acDBObjCollCols)
{
acDBObjCollLvls.Add(acObj);
}
// Create the number of objects for each row
foreach (Entity acEnt in acDBObjCollCols)
{
int nRowsCount = 1;
while (nRows > nRowsCount)
{
Entity acEntClone = acEnt.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));
btr.AppendEntity(acEntClone);
acTrans.AddNewlyCreatedDBObject(acEntClone, true);
nRowsCount = nRowsCount + 1;
}
}
Polyline p4 = new Polyline();
p4.AddVertexAt(0, new Point2d(OutterSlabLength, 0), 0, 0, 0);
p4.AddVertexAt(1, new Point2d(OutterSlabLength, (Offset * 2) + (FloorHeigth) * (Floors - 1) + SlabDepth), 0, 0, 0);
btr.AppendEntity(p4);
acTrans.AddNewlyCreatedDBObject(p4, true);
Polyline p5 = new Polyline();
p5.AddVertexAt(0, new Point2d(OutterSlabLength + RiserWidth, 0), 0, 0, 0);
p5.AddVertexAt(1, new Point2d(OutterSlabLength + RiserWidth, (Offset * 2) + (FloorHeigth) * (Floors - 1) + SlabDepth), 0, 0, 0);
btr.AppendEntity(p5);
acTrans.AddNewlyCreatedDBObject(p5, true);
acTrans.Commit();
doc.SendStringToExecute("._zoom _all ", false, false, false);
}
}
}
Link copied