Inventor Customization

Reply
Distinguished Contributor
ADNpati
Posts: 125
Registered: ‎07-01-2012
Message 1 of 7 (250 Views)
Accepted Solution

Face of a Part to Workpoint in another part

250 Views, 6 Replies
11-07-2012 04:24 PM

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 -

-------------------------------------------------------------------------------------
ADN Support Specialist
adam.nagy
Posts: 521
Registered: ‎03-26-2007
Message 2 of 7 (226 Views)

Re: Face of a Part to Workpoint in another part

11-20-2012 07:20 AM 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
Developer Technical Services
Autodesk Developer Network
Distinguished Contributor
ADNpati
Posts: 125
Registered: ‎07-01-2012
Message 3 of 7 (220 Views)

Re: Face of a Part to Workpoint in another part

11-20-2012 02:05 PM 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 -

-------------------------------------------------------------------------------------
*Expert Elite*
Crstiano
Posts: 104
Registered: ‎03-11-2012
Message 4 of 7 (117 Views)

Re: Face of a Part to Workpoint in another part

10-18-2013 11:47 AM 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

Colaborador MFG Comunidade Autodesk Brasil
ConsultCAD - www.facebook.com/ConsultCAD
---
Por favor, marque Accept as Solution se a sua pergunta foi respondida. Kudos se gostou. ⇘
ADN Support Specialist
adam.nagy
Posts: 521
Registered: ‎03-26-2007
Message 5 of 7 (114 Views)

Re: Face of a Part to Workpoint in another part

10-18-2013 12:19 PM 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
Developer Technical Services
Autodesk Developer Network
*Expert Elite*
Crstiano
Posts: 104
Registered: ‎03-11-2012
Message 6 of 7 (109 Views)

Re: Face of a Part to Workpoint in another part

10-18-2013 04:40 PM 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

Colaborador MFG Comunidade Autodesk Brasil
ConsultCAD - www.facebook.com/ConsultCAD
---
Por favor, marque Accept as Solution se a sua pergunta foi respondida. Kudos se gostou. ⇘
*Expert Elite*
Crstiano
Posts: 104
Registered: ‎03-11-2012
Message 7 of 7 (98 Views)

Re: Face of a Part to Workpoint in another part

10-19-2013 11:27 AM 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

Colaborador MFG Comunidade Autodesk Brasil
ConsultCAD - www.facebook.com/ConsultCAD
---
Por favor, marque Accept as Solution se a sua pergunta foi respondida. Kudos se gostou. ⇘

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community


Inventor Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Autodesk Inventor helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Inventor

Twitter

Facebook

Blogs

Pinterest

Youtube