-
Re: vba macro to get thickness of a part
Peter Brinkhuis May 8, 2017 5:56 AM (in response to Nadav Gover)Can you show us an example picture? How did you get the file, is it an imported file?
-
Re: vba macro to get thickness of a part
Nadav Gover May 8, 2017 12:37 PM (in response to Peter Brinkhuis)
-
-
Re: vba macro to get thickness of a part
Christian Chu May 8, 2017 12:48 PM (in response to Nadav Gover)Not sure what you want to achieve here, how's about measure command ?
-
Re: vba macro to get thickness of a part
Nadav Gover May 8, 2017 12:54 PM (in response to Christian Chu)Sorry for the misunderstanding.
The thing I want to achieve is to know how many thicknesses I have in a part and what are the thicknesses themselves.
If this could be done in a drawing it can be a bonus if I can know what is the tolerance of each thickness.
This must be duone using vba.
Thank you
-
Re: vba macro to get thickness of a part
Christian Chu May 8, 2017 12:59 PM (in response to Nadav Gover)-
Re: vba macro to get thickness of a part
Nadav Gover May 8, 2017 1:09 PM (in response to Christian Chu)I understand what you are saying, good point...
Let's say than that I need to check if faces are parallel and if they are than to check the thickness.
I don't have a code yet, but i come across a problem when I just iterate naively through all faces to check if they are parallel
because obviously if there is a box so only two opposite face are parallel, but I am interested only in the thickness
(in a box it is the extrude base height, in different shapes a thickness might be also created from a cut, for example).
Thank you
-
Re: vba macro to get thickness of a part
Christian Chu May 8, 2017 1:16 PM (in response to Nadav Gover)Try this
-
-
-
-
-
Re: vba macro to get thickness of a part
Nick Gvk May 9, 2017 4:02 AM (in response to Nadav Gover)how about using the model items button
before
after
the thickness of a part is a a strange thing to determain
the thickness wil be depending on wich plane the part has been drawn
and also on how u are planning to use the part and how to make the part as the end product ( sheet , round bar, square bar , forging , casting )
in this case its obvius as i inserterted the isometric view of it
mayby for sheet metal there is an option to display the thickness
or in structure it can be displayed in the cutting list but thats only for the stuff u pre define
-
Re: vba macro to get thickness of a part
Ivana Kolin May 10, 2017 9:19 AM (in response to Nadav Gover)open part doc and select any face. Then try this macro:
Option Explicit Sub main() Dim swApp As SldWorks.SldWorks Dim swModel As SldWorks.ModelDoc2 Dim swPart As SldWorks.PartDoc Dim swSelMgr As SldWorks.SelectionMgr Dim swFace As SldWorks.Face2 Dim arrBody As Variant Dim Body As Variant Dim arrFaces As Variant Dim face As Variant Dim swFace2 As SldWorks.Face2 Dim swBody As SldWorks.Body2 Dim vPoint1 As Variant Dim vPoint2 As Variant Dim nDist As Double Dim v As MathVector Dim v2 As MathVector Dim swMath As SldWorks.MathUtility Dim swMeasure As SldWorks.measure Set swApp = Application.SldWorks Set swMath = swApp.GetMathUtility Set swModel = swApp.ActiveDoc Set swPart = swModel If swPart Is Nothing Then Exit Sub Set swSelMgr = swModel.SelectionManager If swSelMgr.GetSelectedObjectCount2(-1) <> 1 Then Exit Sub If swSelMgr.GetSelectedObjectType3(1, -1) <> swSelFACES Then Exit Sub Set swFace = swSelMgr.GetSelectedObject6(1, -1) Set v = swMath.CreateVector(swFace.Normal) Set swMeasure = swModel.Extension.CreateMeasure arrBody = swPart.GetBodies2(swSolidBody, True) If IsEmpty(arrBody) Then Exit Sub For Each Body In arrBody Set swBody = Body arrFaces = swBody.GetFaces For Each face In arrFaces Set swFace2 = face Set v2 = swMath.CreateVector(swFace2.Normal) If Abs(v.Dot(v2)) = 1 And swApp.IsSame(swFace2, swFace) = swObjectNotSame Then 'swFace2.Select4 False, Nothing nDist = swModel.ClosestDistance(swFace, swFace2, vPoint1, vPoint2) * 1000 Debug.Print nDist End If Next Next End Sub
-
Re: vba macro to get thickness of a part
Nadav Gover May 18, 2017 6:25 PM (in response to Ivana Kolin)Wow! This is exactly what I need. Is there a way to do this without selecting a face?
Of course you need a reference face, but maybe there is a way to getFirstFace (assuming this is the face needed)?
Thank you
-
-
Re: vba macro to get thickness of a part
Amen Allah Jlili May 20, 2017 3:21 PM (in response to Nadav Gover)Interesting question!
I think the closest definition to a thickness in 3D is the normal distance between the two equal, largest, planar faces of a part. Once you identify these two large faces. You can pretty much get other thickness by comparing one of these faces and the other faces (much like Ivana Kolin did).
-
Re: vba macro to get thickness of a part
Josh Brady May 20, 2017 8:52 PM (in response to Amen Allah Jlili)Not quite, Amen... OP already mentioned blind holes/cuts. With a large enough blind pocket, the "thickness" could be relative to a pretty small face. Our brains are pretty amazing at analyzing 3D geometry in ways that are much harder to figure out how to program...
-
Re: vba macro to get thickness of a part
Amen Allah Jlili May 20, 2017 9:14 PM (in response to Josh Brady)Nice catch Josh Brady !
Perhaps if all possibilities (by pairs of outside faces) are considered, the smallest thickness could be the ultimate answer. This would only workround blind holes. Don't you think?
-
Re: vba macro to get thickness of a part
Josh Brady May 21, 2017 12:16 AM (in response to Amen Allah Jlili)I think in order to generate any useful response we would need to understand the end goal. Of course, a macro could easily be written to report all the distances between every pair of parallel faces whose normal vectors point opposite directions. That part is trivial. You could also easily find the maximum distance between pairs of parallel faces along every arbitrary axis along which pairs of faces exist. Then pick the smallest maximum distance and say that it's the thickness. But it all depends on what needs to be done next with that data.
-
-
-