Pulling dimension from a part in SolidWorks Macro

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zaxper95
    New Member
    • Jul 2020
    • 5

    Pulling dimension from a part in SolidWorks Macro

    Hi Everyone, I am very new at VB and with macro in SolidWorks. As I have stated in the title, I am trying to find a way to pull the radius of the bottle base (a part) and populated it in the user form or have it assigned to a variable so I can use it in calculation.

    User Form V1.PNG shows the user form that I will be using to collect necessary data from the user. Currently, the user will have to manually measure the radius of the bottle in SolidWorks and input it in the userform. However, I would like to make it so that the user will not have to measure the radius, instead have the macro pull that data on its own and assign it to a variable so I can use it for calculation. I am really not sure, how to implement this or if there's a better method to go about this.

    I apologize for the long writing but I wanted to make sure everyone understand what I am trying to get the macro to do. Thank you in advance. I really appreciate it.
    Attached Files
  • SioSio
    Contributor
    • Dec 2019
    • 272

    #2
    Combobox1 has "BASE 1" to "BASE 6" set, but Change() has no options other than "Bottele 1" to "Bottle 6".
    If you don't unify them either, the program does nothing.

    Comment

    • zaxper95
      New Member
      • Jul 2020
      • 5

      #3
      Hi, yes thank you for pointing that out, that was my mistake. Also thank you, your code helped me last time. Could you help me on how I could go about pulling the dimension from the bottle. Please let me know if you need more information from me.

      Comment

      • SioSio
        Contributor
        • Dec 2019
        • 272

        #4
        Use the "text" property to display the value in the textbox.
        Use the "value" property to reference the value in the textbox.
        Code:
        Public value As Double
        
        Private Sub UserForm_Initialize()
            With ComboBox1
                .AddItem "Bottle 1"
                .AddItem "Bottle 2"
                .AddItem "Bottle 3"
                .AddItem "Bottle 4"
                .AddItem "Bottle 5"
                .AddItem "Bottle 6"
            End With
        End Sub
        
        Private Sub ComboBox1_Change()
            Select Case ComboBox1.List(ComboBox1.ListIndex)
                Case "Bottle 1"
                    value = 1.1
                Case "Bottle 2"
                    value = 1.2
                Case "Bottle 3"
                    value = 1.3
                Case "Bottle 4"
                    value = 1.4
                Case "Bottle 5"
                    value = 1.5
                Case "Bottle 6"
                    value = 1.6
            End Select
        
        End Sub
        
        Private Sub CalculateButton_Click()
            AngleTextBox.Text = Math.Atn((CDate(RadiusTextBox.value) / CDate(HightTextBox.value)) * (180# / PI()) + value
        End Sub
        
        Function PI()
            PI = 4# * Atn(1#)
        End Function

        Comment

        • zaxper95
          New Member
          • Jul 2020
          • 5

          #5
          So this would allow for me to reference the value from the part? How would the code know get which part of its body, in solidworks, I am wanting the dimension of? Would this not just grab the code from the text box?

          Comment

          • SioSio
            Contributor
            • Dec 2019
            • 272

            #6
            I don't know how to get the data of SolidWorks.
            You can think of it. And assign it as RadiusTextBox.t ext=XXXX and HightTextBox.te xt=XXXX in Combobox1_chang e() Fanction.
            I just fixed a mistake in your code.

            Comment

            • SioSio
              Contributor
              • Dec 2019
              • 272

              #7
              If the bottle geometry data is stored in the table and you want to retrieve it from the table, issue a query (Select statement).

              Comment

              Working...