Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Face of a Part to Workpoint in another part

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
ADNpati
741 Views, 6 Replies

Face of a Part to Workpoint in another part

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.

Mechanical Engineer
Inventor Applications Engineer

--------------------------------------------------------------------------------------

If my solution seems to remedy your problem, please press the Accept Solution button, Some KUDOS -

-------------------------------------------------------------------------------------
6 REPLIES 6
Message 2 of 7
adam.nagy
in reply to: ADNpati

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.



Adam Nagy
Autodesk Platform Services
Message 3 of 7
ADNpati
in reply to: adam.nagy

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.

Mechanical Engineer
Inventor Applications Engineer

--------------------------------------------------------------------------------------

If my solution seems to remedy your problem, please press the Accept Solution button, Some KUDOS -

-------------------------------------------------------------------------------------
Message 4 of 7
Crstiano
in reply to: adam.nagy

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?

Cristiano Oliveira
Developer Addins | Consultant CAD/PLM | CAD Manager
https://www.ConsultCAD.com/


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.

Message 5 of 7
adam.nagy
in reply to: Crstiano

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,



Adam Nagy
Autodesk Platform Services
Message 6 of 7
Crstiano
in reply to: adam.nagy

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

 

Cristiano Oliveira
Developer Addins | Consultant CAD/PLM | CAD Manager
https://www.ConsultCAD.com/


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.

Message 7 of 7
Crstiano
in reply to: Crstiano

I found the solution. Thanks for all.

Sub mytest2()
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 oWP As WorkPlane
Set oWP = oCC.Definition.WorkPlanes.Item(1)
Dim oWPxz As WorkPlaneProxy
Call oCC.CreateGeometryProxy(oWP, oWPxz)

Dim pt As Point
Set pt = ad.SelectSet(1).Point

Dim d As Double
d = oWPxz.Plane.DistanceTo(pt)
End Sub
Cristiano Oliveira
Developer Addins | Consultant CAD/PLM | CAD Manager
https://www.ConsultCAD.com/


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.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report