Hello all,
what do we use to get distance from a face to a workoint in VBA??
Do we use Measuretools or Distanceto or is there anything else??
I wolud like get horizontal distance from a face to workpoint..
Please find attachment.
Look for forward for solution.
Solved! Go to Solution.
Solved by ADNpati. Go to Solution.
Hi,
One thing you could do is intersect the face's plane with the plane along which you want to measure, then measure the distance from the point to the intersection line:
Sub test() Dim ad As AssemblyDocument Set ad = ThisApplication.ActiveDocument Dim tg As TransientGeometry Set tg = ThisApplication.TransientGeometry Dim mt As MeasureTools Set mt = ThisApplication.MeasureTools ' Plane of face Dim p As Plane Set p = ad.SelectSet(1).Geometry ' Point from which we want to measure Dim pt As Point Set pt = ad.SelectSet(2).Point ' Plane inside which we want to measure ' Assume the plane's normal is Z Dim ptp As Plane Set ptp = tg.CreatePlane(pt, tg.CreateVector(0, 0, 1)) Dim l As Line Set l = p.IntersectWithPlane(ptp) Dim d As Double d = mt.GetMinimumDistance(pt, l) End Sub
I hope this helps.
Hello Adam,
I found a way using Proxies.
Private Sub FacePoint()
Dim oDoc As AssemblyDocument
Set oDoc = ThisApplication.ActiveDocument
Dim oAssyDef As AssemblyComponentDefinition
Set oAssyDef = oDoc.ComponentDefinition
Dim oOcc As ComponentOccurrence
Set oOcc = oAssyDef.occurrences.Item(1) '1) get the reference to the workpoint "2" (not origin point) in the component "1"
Dim oDef As AssemblyComponentDefinition
Set oDef = oOcc.Definition
Dim oWP As WorkPoint
Set oWP = oDef.WorkPoints.Item(2) 'create work point proxy object
Dim oWPproxy As WorkPointProxy
Call oOcc.CreateGeometryProxy(oWP, oWPproxy) '2) get the reference to the selected face
Dim oSSet As SelectSet
Set oSSet = oDoc.SelectSet
If oSSet.Count = 0 Then
MsgBox "Select some face"
Exit Sub
End If
Dim oObj As Object
Set oObj = oSSet.Item(1)
If Not (TypeOf oObj Is FaceProxy) Then
MsgBox "Select some face"
Exit Sub
End If
Dim oFaceProxy As FaceProxy
Set oFaceProxy = oObj '3) Measurements Dim oMeasureTools As MeasureTools
Set oMeasureTools = ThisApplication.MeasureTools
Dim D As Double ' distance (cm)
D = oMeasureTools.GetMinimumDistance(oFaceProxy, oWPproxy)
MsgBox ("D, cm = " & FormatNumber(D, 3))
End Sub 'FacePoint
Using Proxies we can get location of any feature or part.
Thanks for your reply.
AD
Accept as Solution and "Kudos" if finds useful.
Hi Adam,
I have a problem when use the plane on the part in the sub-assembly.
I change only this line for test :
Set p = ad.ComponentDefinition.Occurrences.Item(15).Definition.Occurrences.Item(2).Definition.WorkPlanes.Item("YZ Plane").Plane
And the it use the "YZ Plane" from Assembly Master like reference. And not part on the sub-assembly.
Any ideia?
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Hi Cristiano,
You go into the "Definition" of the documents so the results will be in context of the document itself and not the top assembly. The values of the "YZ Plane" of the part in context of the part is exactly the same as "YZ Plane" of the top assembly in context of the top assembly. What I think you are looking for is the values of the part's "YZ Plane" in context of the top assembly.
Please have a look at the following article. I hope it will clarify things: http://adndevblog.typepad.com/manufacturing/2013/07/occurrences-contexts-definitions-proxies.html
Cheers,
Hi Adam,
I set each item now, and the result is the same. Atthaced sample example.
If you use the SelectSet, ok.. fine. But if you use the "Plane", the results is wrong.
See:
Sub mytest() Dim ad As AssemblyDocument Set ad = ThisApplication.ActiveDocument Dim addef As AssemblyComponentDefinition Set addef = ad.ComponentDefinition Dim oCC As ComponentOccurrence Set oCC = addef.Occurrences(1).SubOccurrences.Item(1) Dim part As PartDocument Set part = oCC.Definition.Document Dim partDef As PartComponentDefinition Set partDef = part.ComponentDefinition Dim tg As TransientGeometry Set tg = ThisApplication.TransientGeometry Dim mt As MeasureTools Set mt = ThisApplication.MeasureTools ' Plane of face Dim p As Plane Set p = partDef.WorkPlanes.Item("Plane").Plane 'Set p = ad.SelectSet(2).Plane ' Point from which we want to measure Dim pt As Point Set pt = ad.SelectSet(1).Point ' Plane inside which we want to measure ' Assume the plane's normal is Z Dim ptp As Plane Set ptp = tg.CreatePlane(pt, tg.CreateVector(0, 0, 1)) Dim l As Line Set l = p.IntersectWithPlane(ptp) Dim d As Double d = mt.GetMinimumDistance(pt, l) End Sub
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.