Hello,
First time posting, quite fresh in terms of autocad/lisp/c#/.net but very eager to learn...
Anyway the company i work for has a drawing from which they load all blocks (using Lisp currently). There is a specific block in that collection that i need but i can't seem to load it with c# (or any of the other blocks for that matter). Even though the [insert] command can already see the block in a new drawing. I thought it would be visible in the blocktable but it does not show up when i try to find that same block with c#...
Now i know i can just open the drawing in c# and load the block from there but something tells me that's unneccesary since autocad can already find it with the [insert] command. My question is where exactly do the blocks visible in the [insert]-menu "live" and how do i get access to them? Or how does Autocad find the blocks listed in the [insert] menu and can i translate that over to c#?
Thanks a bunch!
Solved! Go to Solution.
Solved by norman.yuan. Go to Solution.
When discussing "Block" in terms of AutoCAD programming, it would be better to explicitly use term "block definition" (or BlockTableRecord, since the discussion is an=bout Acad .NET API), or "block reference", so that when you say "load [block]", we know what you mean" adding/inserting block definition to current drawing only from an external block drawing file, or inserting a block reference into current drawing's Model[Paper]Space; or both. If you have code posted, that would be helpful to understand what "load" means in your context.
I assume you are talking the "INSERT" command of newer AutoCAD version that shows a modeless paletteset with multiple tabs. If by "Load", you mean the block definitions exist in current drawing, then only blocks shown in tab "Current Drawing" are loaded blocks. Blocks shown in other tab may or may not be loaded in the current drawing (e.g. may or may not available in the BlockTable of the current drawing).
You may ask, if the block definition does not exist in block table of the current drawing, how the "INSERT" command's UI show the block (as an image)? There are ways to extract block image either directly from block definition in the current drawing, or from a block drawing file that is not currently/visibly opened in AutoCAD.
So, assume you want to insert a block reference, but not sure if its definition exists in the current drawing, you would:
1. look up the BlockTable to see if the BlockTableRecord exists or not;
2. If the block definition not in BlockTable, you need to add/insert the block definition from external block drawing by using Database.Insert() method, therefore, you would need
a. You need to know a known/given folder/file path where the block drawing file locate; or
b. Search each AutoCAD support path9folder) for the target block drawing file, until you find it.
3. Once you find the block drawing file, you read it into a blank database, and then insert it into current drawing's database with method Database.Insert(). After this, you can say this block is "loaded"
Norman Yuan
Thank you for the quick response! Appreciate it...
Yeah, sorry i realize i'm new to all the new keywords, for example i was suprised to see .net store things like a default polyline in a blocktable. I will try to be as consise as possible.
1: Yes, i am looking to insert a block reference to the current drawing from an external block drawing file.
2: So if i understand you correctly, the blocks visible in the [insert] menu are only images with a link to the external dwg and the blockreferences are not actually already loaded in the current drawing? None of the blocks visible in the [insert] menu are showing up in the current drawing's blocktable.
So in the case of 2 being true i need to manually load the blockreference from the external drawing file and add it to the current drawing? I think i can manage this, i already bookmarked a topic which covers this so i should be allright. If not you'll definitely hear from me 🙂
(ps how does one share code with proper formatting here?)
In order to create a block reference (e.g. block you see AutoCAD editor, as user), the block definition (BlockTableRecord) must exist in BlockTable. So, as I stated, you need to first to see if the block definition already exists or not. If yes, you can create block reference using that block definition's Id in the BlockReference() contructor. If not, you need to bring the block drawing file into current drawing as block definition (using Database.Insert()). However, you can always bring in the block definition from external block drawing file to overwrite the exiting block definition with the same block name.
To post code with code formatting preserved, you use the button "</>" on top of the message window to copy/paste the code.
Norman Yuan
Can't find what you're looking for? Ask the community or share your knowledge.