Posts: 13
Registered: ‎06-01-2010
Message 1 of 2 (393 Views)

AutoCAD Mechanical BOM, Inserting Blocks with AMPartRef

393 Views, 1 Replies
09-23-2013 01:05 AM



I'm afraid this is going to require a little reading as its a fairly unique set of events i need to describe, but i hope someone has seen this and can help!


I am inserting blocks that contain an AMPartRef into a drawing using .NET, when the blocks are inserted before the BOM has been viewed, all the blocks are inserted and the Items appear in the BOM as they would if you used the standard Insert command from CAD.

However if the BOM has been opened and viewed one of 2 things seems to happen

  1. The block is inserted but the item is not added to the BOM, requiring the Add Parts button to be selected from the BOM and the AMPartRef Selected to add it.
  2. THe block is inserted and the part is not added to the BOM and when the Add Parts button is clicked the part cannot be selected to be added to the BOM

To provide more information what i have found is that if the first instance of the block is added using the AutoCAD Insert command, the insert routine i wrote in .NET always functions correctly and the parts are added to the BOM (Using the Block Definition created when manually inserted)


This has leads me to believe that the issue may be with the creation of the Block definition the code for which i have provided below. (A check for if the block definition already exists is done else where)


 private ObjectId InsertBlockDefinition(string fileName)
            Document openDrawing = Core.Application.DocumentManager.MdiActiveDocument;            
            ObjectId newBlockID = ObjectId.Null;
            if (openDrawing != null && CheckFileExists(fileName) == true)
                Transaction currentTransaction = openDrawing.TransactionManager.StartTransaction();

                using (currentTransaction)
                    using (openDrawing.LockDocument())
                        Database openDrawingDatabase = openDrawing.Database;

                        using (openDrawingDatabase)

                            Database newBlockDatabase = null;

                            //Declare a new drawing database to read the block being inserted into
                            using (newBlockDatabase = new Database(false, true))
                                    //Read the content of the drawing from its location into the database 
                                    newBlockDatabase.ReadDwgFile(fileName, System.IO.FileShare.Read, true, "");
                                    newBlockID = openDrawingDatabase.Insert(SymbolUtilityServices.RepairSymbolName(SymbolUtilityServices.GetBlockNameFromInsertPathName(fileName),false), newBlockDatabase,false);
                                catch (System.Exception ex)
                                    System.Windows.MessageBox.Show("File " + fileName + " Read Only, Unable to Insert" + System.Environment.NewLine + "Message: " + ex.Message);



            return newBlockID;

 So guess there are a couple of questions

  1. Has anyone had any problems when inserting Blocks that contain an AMPartRef into a drawing using .NET?
  2. Can anyone shed any light on why I am seeing the behaviour with the AMBOM as described above?
  3. Or does anyone have insight into why this doesn't work consistantly or what changes may be needed to the routine to make it work consistantly?

Any help is greatfully recieved, even just confirmation that Inserting the Block Definintion cant be done this way when an AMPartRef is involved!




Product Support
Posts: 234
Registered: ‎10-14-2007
Message 2 of 2 (364 Views)

Re: AutoCAD Mechanical BOM, Inserting Blocks with AMPartRef

09-24-2013 02:07 AM in reply to: PSharpe
As this issue is about .NET, so I move it to AutoCAD Customization>.Net group. Wish someone could give you help.

Yong Jing
Product Support Specialist
Frontline Technical Support, CSS. GCSO
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

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