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

Speed problem with modifying properties of multiple dynamic blocks

4 REPLIES 4
Reply
Message 1 of 5
SRSDS
457 Views, 4 Replies

Speed problem with modifying properties of multiple dynamic blocks

Would there be a faster way of doing the following?

 

I have a an event that updates dynamic properties of potentialy hundreds blocks. I'm a bit surprised at how slow it is considering that if I filter and change the colors of the same blocks it is instantaneous.

 

    Sub ModifyViewDimensions(ByVal trans As Transaction)
        For Each ObjID In tmpIDCollection
           ProgressBar("Updating Views", tmpIDCollection.Count, False)
            Dim br As BlockReference = DirectCast(trans.GetObject(ObjID, OpenMode.ForWrite), BlockReference)
            Dim pc As DynamicBlockReferencePropertyCollection = br.DynamicBlockReferencePropertyCollection
            For i = 0 To pc.Count - 1
                Dim prop As DynamicBlockReferenceProperty = pc(i)
                If prop.PropertyName = "A" Then prop.Value = A
                If prop.PropertyName = "B" Then prop.Value = B
                If prop.PropertyName = "C" Then prop.Value = C
                If prop.PropertyName = "D" Then prop.Value = D
                If prop.PropertyName = "E" Then prop.Value = E_
            Next
            br.Dispose()
            pc.Dispose()
        Next
        ProgressBar("Updating Views", tmpIDCollection.Count, True)
    End Sub

 

I use a main transaction and pass that transaction through all my subroutines. There is something also after the procedure that also causes a long delay. I assume the drawing regen but there is no way to add a progress bar to that.

Performed on 60 blocks it takes 15 seconds to make the updates then there's a 20 second stall for the drawing to update.

 

Hope someone can help. 

 

 

 

4 REPLIES 4
Message 2 of 5
AubelecBE
in reply to: SRSDS

Sub ModifyViewDimensions(ByRef trans As Transaction)
        Dim br As BlockReference 
        Dim pc As DynamicBlockReferencePropertyCollection 

        For Each ObjID In tmpIDCollection
           ProgressBar("Updating Views", tmpIDCollection.Count, False)
            br = DirectCast(trans.GetObject(ObjID, OpenMode.ForWrite), BlockReference)
            pc = br.DynamicBlockReferencePropertyCollection
            For i = 0 To pc.Count - 1
                Dim prop As DynamicBlockReferenceProperty = pc(i)
                If prop.PropertyName = "A" Then prop.Value = A
                If prop.PropertyName = "B" Then prop.Value = B
                If prop.PropertyName = "C" Then prop.Value = C
                If prop.PropertyName = "D" Then prop.Value = D
                If prop.PropertyName = "E" Then prop.Value = E_
            Next
        Next
        ProgressBar("Updating Views", tmpIDCollection.Count, True)
    End Sub

 HI i am a noob with vb.net but if you :

-dispose br or dispose pc you have a bug i think you can't dipose a object not create directly with a new ..

-Byval trans is not good so try Byref

-déclare before your for each the type of var

 

try this and say if it is ok.

 

and : prop.Value = A    --> what mean A  ?   is a var ?  integer ? etc..
and : tmpIDCollection is a global var ?

Message 3 of 5
SRSDS
in reply to: AubelecBE

Hi,

I get an unhandled exception “attempted to read or write protected memory” if I don’t dispose br & pc. It’s the reason I added them but I don’t understand this either.

 

A and tmpIDCollection are global. Might not be the best practice thing to do but I there are a few commonly used variables I can’t be bothered passing all the time.

 

I’ve realised that the 20 second ?regen? problem doesn’t occur on the first instance of the event which is odd. Something is hurting it after the first one. I may need to shell the procedure down to try to isolate the problem.

Message 4 of 5
AubelecBE
in reply to: SRSDS

hi. i dont use transaction out of a sub/function.

try to create the transaction in the sub. and use trans.commit

 

Message 5 of 5
adadnet
in reply to: SRSDS

hi, substitute the 'for i = 0 ...' loop by a 'for each' loop if the order doesn't matter. this way you have the 'prop' declaration on the outset of the loop and also add [some] flexibility within the loop. if the individual props are mutually exclusive, test adding " : continue for" at the end of each line

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