Explode Items in Array

Explode Items in Array

Anonymous
Not applicable
1,478 Views
2 Replies
Message 1 of 3

Explode Items in Array

Anonymous
Not applicable

Hey Guys,

 

I'm creating an array using a block from an existing dwg file on my drive. When i import this block on it's own, i can explode it to ownerspace with "bref.ExplodeToOwnerSpace();" but when i'm creating the array, i don't have this ability and i'm left with one of my blocks in the array exploded, and the rest not. How do i explode the blocks in the array? When i try to use acEntClone.ExplodeToOwnerSpace(); it doesn't exist and i only have the option of acEntClone.Explode().

 

Cheers

Vince

 

 

The Original Block

                            Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
                            Database acCurDb = acDoc.Database;

                            LayerTable acLyrTbl;
                            acLyrTbl = tr.GetObject(acCurDb.LayerTableId, OpenMode.ForRead) as LayerTable;
                            string sLayerName = "CH-SPR";
                            BlockReference bref = new BlockReference(pCenter, BlkId);
                            acCurDb.Clayer = acLyrTbl[sLayerName];

                            string SlayerName2 = "CH-SPR";
                            btr.AppendEntity(bref);
                            bref.Layer = SlayerName2;

                            tr.AddNewlyCreatedDBObject(bref, true);


                            bref.ExplodeToOwnerSpace();
                            bref.Erase();
 
 
The Array Code
int nColumnsCount = 1;
                while (nColumns > nColumnsCount)
                {
                    Entity acEntClone = bref.Clone() as Entity;
                    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);
                    
                    
                    nColumnsCount = nColumnsCount + 1;
                    
                }



and 


 foreach (Entity acEnt in acDBObjCollCols)
                {
                    int nRowsCount = 1;

                    while (nRows > nRowsCount)
                    {
                        Entity acEntClone = acEnt.Clone() as Entity;
                        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;

                    }
                }                    

 


 


0 Likes
Accepted solutions (1)
1,479 Views
2 Replies
Replies (2)
Message 2 of 3

norman.yuan
Mentor
Mentor
Accepted solution

Entity only have Explode() method, while BlockReference has Explode() method (since it is derived from Entity), and its own method ExplodeToOwnerSpace().


Since acEnClone is declared as Entity, thus you do not see ExplodeToOwnerSpace() method available.

 

In the foreach... loop, you change change this

 

Entity acEntClone = acEnt.Clone() as Entity;

 

To

 

BlockReference bref=acEnt.Clone() as BlockReference

 

If acEnt is a Blockreference, then you'll get a Blockreference object cloned, after the clone BlockReference being appended to an owner blocktablerecord (modelspace, for example) and added into databaseand, you can call

 

bref.ExplodeToOwnerSpace()

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 3

Anonymous
Not applicable

Awesome thanks! I didn't even notice that.

 

Cheers

Vince

0 Likes