Author Topic: VB.Net code to retrieve dynamic block's effective name  (Read 5075 times)

0 Members and 1 Guest are viewing this topic.

cannorth

  • Guest
VB.Net code to retrieve dynamic block's effective name
« on: May 11, 2012, 11:30:22 AM »
Hello,

   To get the effective name of a dynamic block in LISP, I read that you can use:

vla-get-EffectiveName

  How do I get the same information using ObjectARX for VB.Net?  I read that there's a GetEffectiveName method,
but it doesn't show up in the block reference object's drop down list of properites and methods.

Thanks,

cannorth
« Last Edit: May 11, 2012, 12:21:43 PM by cannorth »

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: VB.Net code to retrieve dynamic block's effective name
« Reply #1 on: May 11, 2012, 12:11:19 PM »
Something like this should work. Inside a transaction:

effectivename = myblockref.DynamicBlockTableRecord.GetObject(OpenMode.ForRead).Name

TheMaster

  • Guest
Re: VB.Net code to retrieve dynamic block's effective name
« Reply #2 on: May 11, 2012, 12:23:17 PM »
Hello,

   To get the effective name of a dynamic block in LISP, I read that you can use:

vla-get-EffectiveName

  How do I get the same information using ObjectARX for VB.Net?  I read that there's a GetEffectiveName method,
but it doesn't show up in the block reference object's drop down list of properites and methods.

Thanks,

cannorth

Here's what I use:

Code - C#: [Select]
  1.  
  2.   public static class MyExtensions
  3.   {
  4.     public static string GetEffectiveName( this BlockReference blockref )
  5.     {
  6.       if( ! blockref.IsDynamicBlock )
  7.         return blockref.Name;
  8.       return blockref.DynamicBlockTableRecord.GetObject<BlockTableRecord>().Name;
  9.     }
  10.    
  11.     public static T GetObject<T>( this ObjectId id ) where T: DBObject
  12.     {
  13.       return (T) id.GetObject( OpenMode.ForRead, false, false );
  14.     }
  15.   }
  16.  
  17.  

cannorth

  • Guest
Re: VB.Net code to retrieve dynamic block's effective name
« Reply #3 on: May 11, 2012, 12:32:55 PM »
The following code:

blkRef.DynamicBlockTableRecord.GetObject(OpenMode.ForRead, False).Name

Doesn't work because it says Name is not part of DBObject.

cannorth

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: VB.Net code to retrieve dynamic block's effective name
« Reply #4 on: May 11, 2012, 01:39:14 PM »
You need to explicitly cast the DBObject returned by GetObject() into a BlockTableRecord.
Speaking English as a French Frog

Gasty

  • Newt
  • Posts: 90
Re: VB.Net code to retrieve dynamic block's effective name
« Reply #5 on: May 12, 2012, 01:43:51 PM »
Hi,

I'm no sure. but it seems that DynamicBlockTableRecord and BlockTableRecord are the same in a non dynamic block, if so, there is no need to check if the block is dynamic or not, just pick the name from the DynamicBlocktablerecord.

Gaston Nunez

TheMaster

  • Guest
Re: VB.Net code to retrieve dynamic block's effective name
« Reply #6 on: May 12, 2012, 11:19:46 PM »
Hi,

I'm no sure. but it seems that DynamicBlockTableRecord and BlockTableRecord are the same in a non dynamic block, if so, there is no need to check if the block is dynamic or not, just pick the name from the DynamicBlocktablerecord.

Gaston Nunez

Yes, the DynamicBlockTableRecord and BlockTableRecord ids are the same for non-dynamic blocks, but the point to testing to see if the block is dynamic is because for non-dynamic blocks, there is no need to open the referenced BlockTableRecord to get the name, the BlockReference gives it to you.

« Last Edit: May 12, 2012, 11:23:14 PM by TheMaster »

Gasty

  • Newt
  • Posts: 90
Re: VB.Net code to retrieve dynamic block's effective name
« Reply #7 on: May 14, 2012, 02:25:53 AM »
Hi,

Interesting to know that to check if is dynamic it's less expensive than to directly open the dbtr and get the name from it, but in cases when you *need* to open the btr/dbtr, like checking/adding attributes, may be its better to get the effective name from the dbtr. Also if we have a mix of dynamic blocks and the others, it seems more efficient in average, just to check dbtr instead to check if the block is or not a dynamic one.

By the way I'm working in a solution that may have a "massive" number of blocks (maybe thousands of them), both dynamics and non dynamics ones, and I'm using almost exactly the same approach i.e checking dyn/not dyn, and works pretty quick, so my question is purely academic.

Gaston Nunez




TheMaster

  • Guest
Re: VB.Net code to retrieve dynamic block's effective name
« Reply #8 on: May 14, 2012, 02:56:35 AM »
Hi,

Interesting to know that to check if is dynamic it's less expensive than to directly open the dbtr and get the name from it, but in cases when you *need* to open the btr/dbtr, like checking/adding attributes, may be its better to get the effective name from the dbtr. Also if we have a mix of dynamic blocks and the others, it seems more efficient in average, just to check dbtr instead to check if the block is or not a dynamic one.

By the way I'm working in a solution that may have a "massive" number of blocks (maybe thousands of them), both dynamics and non dynamics ones, and I'm using almost exactly the same approach i.e checking dyn/not dyn, and works pretty quick, so my question is purely academic.

Gaston Nunez

Of course, If you are going to open the BlockTableRecord in any case, then it's pointless to test the IsDynamic property of the BlockReference first.  The IsDynamic test is mostly useful when you are only interested in the  block name given a BlockReference, such as when filtering block references based on the block name.