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