.NET

Reply
Active Contributor
Posts: 27
Registered: ‎09-02-2013
Message 1 of 13 (214 Views)
Accepted Solution

Getting Fatal Error in Explode method

214 Views, 12 Replies
11-24-2013 10:48 PM

Hello Gentlemen,

 

I am getting Fatal error at the explode method in the following highlighed (red) code.

Can you please help me?

 

public class ExplodeDynamicBlocks
    {
        [CommandMethod("EDB")]
        public static void ExplodeDymanicBlockReference()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord btr = tr.GetObject(bt["JDuct-SP"], OpenMode.ForWrite) as BlockTableRecord;

                ObjectIdCollection oidc1 = btr.GetAnonymousBlockIds();
                ObjectIdCollection oidc2 = btr.GetBlockReferenceIds(true, false);

                DBObjectCollection dboc = new DBObjectCollection();               

                foreach (ObjectId id in oidc1)
                {
                    BlockReference br = tr.GetObject(id, OpenMode.ForWrite) as BlockReference;
                    br.ExplodeToOwnerSpace();   // I am getting Fatal Error at this point                
                }
            }
        }
    }

 

Also, if possible, how to combine two objectidcollection into one?

*Expert Elite*
Alfred.NESWADBA
Posts: 8,494
Registered: ‎06-29-2007
Message 2 of 13 (206 Views)

Re: Getting Fatal Error in Explode method

11-24-2013 11:58 PM in reply to: aliensinearth

Hi,

 

Two questions:

  • have you verified what the owner for the blockreference is (in case of crashing)?
  • have you tried to do br.Explode instead of br.ExplodeToOwnerspace ... if that also crashes?
  •  

    - alfred -

    BTW: you have not commited the transaction.

    -------------------------------------------------------------------------
    Alfred NESWADBA
    Ingenieur Studio HOLLAUS ... www.hollaus.at
    -------------------------------------------------------------------------
    Active Contributor
    Posts: 27
    Registered: ‎09-02-2013
    Message 3 of 13 (202 Views)

    Re: Getting Fatal Error in Explode method

    11-25-2013 12:07 AM in reply to: Alfred.NESWADBA
    Hi Alfred,
    Thanks for your response.
    For your second question,
    I first tried with the explode only, by creating new dbobject collection object

    DBObjectCollection dboc = new DBObjectCollection();
    BlockTableRecord curSpace = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;

    foreach (ObjectId id in oidc1)
    {
    BlockReference br = tr.GetObject(id, OpenMode.ForWrite) as BlockReference;
    br.Explode(dboc); // same problem here
    foreach (Entity e in dboc)
    {
    curSpace.AppendEntity(e);
    tr.AddNewlyCreatedDBObject(e, true);
    }
    }
    I got the same fatal error. After that only I changed to ExplodeToOwnerspace.

    For your first question,
    Sorry. I don't know how to verify owner?
    *Expert Elite*
    Alfred.NESWADBA
    Posts: 8,494
    Registered: ‎06-29-2007
    Message 4 of 13 (199 Views)

    Re: Getting Fatal Error in Explode method

    11-25-2013 12:14 AM in reply to: aliensinearth

    Hi,

     

    >> I don't know how to verify owner?

    Every object has a property .OwnerID that gives you the ObjectID to the owner object.

     

    As there are some differences in the usage of dynamic blocks and the resulting anonymous blocks can you upload a sample drawing that shows the problem when running your code?

     

    - alfred -

    -------------------------------------------------------------------------
    Alfred NESWADBA
    Ingenieur Studio HOLLAUS ... www.hollaus.at
    -------------------------------------------------------------------------
    Active Contributor
    Posts: 27
    Registered: ‎09-02-2013
    Message 5 of 13 (194 Views)

    Re: Getting Fatal Error in Explode method

    11-25-2013 12:24 AM in reply to: Alfred.NESWADBA

     

    Here I found the problem when I debugged.

    In my code, there are two objectid collection.

     

    1. ObjectIdCollection oidc1 = btr.GetAnonymousBlockIds();

    2. ObjectIdCollection oidc2 = btr.GetBlockReferenceIds(true, false);

     

    when I tried with the second object "oidc2" it works fine.

    foreach (ObjectId id in oidc2)
                    {
                        BlockReference br = tr.GetObject(id, OpenMode.ForWrite) as BlockReference;
                        br.ExplodeToOwnerSpace();
                    }

     

    The problem is with the first object "oidc1".

    foreach (ObjectId id in oidc1)
                    {
                        BlockReference br = tr.GetObject(id, OpenMode.ForWrite) as BlockReference;
                        br.ExplodeToOwnerSpace(); // Problem
                    }

     In the above code,  the "br" object is null. That is why the autocad is crashing when trying to explode null object.

     

    Can you help me now how to explode annonumous blocks?

    BlockReference br = tr.GetObject(id, OpenMode.ForWrite) as BlockReference;

    This is code, we have to change.

     

     

    (Thanks for your immediate response)

    *Expert Elite*
    Alfred.NESWADBA
    Posts: 8,494
    Registered: ‎06-29-2007
    Message 6 of 13 (191 Views)

    Re: Getting Fatal Error in Explode method

    11-25-2013 12:29 AM in reply to: aliensinearth

    Hi,

     

    >> In the above code,  the "br" object is null

    And when you check the following two properties (before accessing the blockreference):

       id.isValid
       id.isErased

    how are they set?

     

    - alfred -

    -------------------------------------------------------------------------
    Alfred NESWADBA
    Ingenieur Studio HOLLAUS ... www.hollaus.at
    -------------------------------------------------------------------------
    Active Contributor
    Posts: 27
    Registered: ‎09-02-2013
    Message 7 of 13 (188 Views)

    Re: Getting Fatal Error in Explode method

    11-25-2013 12:33 AM in reply to: Alfred.NESWADBA

    id.isValid = true;
    id.isErased = false;

    *Expert Elite*
    Alfred.NESWADBA
    Posts: 8,494
    Registered: ‎06-29-2007
    Message 8 of 13 (185 Views)

    Re: Getting Fatal Error in Explode method

    11-25-2013 12:36 AM in reply to: aliensinearth

    Hi,

     

    can you upload a drawing that shows that problem?

    And let us know what type of AutoCAD (vertical product?), what release and what servicepack you have.

     

    - alfred -

    -------------------------------------------------------------------------
    Alfred NESWADBA
    Ingenieur Studio HOLLAUS ... www.hollaus.at
    -------------------------------------------------------------------------
    Active Contributor
    Posts: 27
    Registered: ‎09-02-2013
    Message 9 of 13 (182 Views)

    Re: Getting Fatal Error in Explode method

    11-25-2013 12:48 AM in reply to: Alfred.NESWADBA

    Here is the attached drawing.

    Active Contributor
    Posts: 27
    Registered: ‎09-02-2013
    Message 10 of 13 (171 Views)

    Re: Getting Fatal Error in Explode method

    11-25-2013 01:03 AM in reply to: Alfred.NESWADBA
    Sorry. I didn't see the second question.
    My Autocad Version is Autocad 2011 MEP.
    I don't know about service pack.

    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