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

Explode Items in Array

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
vince1327
1051 Views, 2 Replies

Explode Items in Array

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;

                    }
                }                    

 


 


2 REPLIES 2
Message 2 of 3
norman.yuan
in reply to: vince1327

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()

 

Message 3 of 3
vince1327
in reply to: norman.yuan

Awesome thanks! I didn't even notice that.

 

Cheers

Vince

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