468,253 Members | 1,232 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,253 developers. It's quick & easy.

Pulling dimension from a part in SolidWorks Macro

5 Nibble
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 Images
File Type: png User Form V1.PNG (11.7 KB, 35 views)
File Type: jpg User Form Code.jpg (105.4 KB, 46 views)
Jul 8 '20 #1
6 2333
SioSio
240 128KB
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.
Jul 8 '20 #2
zaxper95
5 Nibble
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.
Jul 8 '20 #3
SioSio
240 128KB
Use the "text" property to display the value in the textbox.
Use the "value" property to reference the value in the textbox.
Expand|Select|Wrap|Line Numbers
  1. Public value As Double
  2.  
  3. Private Sub UserForm_Initialize()
  4.     With ComboBox1
  5.         .AddItem "Bottle 1"
  6.         .AddItem "Bottle 2"
  7.         .AddItem "Bottle 3"
  8.         .AddItem "Bottle 4"
  9.         .AddItem "Bottle 5"
  10.         .AddItem "Bottle 6"
  11.     End With
  12. End Sub
  13.  
  14. Private Sub ComboBox1_Change()
  15.     Select Case ComboBox1.List(ComboBox1.ListIndex)
  16.         Case "Bottle 1"
  17.             value = 1.1
  18.         Case "Bottle 2"
  19.             value = 1.2
  20.         Case "Bottle 3"
  21.             value = 1.3
  22.         Case "Bottle 4"
  23.             value = 1.4
  24.         Case "Bottle 5"
  25.             value = 1.5
  26.         Case "Bottle 6"
  27.             value = 1.6
  28.     End Select
  29.  
  30. End Sub
  31.  
  32. Private Sub CalculateButton_Click()
  33.     AngleTextBox.Text = Math.Atn((CDate(RadiusTextBox.value) / CDate(HightTextBox.value)) * (180# / PI()) + value
  34. End Sub
  35.  
  36. Function PI()
  37.     PI = 4# * Atn(1#)
  38. End Function
Jul 9 '20 #4
zaxper95
5 Nibble
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?
Jul 9 '20 #5
SioSio
240 128KB
I don't know how to get the data of SolidWorks.
You can think of it. And assign it as RadiusTextBox.text=XXXX and HightTextBox.text=XXXX in Combobox1_change() Fanction.
I just fixed a mistake in your code.
Jul 9 '20 #6
SioSio
240 128KB
If the bottle geometry data is stored in the table and you want to retrieve it from the table, issue a query (Select statement).
Jul 9 '20 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

25 posts views Thread by Andrew Dalke | last post: by
3 posts views Thread by Alexander Ulyanov | last post: by
8 posts views Thread by junky_fellow | last post: by
4 posts views Thread by Jimbo | last post: by
reply views Thread by kesterson.al | last post: by
reply views Thread by hollierfloanuu | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.