To whom that would be so kind.
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.
You can try using the attached code file. It's not commented, but there are examples of usage towards the top of the file.
The public functions and properties are:
InsertFile() &
InsertBlockFromFile() &
BlockTableRecordId (gets the blocktable record id of the inserted block)
The class doesn't handle any of your dynamics or attributes it just gets the block def from another file into your database, you still have to go about inserting the new block into your drawing, something like:
Editor editor = AcadApp.DocumentManager.MdiActiveDocument.Editor;
PromptPointResult pr = editor.GetPoint(new PromptPointOptions("\nGet Point: "));
BlockReference blockRef = new BlockReference(pr.Value, insertMan.BlockTableRecordId);
then work on your attributes and/or dynamic properties before or after actually adding the block to your dwg, but those are relatively easy steps.
Note, after using the InsertFile() or InsertBlockFromFile() functions, you may have to regen the dwg.
cadMeUp,
Thanks for posting your block insert code. Since I am making the switch from VB/VBA to .Net, this will come in handy for the program I am converting now.
However, I used an online converter to translate your code to VB.Net and I get a couple of errors in VS2008. The first one is at the line 'Imports AcadApp = ...' and the message says "Imports alias 'AcadApp' conflicts with 'Structure AcadApp' declared in the root namespace."
The second one is in the line in 'Public Dub New' and begins with 'm_db = AcadApp.DocumentManager...' and the error message says, " 'AcadApp' is not accessible int this context because it is 'Friend'."
Now, I have no clue if this works that way in C# and not in VB, but is there any way you can tell me how to fix it?
Thanks
Yeah, that's just one of the differences between C# and VB, I normally use C# as I find it to be easier and cleaner, to me anyway. At the top of each C# code file I usually add these statements (below my other C# "using" statements):
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;
using DatabaseServ = Autodesk.AutoCAD.DatabaseServices;
using TransMan = Autodesk.AutoCAD.DatabaseServices.TransactionManager;
but in VB the equivalent statements would be:
Imports AcadApp = Autodesk.AutoCAD.ApplicationServices.Application
Imports DatabaseServ = Autodesk.AutoCAD.DatabaseServices
Imports TransMan = Autodesk.AutoCAD.DatabaseServices.TransactionManager
So if you add those VB statements to your code file, below your other "Imports" statements, that should fix the problem.
Just give the 'AcadApp' a different name, like AcAppObject or something similar.
Hopefully you won't get the same conflicts with another namespace.
Do you have a link to the C# to VB code converter that you use? I would like to experiment with it myself, it might help me with future posts.
Thanks for the very prompt reply and help! I will check out the changes and let you know.
The converter I used is from DeveloperFusion and it is here:
http://www.developerfusion.com/tools/
This is just one of several that come up in Google, but it is clean and simple... and it works nicely (I've used it a few times).
Thanks!
Inserting a dynamic block would be the same as any other block, but I guess you are wanting to modify the parameters
Here is one
http://www.theswamp.org/index.php?topic=31859.0
Jeffrey_H,
I would create the blocks parameterized linear or XY, for example, and modify them when they were inserted, which would otherwise be created for each block a block with different attributes, which is impractical for my solution.
The solution to be adopted will be to create template files dwg blocks with predefined dynamic and instantiate them by modifying them to insert code in c #. But it is a problem that many are finding as can be seen in several other forums dealing with the matter. For now I will adopt the solution above. I am studying the case.
I am very grateful for the aid.
Thanks KailasDhage the solution provided.
As you may have noticed I am new to developing AutoCAD.net in c # and my English is very bad. I will take action on it.
Hugs ...
I think there's an easier solution to my problem. How can I delete a block so you can recreate it?
if (bt.Has (TestBlock "))
{
/ / Delete block?
}
Every DBObject has an Erase() method that you can call:
BlockTable bt = (BlockTable)db.BlockTableId.GetObject(OpenMode.ForRead);
if (bt.Has("TestBlock"))
{
BlockTableRecord btr = (BlockTableRecord)bt["TestBlock"].GetObject(OpenMode.ForWrite);
try
{
btr.Erase();
}
catch
{
ed.WriteMessage("\nException: No Erase!");
}
}
You'll probably get some strange results if you have blocks that reference the BlockTableRecord that you want to erase.
Also, for pre-defined dynamic blocks you might want to look into using tool palettes, they work pretty well in that way.
Hello everybody!
I continue to have problems.
To simplify the example of my problem is to create a block containing only one line and a text where the line dimension is defined in the block by adding the user?
I need to add several block references with different dimensions of the line.
Thanks.
Hello There,
If in a Block "Sample" : for example
Sample1= D1=100,D2=200
Sample2= D1=200,D2=400
Sample3= D1=300,D2=600
Among these if i want to pick the last one where should i change to fetch this result.
rgds
Amit