.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Link objects of array with polyline

5 REPLIES 5
Reply
Message 1 of 6
vince1327
1768 Views, 5 Replies

Link objects of array with polyline

Hello Everyone,

 

So i'm a bit stuck here. I've managed to create an array using custom blocks. This array is obviously comprised of "x" columns and "x" rows. What i'm trying to do is have the ability to essentially link all of the objects per column (and/or per row) with a polyline. So if i have 5 columns generated, I would like to have 5 polylines extend over those columns. Does anyone have an example of how to do something like this. Essentially what i'm looking to do is create something of a grid using the objects in my array as placemarkers. Sorry if this seems vague.

 

*Edited because i forgot to post some code

 

Cheers

Vince

 

 

And now for a bit of existing code

//Use the upper-left corner of the objects extents for the array base point
                        Extents3d acExts = bref.Bounds.GetValueOrDefault();
                        Point2d acPt2dArrayBase = new Point2d(acExts.MinPoint.X, acExts.MaxPoint.Y);

                        //Track the objects created for each column
                        DBObjectCollection acDBObjCollCols = new DBObjectCollection();
                        acDBObjCollCols.Add(bref);

                        //Create the number of objects in the first column
                        int nColumnsCount = 1;
                        while (nColumns > nColumnsCount)
                        {
                            BlockReference acEntClone = bref.Clone() as BlockReference;
                            acDBObjCollCols.Add(acEntClone);
                            
                            //Calculate 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);

                          //  acEntClone.ExplodeToOwnerSpace();
                            nColumnsCount = nColumnsCount + 1;
                        }

                        //Set a value in radians for 90 degress
                        double dAng = Math.PI / 2;

                        //Track the objects created for each row and column
                        DBObjectCollection acDBObjCollLvls = new DBObjectCollection();

                        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)
                            {
                                BlockReference acEntClone = acEnt.Clone() as BlockReference;
                                acDBObjCollLvls.Add(acEntClone);

                                //Calculate 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;
                            }

 

5 REPLIES 5
Message 2 of 6
wayne.brill
in reply to: vince1327

Hi,

 

I don't have an example for this, I just wonder if using a Table would do what you need? This blog post shows how this can be done:

 

"Inserting block reference into table cell"
http://adndevblog.typepad.com/autocad/2012/04/how-to-insert-block-reference-into-table-cell.html

 



Wayne Brill
Developer Technical Services
Autodesk Developer Network

Message 3 of 6
vince1327
in reply to: wayne.brill

Hey,

 

Thanks for the suggestion. I think, unfortunately, that this approach may cause quite a bit of extra work. Essentially i'm trying to space objects in a room, either horizonatally or vertically. If these rooms are regular shapes (rectangle, square)...it's pretty easy to use an array to accomplish this...however when it comes to odd shapes or angled shapes (triange, randoms, etc)...then the array becomes useless. I've tried simply creating a square array around the irregular shape and just removing the outlying objects so that everything is contained within the shape (room)...but this ruins the spacing as it has to be done to a certain code. I'm sort of stuck here, and the idea of using polylines seems to work, but i'm not sure how to begin implementing it. I really do appreciate the suggestion though, and i'll take a more in-depth look at it. In the meantime though, any other suggestions or examples are welcome!!!!

 

Cheers

Vince

Message 4 of 6
Marat.Mirgaleev
in reply to: vince1327

Hello Vince,

 

   Is the problem you are trying to solve to maintain a given gap (distance) between arbitrary objects? Regardless their shape and orientation?

   If so, there is not any ready solution for this in the AutoCAD API. As you noticed, rectangular bounding boxes are not suitable for this and there is no any API that calculates the distance between the closest points of two objects.

   Sorry, if I didn't understand your problem, could you provide more details then, please?



Marat Mirgaleev
Developer Technical Services
Autodesk Developer Network
Message 5 of 6
vince1327
in reply to: vince1327

Hello,

 

Yes, i'm trying to layout objects with specific distances from each other, and from walls and other extremeties. It's fairly basic when i'm dealing with rectangular and square shaped rooms, but becomes quite complex with any other shape.

 

For instance...If i were to have a a room in the shape of a square with a triangle on top (see attached image...apologies for the quality)...it would be difficult to automatically layout using an array as the angles of the triangle will render the calculations incorrect. However, if i were to determine the horizontal spacing of the objects from each other, and then draw lines from those points on the base of the room (see the red arrows) to the top of the room, then my only concern would be my vertical spacing. This will work, i've tried it on paper, however i'm not sure how to begin to approach it in in AutoCAD. If i could figure this out, this could essentially layout any shape room given the appropriate vertical and horizontal spacing for the objects.

 

For extra info, all objects will have the same vertical and horizontal spacing info...so if there are 30 objects, they all have the same properties.

 

Hopefully this clears everything up a bit.

 

Cheers

Vincesample.jpg

Message 6 of 6
StephenPreston
in reply to: vince1327

Hi Vince,

 

Another (untested) suggestion for you to look into ...

 

I can understand that an old style (simple) array wouldn't work, but I'm wondering if you can achieve what you need using the newer associative array feature. If you can do it through the UI that way, then you should be able to code it - see here for an introduction to the API: http://through-the-interface.typepad.com/through_the_interface/2011/11/creating-a-simple-associative....

 

Failing that, maybe by applying suitable geometric/dimensional constraints to the objects you want to array? Although that's really what the associative array is doing.

 

Cheers,

Stephen Preston
Autodesk Developer Network

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost