.NET

Reply
Distinguished Contributor
SRSDS
Posts: 243
Registered: ‎04-15-2011
Message 1 of 5 (219 Views)

Speed problem with modifying properties of multiple dynamic blocks

219 Views, 4 Replies
06-05-2012 10:54 AM

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. 

 

 

 

Valued Mentor
AubelecBE
Posts: 372
Registered: ‎01-27-2010
Message 2 of 5 (202 Views)

Re: Speed problem with modifying properties of multiple dynamic blocks

06-05-2012 02:27 PM 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 ?

Distinguished Contributor
SRSDS
Posts: 243
Registered: ‎04-15-2011
Message 3 of 5 (188 Views)

Re: Speed problem with modifying properties of multiple dynamic blocks

06-05-2012 08:10 PM 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.

Valued Mentor
AubelecBE
Posts: 372
Registered: ‎01-27-2010
Message 4 of 5 (183 Views)

Re: Speed problem with modifying properties of multiple dynamic blocks

06-05-2012 10:26 PM 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

 

Valued Contributor
FFlix
Posts: 95
Registered: ‎11-15-2011
Message 5 of 5 (176 Views)

Re: Speed problem with modifying properties of multiple dynamic blocks

06-06-2012 01:48 AM 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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community