Click button not refreshing.

Click button not refreshing.

arianlako
Explorer Explorer
658 Views
6 Replies
Message 1 of 7

Click button not refreshing.

arianlako
Explorer
Explorer

Dear friend. I used one Form with three macros (Button_Click) each in the Private sub. When I click the first and second button acad shows the changes immediately, while when I click the third button (third macro) the changes do not appear, they appear after I click the fourth close button.
Can anyone help me? Thank you

0 Likes
Accepted solutions (2)
659 Views
6 Replies
Replies (6)
Message 2 of 7

grobnik
Collaborator
Collaborator
Accepted solution

Hi @arianlako it's depend of third macro functionality, try to add to thirdcmacro as last command to execute thisdrawing.regen acallviewport (check function grammary on line)

0 Likes
Message 3 of 7

norman.yuan
Mentor
Mentor
Accepted solution

As @grobnik suggested, it depends on what the code does behind the third button. While calling AcadDocument.Regen() would certainly cause the screen being fully updated, it may not be desirable if the drawing has tons of entities. Instead, when the code creates/modifies entities in drawing, you can call AcadEntity.Update after the creation/midification to each entity. Or, you can call AcadApplication.Update(), which is lighter in comparison to Regen().

Norman Yuan

Drive CAD With Code

EESignature

Message 4 of 7

arianlako
Explorer
Explorer

Thank you!

0 Likes
Message 5 of 7

arianlako
Explorer
Explorer

Thank you !

0 Likes
Message 6 of 7

arianlako
Explorer
Explorer

This is the third code of the macro,  which can't show changes after the button_click

Private Sub Layer_CDS_PNI()

     Dim found As Boolean
     Dim lay As AcadLayer
     Dim lays As AcadLayers
     Dim layerObj As AcadLayer
     Dim strLayerName As String
     Dim elem As Object

   

     On Error Resume Next
     found = False
     Set lays = ThisDrawing.Layers

     For Each lay In lays
        Set layerObj = ThisDrawing.Layers(lay.Name)
        strLayerName = layerObj.Name

        Select Case strLayerName
            Case "NQUO":
                  layerObj.color = acWhite
                  layerObj.Name = "Shkrime (Text Drawings)"
                  found = True
           Case "SEZ":
                 layerObj.color = 200
                 layerObj.Name = "Rc Section"
                 found = True
          Case "RIQ":
                 layerObj.color = 253
                 layerObj.Name = "Add lines"
                 found = True
        End Select
   Next lay

   If Not found Then
       MsgBox "Zëvendësimi nuk u krye.", vbInformation
   Else
       MsgBox "Zëvendësimi u krye.", vbInformation
   End If
End Sub

Thank You .

0 Likes
Message 7 of 7

norman.yuan
Mentor
Mentor

Well, since what your code changes Layer's property, which is not an AcadEntity, it does not have method Update. Rather, it would affect all entities, if the entities' color is set to ByLayer. So, yes, if you change layer's color, you should see color changes on affected entities, eventually, when your code is FINISHED.

 

But it depends how the code (the procedure Layer_CDS_PNI() runs and finish: if you call the shown code directly from an macro, as if it is a command, then you should see the effect after the code runs without having to do anything else, AutoCAD automatically update the screen for this kind of change once the code execution completes.

 

But from your question, it implies you run the code from a button. You DID not say what the button is from: a button on toolbar/ribbon menu? or from UserForm? My guess is a UserForm (please try describe your case as much as detail). If so, because the UserForm is a modal dialog, it means as long as the form is showing, your code execution is not complete. Once you closes the form, the screen will be updated automatically. Or, you need to force the update by calling Application.Update(), or ThisDrawing.Regen() if necessary. So, you code with the userform's button click would be like:

 

Private Sub CommandButton1_Click()
    Layer_CDS_PNI()
    Application.Update
End Sub

 

HTH

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes