I'm wondering if anyone has an example of, or knows where to start with this. I've created a basic GUI which can import a specific block "x" amount of times into a DWG. At this point, I want to automatically arrange these blocks within either a selection set or rectangle (essentially between four points, like a box) in a linear fashion. So if i have a rectangle that is 4 units wide and 2 units high, and each block is 1 unit by 1 unit, i'd like to have 2 rows, each comprised of four blocks. I know AutoCAD already has an array command that can accomplish something similar, however what i'm trying to do will need some serious tweaking down the line and i'm looking for somewhere to start. Hopefully someone may have encountered this before or has some idea.
one idea would be to:
(i think you already have) create the block definition; and
start a row-loop, e.g. from 0 to 1; and
a column-loop, e.g. from 0 to 3; and
insert the 1st block ref in each row via its constructor parameter at pt_column0(row); and
the following block refs in each respective row via blockref.gettransformedcopy(matrix3d.displacement(
hope that's what you're after
I am working on the same thing sort of. I need to create a poster of all blocks in a library. At the same time, it will serve as a QC to make sure all blocks are defined at the same relative size, insertion is the middle, etc.
Assume you have a rectangle 4x2 and the top left corner is @ 100,100. The 1st block will be inserted at 101, 99, 2nd @ 102, 99, 3 @ 103,99, 4 @ 104, 99. After 4 is placed, you need to change Y to 99. Block 1 row 2 is 101, 98, etc.
Thats how I am doing it except I am using myblockref.GeometricExtents(). I add 1/2 of the difference between maxpoint.x - minpoint.x + 5%. My 1st insert is forced to 1000,1000. I then use 1/2 of the X extents of the block plus a space factor (5%) to determine the insert of block 2. My ultimate goal is to have the user pick a page size and a start point and use that as "the box". I don't have much coded yet, but attached is where I am at.
Awesome, this helps a bunch...so my next question has been bugging me for a while. I need to select an area in which to auto-arrange my blocks. Is there any selection tool that I can code/call from code that will allow me to select an area and then return it's co-ordinates and potentially area so that I can create points in which to place my blocks?
This is where i'm at so far. The problem with this is, although i can pick four points ,they are all of varying X and Y values, so it will be hard to calculate area. Is there a way I can do this as if i was creating a rectangle for instance? That way I could visualize the lines while selecting the points, but still obtain enough information to determine area?
public class Corners
[CommandMethod("Corners", CommandFlags.Modal | CommandFlags.UsePickSet | CommandFlags.Redraw)]
public void GeWindowPointSelection()
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.D
Database db = doc.Database;
Editor ed = doc.Editor;
List<Point3d> points = new List<Point3d>();
Transaction tr = db.TransactionManager.StartTransaction();
PromptPointOptions ppo = new PromptPointOptions("\n\tSpecify a first corner: ");
PromptPointResult ppr = ed.GetPoint(ppo);
if (ppr.Status != PromptStatus.OK) return;
PromptPointOptions ppo1 = new PromptPointOptions("\n\tSpecify a second corner: ");
PromptPointResult ppr1 = ed.GetPoint(ppo1);
if (ppr1.Status != PromptStatus.OK) return;
PromptPointOptions ppo2 = new PromptPointOptions("\n\tSpecify a third corner: ");
PromptPointResult ppr2 = ed.GetPoint(ppo2);
if (ppr2.Status != PromptStatus.OK) return;
PromptPointOptions ppo3 = new PromptPointOptions("\n\tSpecify a fourth corner: ");
PromptPointResult ppr3 = ed.GetPoint(ppo3);
if (ppr3.Status != PromptStatus.OK) return;
Point3d pt1 = ppr.Value;
Point3d pt2 = ppr1.Value;
Point3d pt3 = ppr2.Value;
Point3d pt4 = ppr3.Value;
double X1 = Convert.ToDouble(pt1.X);
double Y1 = Convert.ToDouble(pt1.Y);
double X2 = Convert.ToDouble(pt2.X);
double Y2 = Convert.ToDouble(pt2.Y);
double X3 = Convert.ToDouble(pt3.X);
double Y3 = Convert.ToDouble(pt3.Y);
double X4 = Convert.ToDouble(pt4.X);
double Y4 = Convert.ToDouble(pt4.Y);
if (pt1.X == pt2.X || pt1.Y == pt2.Y)
ed.WriteMessage("\nInvalid point specification");
BlockTableRecord acadBTR = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
MText acadMText1 = new MText();
MText acadMText2 = new MText();
MText acadMText3 = new MText();
MText acadMText4 = new MText();
MText acadMText5 = new MText();
MText acadMText6 = new MText();
MText acadMText7 = new MText();
MText acadMText8 = new MText();
acadMText1.Location = new Autodesk.AutoCAD.Geometry.Point3d(12, 5, 0);
acadMText2.Location = new Autodesk.AutoCAD.Geometry.Point3d(12, 7, 0);
acadMText3.Location = new Autodesk.AutoCAD.Geometry.Point3d(12, 9, 0);
acadMText4.Location = new Autodesk.AutoCAD.Geometry.Point3d(12, 11, 0);
acadMText5.Location = new Autodesk.AutoCAD.Geometry.Point3d(12, 13, 0);
acadMText6.Location = new Autodesk.AutoCAD.Geometry.Point3d(12, 15, 0);
acadMText7.Location = new Autodesk.AutoCAD.Geometry.Point3d(12, 17, 0);
acadMText8.Location = new Autodesk.AutoCAD.Geometry.Point3d(12, 19, 0);
acadMText1.Contents = "Double X1 = " + X1;
acadMText2.Contents = "Double X2 = " + X2;
acadMText3.Contents = "Double X3 = " + X3;
acadMText4.Contents = "Double X4 = " + X4;
acadMText5.Contents = "Double Y1 = " + Y1;
acadMText6.Contents = "Double Y2 = " + Y2;
acadMText7.Contents = "Double Y3 = " + Y3;
acadMText8.Contents = "Double Y4 = " + Y4;
catch (System.Exception ex)
ed.WriteMessage(ex.Message + "\n" + ex.StackTrace);
No problem. It's always good to give something back to this forum.
Maybe you could use a jig? - something I have never used. Keep searching! Maybe this: http://www.theswamp.org/index.php?topic=30252.0
Access a broad range of knowledge to help get the most out of your products and services.
Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.
Upgrading to a 2015 product? Make sure to check these out 1st!