.NET

Reply
Distinguished Contributor
vince1327
Posts: 117
Registered: ‎11-02-2011
Message 1 of 3 (369 Views)
Accepted Solution

Explode Items in Array

369 Views, 2 Replies
03-28-2012 08:26 AM

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;

                    }
                }                    

 


 


*Expert Elite*
norman.yuan
Posts: 986
Registered: ‎04-27-2009
Message 2 of 3 (348 Views)

Re: Explode Items in Array

03-28-2012 10:07 AM 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()

 

Distinguished Contributor
vince1327
Posts: 117
Registered: ‎11-02-2011
Message 3 of 3 (343 Views)

Re: Explode Items in Array

03-28-2012 10:20 AM in reply to: norman.yuan

Awesome thanks! I didn't even notice that.

 

Cheers

Vince

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.