.NET
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Get the block name by picking it using VB.net
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
How does someone get the block name in a drawing by picking the block reference in the
drawing using vb.net?
Thank you,
Re: Get the block name by picking it using VB.net
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
psuedo code:
//Create a PromptEntityOptions object
PromptEntityOptions opt=new PromptEntityOptions(....);
//Set PromptEntityOptions' property to allow only Blockreference to be picked
//Pick entity
PromptEntityresult res=theEditor.GetEntity(opt);
if (res.Status=PromptStatus.OK)
{
//Get ObjectId from PromptEntityResult
//Open a transaction to obtain the BlockReference from the ObjectId
//Block name equals to BlcokReference.Name
}
Re: Get the block name by picking it using VB.net
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Oh, addtional info.
If the block refernece is an dynamic block, its name property might be like "*Uxx", which probably is not what you want. So, after getting a BlockRefernce object, you may want to test its IsDynamicBlock property within the transaction. If it is, you need to use its DynamicBlockTableRecord property to get the corresponding BlockTableRecord and then its name.
Re: Get the block name by picking it using VB.net
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
1. I want to understand how to get the block name by picking it.
2. The next step would be to get block attributes of that choosen picked block
and placing its attributes in a MultiText box.
3. That will get me ready to make a program to edit attributes in a choosen block.
Thats my objective now now.
I want to keep the code simple as possable.
Thank you,
Re: Get the block name by picking it using VB.net
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Can't you just use BlockReference.DynamicBlockTableRecord Property for both as DynamicBlockTableRecord & BlockTableRecord property will always be the same for non-dynamic blocks?
Re: Get the block name by picking it using VB.net
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Yes, we can use DynamicBlockTableRecord property to get the blockreference's BlockTableRecord regardless the blockreference being regular block or being dynamic block. However, when doing so, we need to open one more object (BlockTableRecord) to get block name inside the transaction, which is not necessary if the block is not a dynamic block. So, I'd still prefer to test IsDynamicBlock property first.
To the OP: the code is really very simple, that was why I wrote psuedo code above. But since you ask, here you go:
[CommandMethod("MyCmd")]
public static void MyCmd()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.D ocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
string blkName = PickBlock(ed);
ed.WriteMessage("\nPicked block is {{0}\n", blkName);
}
private static string PickBlock(Editor ed)
{
string blkName = "";
PromptEntityOptions opt = new PromptEntityOptions("\nPick a block:");
opt.SetRejectMessage("Bad pick: must be a block");
opt.AddAllowedClass(typeof(BlockReference), true);
PromptEntityResult res = ed.GetEntity(opt);
if (res.Status == PromptStatus.OK)
{
using (Transaction tran = res.ObjectId.Database.TransactionManager.StartTran saction())
{
BlockReference blk = tran.GetObject(res.ObjectId, OpenMode.ForRead) as BlockReference;
if (blk != null)
{
if (blk.IsDynamicBlock)
{
BlockTableRecord br = tran.GetObject(blk.DynamicBlockTableRecord, OpenMode.ForRead) as BlockTableRecord;
blkName = br.Name;
}
else
{
blkName = blk.Name;
}
}
tran.Commit();
}
}
return blkName;
}
Re: Get the block name by picking it using VB.net
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
This code looks like it is in c:
What about vb.net ?
Thank you,
Re: Get the block name by picking it using VB.net
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
http://www.developerfusion.com/tools/convert/cshar

“We don’t have a snowball’s chance in a blast furnace of surviving this attack unless every one of our units gets into the fight right now!”
Re: Get the block name by picking it using VB.net
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
For now All I want to do is go get the block name in vb.net and understand that little
snippet of code first.
Thank you,
Re: Get the block name by picking it using VB.net
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
norman.yuan wrote:Yes, we can use DynamicBlockTableRecord property to get the blockreference's BlockTableRecord regardless the blockreference being regular block or being dynamic block. However, when doing so, we need to open one more object (BlockTableRecord) to get block name inside the transaction, which is not necessary if the block is not a dynamic block. So, I'd still prefer to test IsDynamicBlock property first.
To the OP: the code is really very simple, that was why I wrote psuedo code above. But since you ask, here you go:
[CommandMethod("MyCmd")] public static void MyCmd() { Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; string blkName = PickBlock(ed); ed.WriteMessage("\nPicked block is {{0}\n", blkName); } private static string PickBlock(Editor ed) { string blkName = ""; PromptEntityOptions opt = new PromptEntityOptions("\nPick a block:"); opt.SetRejectMessage("Bad pick: must be a block"); opt.AddAllowedClass(typeof(BlockReference), true); PromptEntityResult res = ed.GetEntity(opt); if (res.Status == PromptStatus.OK) { using (Transaction tran = res.ObjectId.Database.TransactionManager.StartTran saction()) { BlockReference blk = tran.GetObject(res.ObjectId, OpenMode.ForRead) as BlockReference; if (blk != null) { if (blk.IsDynamicBlock) { BlockTableRecord br = tran.GetObject(blk.DynamicBlockTableRecord, OpenMode.ForRead) as BlockTableRecord; blkName = br.Name; } else { blkName = blk.Name; } } tran.Commit(); } } return blkName; }
This code shown above by norman.yuan does exactly what you asked for. It is just in c#. Copy the code to your clipboard and head to the website listed by arcticad. That site has a convertor that will convert the code from c# to vb.net for you. The code is simple enough it should convert just fine.
Most people on the boards on happy enough to answer your questions and give help whenever possible. Some know c# extremely well and others know vb.net extremely well. If someone gives the code in a format different than what you want, it is simple enough to convert it.
