.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Block name Extraction

6 REPLIES 6
Reply
Message 1 of 7
vivekanandanXVLYD
225 Views, 6 Replies

Block name Extraction

I cant able to extract the name parameter value i have attached the image reference here.

6 REPLIES 6
Message 2 of 7

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.

 

Message 3 of 7
_gile
in reply to: vivekanandanXVLYD

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;


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 4 of 7

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.

Message 5 of 7
kdub_nz
in reply to: vivekanandanXVLYD

@nshupeFMPE3 

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.

class keyThumper<T> : Lazy<T>;      another  Swamper

Message 6 of 7


@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.

Message 7 of 7

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.

Post to forums  

Technology Administrators


Autodesk Design & Make Report