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

Slowing down when changing Block Reference Property Values

1 REPLY 1
Reply
Message 1 of 2
a.solagaistua
336 Views, 1 Reply

Slowing down when changing Block Reference Property Values

Hello,

 

I'm inserting automatically many references to a couple of dynamic blocks in an AutoCAD drawing using VB.NET. If the number of inserted references is not very big, it works fine but, if I´m inserting hundreds of them, I noticed the app is slowing down a lot.

 

After taking some measures of the time the app uses in its execution, I noticed changing the value of the block reference property is slower as the number of inserted block increases: it takes 10 or 20 miliseconds at the begining but it can take more than 1 second after inserting one thousand of block references (to the same block).

 

This is the function I use to change the property values:

 

Protected Sub CambiarPropiedades(ByRef ed As Editor, _
                                 ByRef br As BlockReference, _
                                 ByVal nombrePropiedad As String, _
                                 ByVal valor As Double)

    Dim pc As DynamicBlockReferencePropertyCollection = br.DynamicBlockReferencePropertyCollection

    If br IsNot Nothing And br.IsDynamicBlock Then

      For Each prop As DynamicBlockReferenceProperty In pc

        If prop.PropertyName = nombrePropiedad Then
          prop.Value = valor  ' This line takes a long time the first time I call this function for the
                              ' same block reference but it is faster in the next calls
                              ' It also changes the block reference name (br.name) in the first call
          Exit For
        End If
      Next

    End If
  End Sub

 Which I call to change all the properties I need to change in an inserted block reference:

 

      CambiarPropiedades(ed, br, "h_testua", objElementoLaboratorio.POS_TEXTO)
      CambiarPropiedades(ed, br, "d_texto_hor", posxTexto)
      CambiarPropiedades(ed, br, "largo", objElementoLaboratorio.LARGO)
      CambiarPropiedades(ed, br, "fondo", objElementoLaboratorio.FONDO)

 A weird thing I noticed is that when I call this function to change the first property of an inserted block, it also changes the .Name of the block reference.

 

Even if I change the order in the property modification, it takes always a lot in the first call, it does not depend on the property I´m changing.

 

Any clue of what is going on?

 

Thanks a lot.

 

Andoni

1 REPLY 1
Message 2 of 2
hgasty1001
in reply to: a.solagaistua

Hi,

 

As for the performance issue , it seems we have to live with it, see this thread in the Swamp: DynBlocks Performance , as for the .Name change it's by design as a DynamicBlock change its name to anomymous block when some dynamic property is changed or activate , after that you need to check the effective name of the block reference, you can implement this "property" as an extension method (Extensions) or a simple function like this:

 

 

Public Function GetEffectiveName(ByVal blkref As BlockReference, ByVal acTrans As Transaction) As String
        Dim btr As BlockTableRecord

        btr = acTrans.GetObject(blkref.DynamicBlockTableRecord, OpenMode.ForRead)
        Return btr.Name

End Function

 

 

Gaston Nunez

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost