{"id":2053,"date":"2014-02-19T21:49:46","date_gmt":"2014-02-19T20:49:46","guid":{"rendered":"https:\/\/www.modelical.com\/?p=337"},"modified":"2022-05-10T17:55:28","modified_gmt":"2022-05-10T15:55:28","slug":"explode-autocad-block-references-using-net","status":"publish","type":"post","link":"https:\/\/www.modelical.com\/en\/explode-autocad-block-references-using-net\/","title":{"rendered":"Explode CAD Blocks using .Net"},"content":{"rendered":"<p>I&#8217;ve been playing a lot with AutoCAD API in the past days. This a function that will help you exploding block references if you provide the Block&#8217;s Name.<\/p>\n<p>Feel free to use, improve and share.<\/p>\n<pre class=\"wrap:true lang:c# decode:true \" title=\"Explode AutoCAD Blocks By Name\">\tpublic bool ExplodeBlockByNameCommand(string blockToExplode)\r\n\t{\r\n    \tbool explodeResult = true;\r\n        Document bDwg = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;\r\n        Editor ed = bDwg.Editor;\r\n        Database db = bDwg.Database;\r\n        Autodesk.AutoCAD.DatabaseServices.TransactionManager bTransMan = bDwg.TransactionManager;\r\n        using (Transaction bTrans = bTransMan.StartTransaction())\r\n        {\r\n\t        try {\r\n    \t         BlockTable bt = (BlockTable)bTrans.GetObject(db.BlockTableId, OpenMode.ForRead);\r\n\r\n\t\t\t\ted.WriteMessage(\"nProcessing {0}\", blockToExplode);\r\n\r\n                if (bt.Has(blockToExplode))\r\n                {\r\n                \tObjectId blkId = bt[blockToExplode];\r\n                    BlockTableRecord btr = (BlockTableRecord)bTrans.GetObject(blkId, OpenMode.ForRead);\r\n                    ObjectIdCollection blkRefs = btr.GetBlockReferenceIds(true, true);\r\n\r\n                    foreach (ObjectId blkXId in blkRefs)\r\n                    {\r\n\t\t\t\t    \t\/\/create collection for exploded objects\r\n                        DBObjectCollection objs = new DBObjectCollection();\r\n\r\n                        \/\/handle as entity and explode\r\n                        Entity ent = (Entity)bTrans.GetObject(blkXId, OpenMode.ForRead);\r\n                        ent.Explode(objs);\r\n                        ed.WriteMessage(\"nExploded an Instance of {0}\", blockToExplode);\r\n\r\n                        \/\/erase Block\r\n                        ent.UpgradeOpen();\r\n                        ent.Erase();\r\n\r\n                        BlockTableRecord btrCs = (BlockTableRecord)bTrans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);\r\n\r\n\t\t\t\t\t\tforeach (DBObject obj in objs)\r\n                        {\r\n                        \tEntity ent2 = (Entity)obj;\r\n                            btrCs.AppendEntity(ent2);\r\n                            bTrans.AddNewlyCreatedDBObject(ent2, true);\r\n                        }\r\n\r\n               \t\t}\r\n               \t}\r\n\r\n                bTrans.Commit();\r\n\t\t\t} catch {\r\n            \ted.WriteMessage(\"nSomething went wrong\");\r\n                explodeResult = false;\r\n            } finally {\r\n        \t}\r\n    \t    ed.WriteMessage(\"n\");\r\n\t        bTrans.Dispose();\r\n        \tbTransMan.Dispose();\r\n    \t}\r\n\r\n    \treturn explodeResult; \/\/return wheter the method was succesful or not\r\n\r\n\t}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been playing a lot with AutoCAD API in the past days. This a function that will help you exploding block references if you provide the Block&#8217;s Name. Feel free to use, improve and share. public bool ExplodeBlockByNameCommand(string blockToExplode) { bool explodeResult = true; Document bDwg = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Editor ed = bDwg.Editor; Database db = [&hellip;]<\/p>\n","protected":false},"author":64,"featured_media":27201,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[4],"tags":[766],"class_list":["post-2053","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-guidelines","tag-technology-autocad"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Explode CAD Blocks using .Net - Modelical<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.modelical.com\/en\/explode-autocad-block-references-using-net\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Explode CAD Blocks using .Net - Modelical\" \/>\n<meta property=\"og:description\" content=\"I&#8217;ve been playing a lot with AutoCAD API in the past days. This a function that will help you exploding block references if you provide the Block&#8217;s Name. Feel free to use, improve and share. public bool ExplodeBlockByNameCommand(string blockToExplode) { bool explodeResult = true; Document bDwg = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Editor ed = bDwg.Editor; Database db = [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.modelical.com\/en\/explode-autocad-block-references-using-net\/\" \/>\n<meta property=\"og:site_name\" content=\"Modelical\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Modelical\/\" \/>\n<meta property=\"article:published_time\" content=\"2014-02-19T20:49:46+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-05-10T15:55:28+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.modelical.com\/wp-content\/uploads\/40_Autocad.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"500\" \/>\n\t<meta property=\"og:image:height\" content=\"375\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Roberto Molinos\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@modelical\" \/>\n<meta name=\"twitter:site\" content=\"@modelical\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Roberto Molinos\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.modelical.com\\\/en\\\/explode-autocad-block-references-using-net\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.modelical.com\\\/en\\\/explode-autocad-block-references-using-net\\\/\"},\"author\":{\"name\":\"Roberto Molinos\",\"@id\":\"https:\\\/\\\/www.modelical.com\\\/en\\\/#\\\/schema\\\/person\\\/3ad52fd99e6b5b98a59ef24c76a7c2d5\"},\"headline\":\"Explode CAD Blocks using .Net\",\"datePublished\":\"2014-02-19T20:49:46+00:00\",\"dateModified\":\"2022-05-10T15:55:28+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.modelical.com\\\/en\\\/explode-autocad-block-references-using-net\\\/\"},\"wordCount\":42,\"image\":{\"@id\":\"https:\\\/\\\/www.modelical.com\\\/en\\\/explode-autocad-block-references-using-net\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.modelical.com\\\/wp-content\\\/uploads\\\/2014\\\/02\\\/PloteadoAutocad.NET-400x250-1.jpg\",\"keywords\":[\"Tec AutoCad\"],\"articleSection\":[\"Guidelines\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.modelical.com\\\/en\\\/explode-autocad-block-references-using-net\\\/\",\"url\":\"https:\\\/\\\/www.modelical.com\\\/en\\\/explode-autocad-block-references-using-net\\\/\",\"name\":\"Explode CAD Blocks using .Net - Modelical\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.modelical.com\\\/en\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.modelical.com\\\/en\\\/explode-autocad-block-references-using-net\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.modelical.com\\\/en\\\/explode-autocad-block-references-using-net\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.modelical.com\\\/wp-content\\\/uploads\\\/2014\\\/02\\\/PloteadoAutocad.NET-400x250-1.jpg\",\"datePublished\":\"2014-02-19T20:49:46+00:00\",\"dateModified\":\"2022-05-10T15:55:28+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.modelical.com\\\/en\\\/#\\\/schema\\\/person\\\/3ad52fd99e6b5b98a59ef24c76a7c2d5\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.modelical.com\\\/en\\\/explode-autocad-block-references-using-net\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.modelical.com\\\/en\\\/explode-autocad-block-references-using-net\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.modelical.com\\\/wp-content\\\/uploads\\\/2014\\\/02\\\/PloteadoAutocad.NET-400x250-1.jpg\",\"contentUrl\":\"https:\\\/\\\/www.modelical.com\\\/wp-content\\\/uploads\\\/2014\\\/02\\\/PloteadoAutocad.NET-400x250-1.jpg\",\"width\":400,\"height\":250},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.modelical.com\\\/en\\\/#website\",\"url\":\"https:\\\/\\\/www.modelical.com\\\/en\\\/\",\"name\":\"Modelical\",\"description\":\"We build information\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.modelical.com\\\/en\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.modelical.com\\\/en\\\/#\\\/schema\\\/person\\\/3ad52fd99e6b5b98a59ef24c76a7c2d5\",\"name\":\"Roberto Molinos\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9346c12c96cb942be9bb8b2454e296662a1baa0b4cd461ab315ae9a5185b0db6?s=96&d=initials&r=g&initials=ro\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9346c12c96cb942be9bb8b2454e296662a1baa0b4cd461ab315ae9a5185b0db6?s=96&d=initials&r=g&initials=ro\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9346c12c96cb942be9bb8b2454e296662a1baa0b4cd461ab315ae9a5185b0db6?s=96&d=initials&r=g&initials=ro\",\"caption\":\"Roberto Molinos\"},\"sameAs\":[\"https:\\\/\\\/www.modelical.com\"],\"url\":\"https:\\\/\\\/www.modelical.com\\\/en\\\/author\\\/roberto\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Explode CAD Blocks using .Net - Modelical","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.modelical.com\/en\/explode-autocad-block-references-using-net\/","og_locale":"en_US","og_type":"article","og_title":"Explode CAD Blocks using .Net - Modelical","og_description":"I&#8217;ve been playing a lot with AutoCAD API in the past days. This a function that will help you exploding block references if you provide the Block&#8217;s Name. Feel free to use, improve and share. public bool ExplodeBlockByNameCommand(string blockToExplode) { bool explodeResult = true; Document bDwg = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Editor ed = bDwg.Editor; Database db = [&hellip;]","og_url":"https:\/\/www.modelical.com\/en\/explode-autocad-block-references-using-net\/","og_site_name":"Modelical","article_publisher":"https:\/\/www.facebook.com\/Modelical\/","article_published_time":"2014-02-19T20:49:46+00:00","article_modified_time":"2022-05-10T15:55:28+00:00","og_image":[{"width":500,"height":375,"url":"https:\/\/www.modelical.com\/wp-content\/uploads\/40_Autocad.jpg","type":"image\/jpeg"}],"author":"Roberto Molinos","twitter_card":"summary_large_image","twitter_creator":"@modelical","twitter_site":"@modelical","twitter_misc":{"Written by":"Roberto Molinos","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.modelical.com\/en\/explode-autocad-block-references-using-net\/#article","isPartOf":{"@id":"https:\/\/www.modelical.com\/en\/explode-autocad-block-references-using-net\/"},"author":{"name":"Roberto Molinos","@id":"https:\/\/www.modelical.com\/en\/#\/schema\/person\/3ad52fd99e6b5b98a59ef24c76a7c2d5"},"headline":"Explode CAD Blocks using .Net","datePublished":"2014-02-19T20:49:46+00:00","dateModified":"2022-05-10T15:55:28+00:00","mainEntityOfPage":{"@id":"https:\/\/www.modelical.com\/en\/explode-autocad-block-references-using-net\/"},"wordCount":42,"image":{"@id":"https:\/\/www.modelical.com\/en\/explode-autocad-block-references-using-net\/#primaryimage"},"thumbnailUrl":"https:\/\/www.modelical.com\/wp-content\/uploads\/2014\/02\/PloteadoAutocad.NET-400x250-1.jpg","keywords":["Tec AutoCad"],"articleSection":["Guidelines"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.modelical.com\/en\/explode-autocad-block-references-using-net\/","url":"https:\/\/www.modelical.com\/en\/explode-autocad-block-references-using-net\/","name":"Explode CAD Blocks using .Net - Modelical","isPartOf":{"@id":"https:\/\/www.modelical.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.modelical.com\/en\/explode-autocad-block-references-using-net\/#primaryimage"},"image":{"@id":"https:\/\/www.modelical.com\/en\/explode-autocad-block-references-using-net\/#primaryimage"},"thumbnailUrl":"https:\/\/www.modelical.com\/wp-content\/uploads\/2014\/02\/PloteadoAutocad.NET-400x250-1.jpg","datePublished":"2014-02-19T20:49:46+00:00","dateModified":"2022-05-10T15:55:28+00:00","author":{"@id":"https:\/\/www.modelical.com\/en\/#\/schema\/person\/3ad52fd99e6b5b98a59ef24c76a7c2d5"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.modelical.com\/en\/explode-autocad-block-references-using-net\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.modelical.com\/en\/explode-autocad-block-references-using-net\/#primaryimage","url":"https:\/\/www.modelical.com\/wp-content\/uploads\/2014\/02\/PloteadoAutocad.NET-400x250-1.jpg","contentUrl":"https:\/\/www.modelical.com\/wp-content\/uploads\/2014\/02\/PloteadoAutocad.NET-400x250-1.jpg","width":400,"height":250},{"@type":"WebSite","@id":"https:\/\/www.modelical.com\/en\/#website","url":"https:\/\/www.modelical.com\/en\/","name":"Modelical","description":"We build information","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.modelical.com\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.modelical.com\/en\/#\/schema\/person\/3ad52fd99e6b5b98a59ef24c76a7c2d5","name":"Roberto Molinos","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/9346c12c96cb942be9bb8b2454e296662a1baa0b4cd461ab315ae9a5185b0db6?s=96&d=initials&r=g&initials=ro","url":"https:\/\/secure.gravatar.com\/avatar\/9346c12c96cb942be9bb8b2454e296662a1baa0b4cd461ab315ae9a5185b0db6?s=96&d=initials&r=g&initials=ro","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9346c12c96cb942be9bb8b2454e296662a1baa0b4cd461ab315ae9a5185b0db6?s=96&d=initials&r=g&initials=ro","caption":"Roberto Molinos"},"sameAs":["https:\/\/www.modelical.com"],"url":"https:\/\/www.modelical.com\/en\/author\/roberto\/"}]}},"_links":{"self":[{"href":"https:\/\/www.modelical.com\/en\/wp-json\/wp\/v2\/posts\/2053","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.modelical.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.modelical.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.modelical.com\/en\/wp-json\/wp\/v2\/users\/64"}],"replies":[{"embeddable":true,"href":"https:\/\/www.modelical.com\/en\/wp-json\/wp\/v2\/comments?post=2053"}],"version-history":[{"count":0,"href":"https:\/\/www.modelical.com\/en\/wp-json\/wp\/v2\/posts\/2053\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.modelical.com\/en\/wp-json\/wp\/v2\/media\/27201"}],"wp:attachment":[{"href":"https:\/\/www.modelical.com\/en\/wp-json\/wp\/v2\/media?parent=2053"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.modelical.com\/en\/wp-json\/wp\/v2\/categories?post=2053"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.modelical.com\/en\/wp-json\/wp\/v2\/tags?post=2053"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}