2 Replies Latest reply on Jul 14, 2017 11:22 AM by Luigi Piron

    form is not editable when the procedure is going on

    Luigi Piron

      Hy guy just one question concerning a programming

      i'm moving my vba code on vb.net

       

      in vba when my form was loaded the program went inside the procedure and the form was editable even if the CPU was running

      now i have tried do move the code into vb.net

      i sobstitute inside thecode

       

      do while form1.visible

      do events

      loop

       

      with the corrispond

      do while Me.visible

      Application.Doevents()

      loop

       

      but the form is not editable when cpu is running

      any suggestion ??

        • Re: form is not editable when the procedure is going on
          Christian Chu

          What you mean "From is not editable"?

          By the way, are you trying to write a macro or addin/stand alone in .NET?

            • Re: form is not editable when the procedure is going on
              Luigi Piron

              yes i'tring, but this problem is in a black hole :-)

              i pubblic some code :

               


              Public Class Form1

                  Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

                      Dim swFeatMgr As FeatureManager
                      Dim swConfigMgr As ConfigurationManager
                      Dim swConfig As Configuration
                      Dim swRootComp As Component2
                      Dim swModel As ModelDoc2

                      swApp = CreateObject("SldWorks.Application")
                      swModel = swApp.ActiveDoc
                      swFeatMgr = swModel.FeatureManager
                      swConfigMgr = swModel.ConfigurationManager
                      swConfig = swConfigMgr.ActiveConfiguration
                      swRootComp = swConfig.GetRootComponent3(True)

               

                      Call m()
                   
                      'Timer1.Start() 'Timer starts functioning

                   

                      Timer1.Enabled = True
                      Timer1.Start()


                      swAssDoc = swModel
                      swFeature = swModel.FeatureByName("bla-bla")
                      '-----------------------------------------------------
                      swNameDoc = swAssDoc.GetTitle
                      Debug.Print(swNameDoc)

                      varCompNum = swAssDoc.GetComponentCount(False)   
                      Debug.Print(varCompNum)
                      '- false oltre ai componenti i sottocomponenti true 11 false 13
                      varComp = swAssDoc.GetComponents(False)

                   
                      For i = LBound(varComp) To UBound(varComp)
                      do something with the code.........
                                

                      Next i 
               
                      'swApp.CommandInProgress = False
                      swAssDoc.ClearSelection2(True)
                      ' myModelview.EnableGraphicsUpdate = True
                      'swFeatMgr = swModel.FeatureManager
                      'swModel.FeatureManager.EnableFeatureTree = True '
                      'swFeatMgr.UpdateFeatureTree()


                      'Timer1.Stop() 'Timer stops functioning
                      Timer1.Enabled = False
                      Timer1.Stop()
                      ' Debug.Print("    Time       = " & Timer1.Stop - Timer1.Start() & " s")
                  End Sub


                  Sub m()
              Line5:
                      v = InputBox("inserisci.......")
                      Dim null As Object = Nothing
                      'Dim v As Variant
                      If v Is null Then
                          MsgBox("Non hai inserito nulla." & Chr(13) & "Esco dalla procedura")
                          GoTo Line5
                      End If
                      If Not IsNumeric(v) Then
                          MsgBox("bla-bla.")
                          GoTo Line5

                      End If

                      If InStr(v, ",") > 0 Then v = Replace(v, ",", ".")
                  End Sub


                  Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
                      swApp = Nothing
                  End Sub

               

                  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
                      Timer1.Interval = 10000
                      Label1.Text = "0"
                      Timer1.Start()

                      Do Until Me.Visible
                          Application.DoEvents()
                          'Me.Refresh()
                      Loop
                      'swApp = Nothing
                  End Sub

               

                  Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
                      'Dim counter As Integer
                      Label1.Text = Label1.Text + 1

                      'A = A + 1

                      'Label1.Refresh()
                      'Me.Label1.Text = Me.Label1.Text + 1
                      'Label1.Text = A.ToString

                      Label1.Refresh()
                     
                  End Sub
                  Public Sub Doevents()
                  End Sub

               

                  'Public swModel As ModelDoc2
                  ''' <summary>
                  ''' The SldWorks swApp variable is pre-assigned for you.
                  ''' </summary>

                  Public swApp As SldWorks

               

              End Class