kloe Posted October 16, 2010 Share Posted October 16, 2010 hello I need simple code to do just one thing, inserting a dynamic block that is stored in a separate file on my computer (like C:/base/b-22) in the drawing that I'm currently using. For example, I have a windows form with a list box with names of many dynamic blocks that are stored on my c drive, I would like to pick a block with a name and upon a click event of a button or other will go get this block from a separate file and insert it in the drawing I'm currently using, and would need to be able to pick the point of where I want the block to go. Could someone help, I'm using autocad 2010 with visual studio 2008- using the new autocad .net language. Quote Link to comment Share on other sites More sharing options...
RMS Posted November 10, 2010 Share Posted November 10, 2010 I found this link, http://forums.autodesk.com/t5/NET/Code-to-insert-a-dynamic-block-into-the-current-drawing/m-p/2804900 maybe it can help?? Quote Link to comment Share on other sites More sharing options...
Jeff H Posted November 11, 2010 Share Posted November 11, 2010 Just to clone a block from another file and insert a reference would be the same if it was dynamic or not. Here is link to a block manger I posted to get people started with one http://www.theswamp.org/index.php?topic=35280.0 Here is code from that link to bring it in and select a point to insert it. It has it in VB to [color=blue]private[/color] [color=blue]void[/color] InsertBlock([color=blue]string[/color] blkName, [color=blue]string[/color] fileName) { [color=#2b91af]Database[/color] extDb = [color=blue]new[/color] [color=#2b91af]Database[/color]([color=blue]false[/color], [color=blue]true[/color]) [color=blue]as[/color] [color=#2b91af]Database[/color]; extDb.ReadDwgFile(fileName, [color=#2b91af]FileOpenMode[/color].OpenForReadAndAllShare, [color=blue]true[/color], [color=#a31515]""[/color]); [color=#2b91af]Document[/color] doc = [color=#2b91af]AcadApp[/color].DocumentManager.MdiActiveDocument; [color=#2b91af]Editor[/color] ed = doc.Editor; [color=#2b91af]Database[/color] db = doc.Database; [color=blue]using[/color] ([color=#2b91af]DocumentLock[/color] docloc = doc.LockDocument()) [color=blue]using[/color] ([color=#2b91af]Transaction[/color] trx = db.TransactionManager.StartTransaction()) [color=blue]using[/color] ([color=#2b91af]Transaction[/color] extTrx = extDb.TransactionManager.StartTransaction()) { [color=#2b91af]BlockTable[/color] bt = db.BlockTableId.GetObject([color=#2b91af]OpenMode[/color].ForRead) [color=blue]as[/color] [color=#2b91af]BlockTable[/color]; [color=#2b91af]BlockTableRecord[/color] currBtr = db.CurrentSpaceId.GetObject([color=#2b91af]OpenMode[/color].ForRead) [color=blue]as[/color] [color=#2b91af]BlockTableRecord[/color]; [color=blue]if[/color] (!(bt.Has(blkName))) { [color=#2b91af]BlockTable[/color] extBt = extDb.BlockTableId.GetObject([color=#2b91af]OpenMode[/color].ForRead) [color=blue]as[/color] [color=#2b91af]BlockTable[/color]; [color=#2b91af]IdMapping[/color] map = [color=blue]new[/color] [color=#2b91af]IdMapping[/color](); [color=#2b91af]ObjectIdCollection[/color] objIdColl = [color=blue]new[/color] [color=#2b91af]ObjectIdCollection[/color](); [color=blue]try[/color] { objIdColl.Add(extBt[blkName]); } [color=blue]catch[/color] { trx.Commit(); [color=blue]return[/color]; } db.WblockCloneObjects(objIdColl, bt.ObjectId, map, [color=#2b91af]DuplicateRecordCloning[/color].Replace, [color=blue]false[/color]); } [color=#2b91af]ObjectId[/color] btrId = bt[blkName].GetObject([color=#2b91af]OpenMode[/color].ForRead).ObjectId; [color=#2b91af]PromptPointOptions[/color] ppo = [color=blue]new[/color] [color=#2b91af]PromptPointOptions[/color]([color=#a31515]"/nSelect Insertion Point: "[/color]); [color=#2b91af]PromptPointResult[/color] ppr = ed.GetPoint(ppo); [color=blue]if[/color] (ppr.Status == [color=#2b91af]PromptStatus[/color].OK) { [color=#2b91af]Point3d[/color] insertPnt = ppr.Value; currBtr.UpgradeOpen(); [color=#2b91af]BlockReference[/color] bref = [color=blue]new[/color] [color=#2b91af]BlockReference[/color](insertPnt,btrId); currBtr.AppendEntity(bref); trx.AddNewlyCreatedDBObject(bref,[color=blue]true[/color]); } trx.Commit(); } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.