.NET

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

Explode Items in Array

329 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*
Posts: 893
Registered: ‎04-27-2009
Message 2 of 3 (308 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 (303 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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community