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

AutoCAD Mechanical BOM, Inserting Blocks with AMPartRef

1 REPLY 1
Reply
Message 1 of 2
PSharpe
787 Views, 1 Reply

AutoCAD Mechanical BOM, Inserting Blocks with AMPartRef

Hi,

 

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))
                            {
                                try
                                {
                                    //Read the content of the drawing from its location into the database 
                                    newBlockDatabase.ReadDwgFile(fileName, System.IO.FileShare.Read, true, "");
                                    newBlockDatabase.CloseInput(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);
                                }
                                currentTransaction.Commit();    
                            }
                        }
                    }

                }                             

            }

            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!

 

Thanks

 

Tags (3)
1 REPLY 1
Message 2 of 2
Yong.Jing
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 Senior Specialist
Technical Support, CSS, GPS

If my post answers your question, please click the "Accept as Solution" button. This helps everyone find answers more quickly!
如果我的回帖解决了您的问题,请点击 "接受为解决方案" 按钮. 这可以帮助其他人更快的找到解决方案!

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