This macro will create a folder and place inside of it a part document file and 3 dxf files. A user form pops up asking for box dimensions (inner measurements), thickness of the material being cut, amount of overhang to be sanded off later, and whether or not to add handles to the shorter sides of your box. Since this macro is creating a part file you'll need to adjust line 57 of the main code (not the userForm code) to point to your version of solidWorks' Part.prtdot file. Also, take a look at line 23 of the code. You have to have a folder named Boxes located at "C:\Solidworks Files\Boxes\". This macro creates folders inside that Boxes folder to hold your part file and 3 dxf files.

Box.bmp
Box.swp

  1.  
  2. 'Preconditions: Adjust line 29 of the code to point to the folder you wish to store all generated folders and files.
  3. 'Adjust line 57 to point to the solidworks default part file on your system.
  4.  
  5. Dim swApp As SldWorks.SldWorks
  6. Dim part As SldWorks.ModelDoc2
  7. Dim boolstatus As Boolean
  8. Dim longstatus As Long, longwarnings As Long
  9. Dim thick As Long
  10. Dim myModelView As ModelView
  11. Dim final As Double
  12. Dim final2 As Double
  13. Dim sModelName As String
  14. Dim sPathName As String
  15. Dim varAlignment As Variant
  16. Dim dataAlignment(11) As Variant
  17. Dim dataAlignment2(11) As Variant
  18. Dim varViews As Variant
  19. Dim dataViews(0) As String
  20. Dim options As Long
  21. Dim test As String
  22. Dim partTitle As String
  23. Dim fix1 As Double
  24. Dim halfWidth As Double
  25. Dim folderPath As String
  26. Public addHandle As Boolean
  27.  
  28. Sub main()
  29. folderPath = "c:\Solid Works Files\Boxes\"
  30. Set swApp = Application.SldWorks
  31. Set part = swApp.ActiveDoc
  32. Dim skSegment As Object
  33. UserForm1.Show
  34. End Sub
  35.  
  36. Public Sub createBox(inputLength As Double, inputWidth As Double, inputHeight As Double, inputThickness As Double, inputSand As Double)
  37. UserForm1.Hide
  38. Dim temp As Double
  39. Dim fileName As String
  40. If inputLength > inputWidth Then 'handles go on shorter side so length must be less than width
  41. temp = inputLength
  42. inputLength = inputWidth
  43. inputWidth = temp
  44. End If
  45. fileName = inputWidth & "-" & inputLength & "-" & inputHeight & "-" & inputThickness
  46.  
  47. '######################## CREATE FOLDER ############################################
  48. Dim fso
  49. Set fso = CreateObject("Scripting.FileSystemObject")
  50. If (fso.FolderExists(folderPath & fileName)) Then
  51. MsgBox "folder exists"
  52. Else
  53. MkDir folderPath & fileName
  54. End If
  55.  
  56. '#################################### SAVE AS SLDPRT FILE ##############################################
  57. Set part = swApp.NewDocument("C:\ProgramData\SolidWorks\SOLIDWORKS 2017\templates\Part.prtdot", 0, 0, 0)
  58. swApp.ActivateDoc2 "Part1", False, longstatus
  59. longstatus = part.SaveAs3(folderPath & fileName & "\" & fileName & ".SLDPRT", 0, 2)
  60. partTitle = part.GetTitle
  61. swApp.CloseDoc partTitle
  62. Set part = swApp.OpenDoc6(folderPath & fileName & "\" & fileName & ".SLDPRT", 1, 0, "", longstatus, longwarnings)
  63. boolstatus = part.Extension.SelectByID2("Top Plane", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
  64. part.SketchManager.InsertSketch True
  65. Dim instance As ISketchManager
  66. Set instance = part.SketchManager
  67. Dim Width, Length, Height, Thickness, Extra, Extra2, distance, distance2, sand As Double
  68. Width = (inputWidth * 0.0254)
  69. Length = inputLength * 0.0254
  70. Thickness = (inputThickness * 0.0254)
  71. Height = inputHeight * 0.0254
  72. Height = Height + (0.5 * 0.0254) + Thickness 'account for bottom of box
  73. sand = inputSand * 0.0254
  74. instance.AddToDB = True
  75.  
  76. '######################## FRONT WIDTH ############################
  77. fix1 = inputWidth / inputThickness
  78. Extra = (inputWidth - (Int(fix1)) * inputThickness) * 0.5 * 0.0254
  79. If Extra / 0.0254 < 0.0001 Then
  80. Extra = 0
  81. End If
  82. If (Int(fix1)) Mod 2 = 0 Then 'odd #? then add half
  83. Extra = Extra + (0.5 * Thickness)
  84. Else
  85. End If
  86. distance = Thickness * 2 + Extra
  87. Set skSegment = part.SketchManager.CreateLine(Thickness, Thickness, 0#, distance, Thickness, 0#) 'over
  88. final = Width - (Thickness + Extra)
  89. Do While Width - (Thickness + Extra) - distance > 0.0000001 And Abs(final - distance + 2 * Thickness) > 0.0001 / 0.0254
  90. Set skSegment = part.SketchManager.CreateLine(distance, Thickness, 0#, distance, -sand, 0#) 'down
  91. Set skSegment = part.SketchManager.CreateLine(distance, -sand, 0#, (distance + Thickness), -sand, 0#) 'over
  92. Set skSegment = part.SketchManager.CreateLine((distance + Thickness), -sand, 0#, (distance + Thickness), Thickness, 0#) 'up
  93. Set skSegment = part.SketchManager.CreateLine((distance + Thickness), Thickness, 0#, (distance + Thickness * 2), Thickness, 0#) 'over
  94. distance = distance + Thickness * 2
  95. Loop
  96. Set skSegment = part.SketchManager.CreateLine(distance, Thickness, 0#, distance, -sand, 0#) 'down
  97. Set skSegment = part.SketchManager.CreateLine(distance, -sand, 0#, (distance + Thickness), -sand, 0#) 'over
  98. Set skSegment = part.SketchManager.CreateLine(distance + Thickness, -sand, 0#, distance + Thickness, Thickness, 0#) 'up
  99. Set skSegment = part.SketchManager.CreateLine(distance + Thickness, Thickness, 0#, Width + Thickness, Thickness, 0#) 'over
  100.  
  101. '####################### RIGHT LENGTH ##############################
  102. fix1 = inputLength / inputThickness
  103. Extra2 = (inputLength - (Int(fix1) * inputThickness)) * 0.5 * 0.0254
  104. If Int(fix1) Mod 2 = 0 Then 'if odd # then?'
  105. Extra2 = Extra2 + (0.5 * Thickness) 'even # of thicknesses
  106. End If
  107. distance2 = Thickness * 2 + Extra2
  108. final2 = Length - (Thickness + Extra2)
  109. Set skSegment = part.SketchManager.CreateLine((Width + Thickness), Thickness, 0#, (Width + Thickness), distance2, 0#) 'up
  110. Do While Length - (Thickness + Extra2) - distance2 > 0.0000001 And Abs(final2 - distance2 + 2 * Thickness) > 0.0001 / 0.0254
  111. Set skSegment = part.SketchManager.CreateLine((Width + Thickness), distance2, 0#, (Width + Thickness * 2 + sand), distance2, 0#) 'out
  112. Set skSegment = part.SketchManager.CreateLine((Width + Thickness * 2 + sand), distance2, 0#, (Width + Thickness * 2 + sand), (distance2 + Thickness), 0#) 'up
  113. Set skSegment = part.SketchManager.CreateLine((Width + Thickness * 2 + sand), (distance2 + Thickness), 0#, (Width + Thickness), (distance2 + Thickness), 0#) 'in
  114. Set skSegment = part.SketchManager.CreateLine(Width + Thickness, distance2 + Thickness, 0#, Width + Thickness, distance2 + Thickness * 2, 0#) 'up
  115. distance2 = distance2 + Thickness * 2
  116. Loop
  117. Set skSegment = part.SketchManager.CreateLine(Width + Thickness, distance2, 0#, Width + Thickness * 2 + sand, distance2, 0#) 'out
  118. Set skSegment = part.SketchManager.CreateLine(Width + Thickness * 2 + sand, distance2, 0#, Width + Thickness * 2 + sand, distance2 + Thickness, 0#) 'up
  119. Set skSegment = part.SketchManager.CreateLine(Width + Thickness * 2 + sand, distance2 + Thickness, 0#, Width + Thickness, distance2 + Thickness, 0#) 'in
  120. Set skSegment = part.SketchManager.CreateLine(Width + Thickness, distance2 + Thickness, 0#, Width + Thickness, Length + Thickness, 0#) 'up
  121.  
  122. '############################################## BACK WIDTH #####################################################################
  123. distance = Width - Extra
  124. Set skSegment = part.SketchManager.CreateLine(Width + Thickness, Length + Thickness, 0#, distance, Length + Thickness, 0#) 'over
  125. Do While distance > 4 * Thickness + Extra
  126. Set skSegment = part.SketchManager.CreateLine(distance, Length + Thickness, 0#, distance, Length + Thickness * 2 + sand, 0#) 'up
  127. Set skSegment = part.SketchManager.CreateLine(distance, Length + Thickness * 2 + sand, 0#, distance - Thickness, Length + Thickness * 2 + sand, 0#) 'over
  128. Set skSegment = part.SketchManager.CreateLine(distance - Thickness, Length + Thickness * 2 + sand, 0#, distance - Thickness, Length + Thickness, 0#) 'down
  129. Set skSegment = part.SketchManager.CreateLine(distance - Thickness, Length + Thickness, 0#, distance - Thickness * 2, Length + Thickness, 0#) 'over
  130. distance = distance - Thickness * 2
  131. Loop
  132. Set skSegment = part.SketchManager.CreateLine(distance, Length + Thickness, 0#, distance, Length + Thickness * 2 + sand, 0#) 'up
  133. Set skSegment = part.SketchManager.CreateLine(distance, Length + Thickness * 2 + sand, 0#, distance - Thickness, Length + Thickness * 2 + sand, 0#) 'over
  134. Set skSegment = part.SketchManager.CreateLine(distance - Thickness, Length + Thickness * 2 + sand, 0#, distance - Thickness, Length + Thickness, 0#) 'down
  135. Set skSegment = part.SketchManager.CreateLine(distance - Thickness, Length + Thickness, 0#, Thickness, Length + Thickness, 0#) 'over
  136.  
  137. '########################################### LEFT SIDE #########################################################
  138. distance2 = Length - Extra2
  139. Set skSegment = part.SketchManager.CreateLine(Thickness, Length + Thickness, 0#, Thickness, distance2, 0#) 'down
  140. Do While distance2 > 4 * Thickness + Extra2
  141. Set skSegment = part.SketchManager.CreateLine(Thickness, distance2, 0#, -sand, distance2, 0#) 'left
  142. Set skSegment = part.SketchManager.CreateLine(-sand, distance2, 0#, -sand, distance2 - Thickness, 0#) 'down
  143. Set skSegment = part.SketchManager.CreateLine(-sand, distance2 - Thickness, 0#, Thickness, distance2 - Thickness, 0#) 'right
  144. Set skSegment = part.SketchManager.CreateLine(Thickness, distance2 - Thickness, 0#, Thickness, distance2 - Thickness * 2, 0#) 'down
  145. distance2 = distance2 - Thickness * 2
  146. Loop
  147. Set skSegment = part.SketchManager.CreateLine(Thickness, distance2, 0#, -sand, distance2, 0#) 'left
  148. Set skSegment = part.SketchManager.CreateLine(-sand, distance2, 0#, -sand, distance2 - Thickness, 0#) 'down
  149. Set skSegment = part.SketchManager.CreateLine(-sand, distance2 - Thickness, 0#, Thickness, distance2 - Thickness, 0#) 'right
  150. Set skSegment = part.SketchManager.CreateLine(Thickness, distance2 - Thickness, 0#, Thickness, Thickness, 0#) 'down
  151.  
  152. '################################ EXPORT TO DXF ##################################
  153. sModelName = folderPath & fileName & "\" & fileName & ".SLDPRT"
  154. sPathName = folderPath & fileName & "\" & fileName
  155. test = folderPath & fileName & "\" & fileName
  156. sPathName = sPathName + ".dxf"
  157. dataAlignment(0) = 0# 'this part controls geometry to origin relation
  158. dataAlignment(1) = 0#
  159. dataAlignment(2) = 0#
  160. dataAlignment(3) = 0#
  161. dataAlignment(4) = 0#
  162. dataAlignment(5) = 0#
  163. dataAlignment(6) = 0#
  164. dataAlignment(7) = 0#
  165. dataAlignment(8) = 0#
  166. dataAlignment(9) = 0#
  167. dataAlignment(10) = 0#
  168. dataAlignment(11) = 0#
  169. dataAlignment2(0) = 1#
  170. dataAlignment2(1) = 0#
  171. dataAlignment2(2) = 0#
  172. dataAlignment2(3) = 1#
  173. dataAlignment2(4) = 0#
  174. dataAlignment2(5) = 0#
  175. dataAlignment2(6) = 1#
  176. dataAlignment2(7) = 0#
  177. dataAlignment2(8) = 0#
  178. dataAlignment2(9) = 1#
  179. dataAlignment2(10) = 0#
  180. dataAlignment2(11) = 0#
  181. dataViews(0) = "*Top"
  182. varViews = dataViews
  183. sModelName = part.GetPathName
  184. part.ExportToDWG2 sPathName, sModelName, 3, True, dataAlignment, True, True, 0, varViews
  185. test2 = test & " Bottom.dxf"
  186. test = test & ".dxf"
  187. Name test As test2
  188. part.SketchManager.InsertSketch True
  189. '####################### FRONT WIDTH & RIGHT SIDE 1 ######################
  190. fix1 = (Height / 0.0254) / inputThickness
  191. Extra3 = ((Height / 0.0254) - (Int(fix1) * inputThickness)) * 0.5 * 0.0254
  192. If Int(fix1) Mod 2 = 0 Then 'if even # then?'
  193. Extra3 = Extra3 + (0.5 * Thickness) 'even # of thicknesses
  194. End If
  195. boolstatus = part.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
  196. part.SketchManager.InsertSketch True
  197. distance = Thickness + Extra3
  198. Set skSegment = part.SketchManager.CreateLine(Thickness, 0#, 0#, Width + Thickness, 0#, 0#) 'over
  199. Set skSegment = part.SketchManager.CreateLine(Width + Thickness, 0#, 0#, Width + Thickness, distance, 0#) 'up
  200. final = Height - (Thickness + Extra3) + (0.5 * 0.0254)
  201. Do While Height - (2 * Thickness + Extra3) - distance > 0.0000001 And Abs(final - distance + 2 * Thickness) > 0.0001 / 0.0254
  202. Set skSegment = part.SketchManager.CreateLine(Width + Thickness, distance, 0#, Width + Thickness * 2 + sand, distance, 0#) 'out
  203. Set skSegment = part.SketchManager.CreateLine(Width + Thickness * 2 + sand, distance, 0#, Width + Thickness * 2 + sand, distance + Thickness, 0#) 'up
  204. Set skSegment = part.SketchManager.CreateLine(Width + Thickness * 2 + sand, distance + Thickness, 0#, Width + Thickness, distance + Thickness, 0#) 'in
  205. Set skSegment = part.SketchManager.CreateLine(Width + Thickness, distance + Thickness, 0#, Width + Thickness, distance + Thickness * 2, 0#) 'up
  206. distance = distance + Thickness * 2
  207. Loop
  208. Set skSegment = part.SketchManager.CreateLine(Width + Thickness, distance, 0#, Width + Thickness * 2 + sand, distance, 0#) 'out
  209. Set skSegment = part.SketchManager.CreateLine(Width + Thickness * 2 + sand, distance, 0#, Width + Thickness * 2 + sand, distance + Thickness, 0#) 'up
  210. Set skSegment = part.SketchManager.CreateLine(Width + Thickness * 2 + sand, distance + Thickness, 0#, Width + Thickness, distance + Thickness, 0#) 'in
  211. Set skSegment = part.SketchManager.CreateLine(Width + Thickness, distance + Thickness, 0#, Width + Thickness, Height, 0#) 'up
  212. '######################################## BACK WIDTH & LEFT SIDE 1 ######################################
  213. Set skSegment = part.SketchManager.CreateLine(Width + Thickness, Height, 0#, Thickness, Height, 0#) 'in far/ BACK WIDTH
  214. distance = distance + Thickness
  215. Set skSegment = part.SketchManager.CreateLine(Thickness, Height, 0#, Thickness, distance, 0#) 'down
  216. Do While (distance) > 3 * Thickness + Extra3
  217. Set skSegment = part.SketchManager.CreateLine(Thickness, distance, 0#, -sand, distance, 0#) 'out
  218. Set skSegment = part.SketchManager.CreateLine(-sand, distance, 0#, -sand, distance - Thickness, 0#) 'down
  219. Set skSegment = part.SketchManager.CreateLine(-sand, distance - Thickness, 0#, Thickness, distance - Thickness, 0#) 'in
  220. Set skSegment = part.SketchManager.CreateLine(Thickness, distance - Thickness, 0#, Thickness, distance - Thickness * 2, 0#) 'down
  221. distance = distance - Thickness * 2
  222. Loop
  223. Set skSegment = part.SketchManager.CreateLine(Thickness, distance, 0#, -sand, distance, 0#) 'out
  224. Set skSegment = part.SketchManager.CreateLine(-sand, distance, 0#, -sand, distance - Thickness, 0#) 'down
  225. Set skSegment = part.SketchManager.CreateLine(-sand, distance - Thickness, 0#, Thickness, distance - Thickness, 0#) 'in
  226. Set skSegment = part.SketchManager.CreateLine(Thickness, distance - Thickness, 0#, Thickness, 0#, 0#) 'down
  227. '############################################# SQUARES 1 ##################################################
  228. final = Width - (Thickness + Extra)
  229. distance = Thickness * 2 + Extra
  230. Do While Width - (Extra) - distance > 0.0000001 And Abs(final - distance + 2 * Thickness) > 0.0001 / 0.0254
  231. Set skSegment = part.SketchManager.CreateLine(distance, 0.5 * 0.0254, 0#, distance, 0.5 * 0.0254 + Thickness, 0#) 'up
  232. Set skSegment = part.SketchManager.CreateLine(distance, 0.5 * 0.0254 + Thickness, 0#, distance + Thickness, 0.5 * 0.0254 + Thickness, 0#) 'over
  233. Set skSegment = part.SketchManager.CreateLine(distance + Thickness, 0.5 * 0.0254 + Thickness, 0#, distance + Thickness, 0.5 * 0.0254, 0#) 'down
  234. Set skSegment = part.SketchManager.CreateLine(distance + Thickness, 0.5 * 0.0254, 0#, distance, 0.5 * 0.0254, 0#) 'over
  235. distance = distance + Thickness * 2
  236. Loop
  237. '##################################### EXPORT TO DXF #####################################
  238. dataViews(0) = "*Front"
  239. varViews = dataViews
  240. part.ExportToDWG2 sPathName, sModelName, 3, True, dataAlignment2, True, False, 0, varViews
  241. test = folderPath & fileName & "\" & fileName
  242. test2 = test & " Side1.dxf"
  243. test = test & ".dxf"
  244. Name test As test2
  245. part.SketchManager.InsertSketch True
  246.  
  247. '##################### FRONT WIDTH & RIGHT SIDE 2 #######################
  248. fix1 = (Height / 0.0254) / inputThickness
  249. Extra = ((Height / 0.0254) - (Int(fix1) * inputThickness)) * 0.5 * 0.0254
  250. If Int(fix1) Mod 2 = 0 Then 'if even # then?'
  251. Extra = Extra + (0.5 * Thickness) 'even # of thicknesses
  252. End If
  253. boolstatus = part.Extension.SelectByID2("Right Plane", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
  254. part.SketchManager.InsertSketch True
  255. distance = Thickness + Extra
  256. Set skSegment = part.SketchManager.CreateLine(-sand, 0#, 0#, Length + Thickness * 2 + sand, 0#, 0#) 'over
  257. Set skSegment = part.SketchManager.CreateLine(Length + Thickness * 2 + sand, 0#, 0#, Length + Thickness * 2 + sand, distance, 0#) 'up
  258. final = Height - (Thickness + Extra) + (0.5 * 0.0254)
  259. Do While Height - (2 * Thickness + Extra) - distance > 0.0000001 And Abs(final - distance + 2 * Thickness) > 0.0001 / 0.0254
  260. Set skSegment = part.SketchManager.CreateLine(Length + Thickness * 2 + sand, distance, 0#, Length + Thickness, distance, 0#) 'in
  261. Set skSegment = part.SketchManager.CreateLine(Length + Thickness, distance, 0#, Length + Thickness, distance + Thickness, 0#) 'up
  262. Set skSegment = part.SketchManager.CreateLine(Length + Thickness, distance + Thickness, 0#, Length + Thickness * 2 + sand, distance + Thickness, 0#) 'out
  263. Set skSegment = part.SketchManager.CreateLine(Length + Thickness * 2 + sand, distance + Thickness, 0#, Length + Thickness * 2 + sand, distance + Thickness * 2, 0#) 'up
  264. distance = distance + Thickness * 2
  265. Loop
  266. Set skSegment = part.SketchManager.CreateLine(Length + Thickness * 2 + sand, distance, 0#, Length + Thickness, distance, 0#) 'in
  267. Set skSegment = part.SketchManager.CreateLine(Length + Thickness, distance, 0#, Length + Thickness, distance + Thickness, 0#) 'up
  268. Set skSegment = part.SketchManager.CreateLine(Length + Thickness, distance + Thickness, 0#, Length + Thickness * 2 + sand, distance + Thickness, 0#) 'out
  269. Set skSegment = part.SketchManager.CreateLine(Length + Thickness * 2 + sand, distance + Thickness, 0#, Length + Thickness * 2 + sand, Height, 0#) 'up
  270. '############################### BACK WIDTH & LEFT SIDE 2 ###############################################################################################
  271. Set skSegment = part.SketchManager.CreateLine(Length + Thickness * 2 + sand, Height, 0#, -sand, Height, 0#) 'in far/ BACK WIDTH
  272. distance = distance + Thickness
  273. Set skSegment = part.SketchManager.CreateLine(-sand, Height, 0#, -sand, distance, 0#) 'down
  274. Do While (distance) > 3 * Thickness + Extra
  275. Set skSegment = part.SketchManager.CreateLine(-sand, distance, 0#, Thickness, distance, 0#) 'in
  276. Set skSegment = part.SketchManager.CreateLine(Thickness, distance, 0#, Thickness, distance - Thickness, 0#) 'down
  277. Set skSegment = part.SketchManager.CreateLine(Thickness, distance - Thickness, 0#, -sand, distance - Thickness, 0#) 'out
  278. Set skSegment = part.SketchManager.CreateLine(-sand, distance - Thickness, 0#, -sand, distance - Thickness * 2, 0#) 'down
  279. distance = distance - Thickness * 2
  280. Loop
  281. Set skSegment = part.SketchManager.CreateLine(-sand, distance, 0#, Thickness, distance, 0#) 'in
  282. Set skSegment = part.SketchManager.CreateLine(Thickness, distance, 0#, Thickness, distance - Thickness, 0#) 'down
  283. Set skSegment = part.SketchManager.CreateLine(Thickness, distance - Thickness, 0#, -sand, distance - Thickness, 0#) 'out
  284. Set skSegment = part.SketchManager.CreateLine(-sand, distance - Thickness, 0#, -sand, 0#, 0#) 'down
  285. '############################################# SQUARES 2 ##########################################################
  286. distance = Thickness * 2 + Extra2
  287. Do While (Length - (Extra2) - distance) > 0.00000254 And Abs(final2 - distance + 2 * Thickness) > (0.0001 * 0.0254)
  288. Set skSegment = part.SketchManager.CreateLine(distance, 0.5 * 0.0254, 0#, distance, 0.5 * 0.0254 + Thickness, 0#) 'up
  289. Set skSegment = part.SketchManager.CreateLine(distance, 0.5 * 0.0254 + Thickness, 0#, distance + Thickness, 0.5 * 0.0254 + Thickness, 0#) 'over
  290. Set skSegment = part.SketchManager.CreateLine(distance + Thickness, 0.5 * 0.0254 + Thickness, 0#, distance + Thickness, 0.5 * 0.0254, 0#) 'down
  291. Set skSegment = part.SketchManager.CreateLine(distance + Thickness, 0.5 * 0.0254, 0#, distance, 0.5 * 0.0254, 0#) 'over
  292. distance = distance + Thickness * 2
  293. Loop
  294.  
  295. '############################################# HANDLE #######################################################################################################
  296. If addHandle = True And Length >= 5 * 0.0254 And inputHeight >= 3 * 0.0254 Then
  297. Set skSegment = part.SketchManager.CreateArc(0.5 * Length + Thickness, Height - (1.31 * 0.0254) + 0.0762, 0#, 0.5 * Length + Thickness + 0.041651, Height - (1.31 * 0.0254) - 0.007103, 0#, 0.5 * Length + Thickness - 0.041651, Height - (1.31 * 0.0254) - 0.007103, 0#, -1) 'lower arc
  298. part.ClearSelection2 True
  299. Set skSegment = part.SketchManager.CreateArc(0.5 * Length + Thickness - 0.0381, Height - (1.31 * 0.0254), 0#, 0.5 * Length + Thickness - 0.041651, Height - (1.31 * 0.0254) - 0.007103, 0#, 0.5 * Length + Thickness - 0.034549, Height - (1.31 * 0.0254) + 0.007103, 0#, -1) 'left arc
  300. part.ClearSelection2 True
  301. Set skSegment = part.SketchManager.CreateArc(0.5 * Length + Thickness, Height - (1.31 * 0.0254) + 0.0762, 0#, 0.5 * Length + Thickness - 0.034549, Height - (1.31 * 0.0254) + 0.007103, 0#, 0.5 * Length + Thickness + 0.034549, Height - (1.31 * 0.0254) + 0.007103, 0#, 1) 'upper arc
  302. part.ClearSelection2 True
  303. Set skSegment = part.SketchManager.CreateArc(0.5 * Length + Thickness + 0.0381, Height - (1.31 * 0.0254), 0#, 0.5 * Length + Thickness + 0.034549, Height - (1.31 * 0.0254) + 0.007103, 0#, 0.5 * Length + Thickness + 0.041651, Height - (1.31 * 0.0254) - 0.007103, 0#, -1) 'right arc
  304. Else
  305. End If
  306.  
  307. '######################################## EXPORT TO DXF ##################################
  308. dataViews(0) = "*Right"
  309. varViews = dataViews
  310. part.ExportToDWG2 sPathName, sModelName, 3, True, dataAlignment2, True, False, 0, varViews
  311. test = folderPath & fileName & "\" & fileName
  312. test2 = test & " Side2.dxf"
  313. test = test & ".dxf"
  314. Name test As test2
  315. longstatus = part.SaveAs3(folderPath & fileName & "\" & fileName & ".SLDPRT", 0, 2)
  316. part.SketchManager.InsertSketch True
  317. instance.AddToDB = False
  318. part.ViewZoomtofit2
  319. End Sub
  320.  

      I set the Sanded measurement to something like .02 inches. What that does is adds .02 inches of material to all 'teeth' or 'fingers' so after assembly you can sand off the discoloration from your laser.

UserForm1 Code:


  1.  
  2. Private Sub CommandButton1_Click()
  3. Dim boxWidth As Double
  4. Dim boxHeight As Double
  5. Dim boxLength As Double
  6. Dim woodThickness As Double
  7. Dim sand As Double
  8. boxWidth = textBox2.Text
  9. boxHeight = textBox3.Text
  10. boxLength = Length.Text
  11. woodThickness = Thickness.Text
  12. sand = Sanded.Text
  13. If CheckBox1.Value = False Then
  14. addHandle = False
  15. Else
  16. addHandle = True
  17. End If
  18. Call createBox(boxLength, boxWidth, boxHeight, woodThickness, sand)
  19. End Sub
  20.  

Notes:


Because of snapping, many lines would not draw properly while this macro ran. This is no longer a problem. The solution to this issue is found on or around line 74 of the main code:

part.SketchManager.AddToDB = True

This line of code some how bypasses the snapping portion of the drawing process.

Handles will only be drawn if the height of your box is over 3 inches and the shorter of the two sides is longer than 5 inches. This is accomplished with line 302 of the main code.

In order to cut the dxf files with a laser I had to adjust the tool path inside of the laser operating software to account for the kerf (thickness) of the laser beam. This step could be avoided if the macro accounted for the laser beam's kerf.