I cant able to extract the name parameter value i have attached the image reference here.
You get the name of a block reference from the Name property of the BlockReference object.
If you are having problems with your code then you should post the code so someone can tell you what the problem is.
hi,
It looks like this block is a dynamic block. In this case, to get the name of the original block, you have to get
the BlockReference.DynamicBlockTableRecord.Name:
string name = ((BlockTableRecord)blockRef.DynamicBlockTableRecord.GetObject(OpenMode.ForRead)).Name;
I hope I'm correct in this, but to add to the answer provided by @_gile; If you are creating a generic function to get the block name from a BlockReference, you can always use BlockReference.DynamicBlockTableRecord.Name. This is because if the block is NOT dynamic, the DynamicBlockTableRecord property will just point to the normal BlockTableRecord.
Or you could use these perhaps :
public bool IsDynamicBlock { get; } |
Declaring Type: | Autodesk.AutoCAD.DatabaseServices.BlockReference |
Assembly: | Acdbmgd, Version=25.0.0.0 |
or
public bool IsDynamicBlock { get; } |
Declaring Type: | Autodesk.AutoCAD.DatabaseServices.BlockTableRecord |
Assembly: | Acdbmgd, Version=25.0.0.0 |
They were designed for that purpose.
// Called Kerry in my other life.
Everything will work just as you expect it to, unless your expectations are incorrect.
Sometimes the question is more important than the answer.
class keyThumper<T> : Lazy<T>; another Swamper
@nshupeFMPE3 wrote:I hope I'm correct in this, but to add to the answer provided by @_gile; If you are creating a generic function to get the block name from a BlockReference, you can always use BlockReference.DynamicBlockTableRecord.Name. This is because if the block is NOT dynamic, the DynamicBlockTableRecord property will just point to the normal BlockTableRecord.
Just to avoid any confusion, BlockReference.DynamicBlockTableRecord.Name isn't a property, you have to open the BlockTableRecord pointed to by the DynamicBlockTableRecord property and then read its name property. And yes, if the block is not dynamic, DynamicBlockTableRecord returns the same value as BlockTableRecord, so there's no need to check IsDynamic first.
I didn't notice that the block whose name you want is dynamic.
Adding this class to your project adds an extension method to the BlockReference class that will return the 'effective' name of the referenced block:
public static class BlockReferenceExtensionMethods
{
public static string GetEffectiveName( this BlockReference target )
{
if( target.IsDynamicBlock )
{
using( BlockTableRecord obj = target.DynamicBlockTableRecord.Open( OpenMode.ForRead, true, true ) as BlockTableRecord )
return obj.Name;
}
return target.Name;
}
}
Using it is simple:
BlockReference blockRef = // Assign to an open BlockReference
string name blockRef.GetEffectiveName():
Can't find what you're looking for? Ask the community or share your knowledge.