Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to measure distance between two workpoints

152 views
Skip to first unread message

mahen

unread,
Oct 28, 2004, 11:26:55 PM10/28/04
to
Hi Dear,
Thanks for opening this topic.

I am thinking to write a macro to get the distance between two work points in assembly document.
First work point is located on "part1.ipt" & second work point is located on "part2.ipt". both of these parts are apperaing in assembly "ring.iam"

Do you have any idea, how to write a macro to get distance between these two points please?

regards,

Mahendra Patel
SKF,Pune-INDIA

Sanjay Ramaswamy (Autodesk)

unread,
Oct 29, 2004, 2:46:40 PM10/29/04
to
Select the 2 workpoints in the assembly and run the following macro. The
basic idea is to get the proxies for the workpoints to measure the distance
between them. In this case, I get the proxies from the selection. You can
also use ComponentOccurrence.CreateGeometryProxy to get the proxies.

Sanjay-

Public Sub GetDistance()

Dim oSS As SelectSet
Set oSS = ThisApplication.ActiveDocument.SelectSet

Dim oWorkPoint1 As WorkPointProxy
Dim oWorkPoint2 As WorkPointProxy

Set oWorkPoint1 = oSS.Item(1)
Set oWorkPoint2 = oSS.Item(2)

Dim distance As Double
distance = oWorkPoint1.Point.DistanceTo(oWorkPoint2.Point)

MsgBox ("Distance = " & distance)

End Sub

"mahen" <nos...@address.withheld> wrote in message
news:15425992.109902044...@jiveforum2.autodesk.com...

mahen

unread,
Oct 30, 2004, 8:50:35 AM10/30/04
to
Dear Sanjay,
Hi, nice to see your reply.
Just now I open your reply from my residence, I will go for the suugested macro on coming Monday at my work.The only possibility where I would get stucked is the call for workpoints which are defined in different part files. I will try to locate them through occurances.item.
Till then bye & thanks for your great & timely support.

See you on Monday.

with best regards,

Mahendra

mahen

unread,
Nov 1, 2004, 3:19:34 AM11/1/04
to
Dear Sanjay,

I tried with the macro supplied by you with following code, but the distance I'm getting is 1.6406 instead of actual distance 2.7501. In this macro , I have defined two workpoings in VBA code itself & checking distance between them on XY plane.

If I select the workpoints in iam browser & then run the code provided by you ( i.e. with selection set) it gives me a correct distance i.e. 2.7501.

Can you please highlight , where I'm going wrong?

Public Sub GetDistance()

Dim oCompDef As AssemblyComponentDefinition
Set oCompDef = ThisApplication.ActiveDocument.ComponentDefinition

Dim oOcc1 As ComponentOccurrence
Set oOcc1 = oCompDef.Occurrences.Item(1)
Dim oPartDef1 As PartComponentDefinition
Set oPartDef1 = oOcc1.Definition
Dim oRingCenter As WorkPoint
Set oRingCenter = oPartDef1.WorkPoints.Item("Work Point1")

Dim oOcc2 As ComponentOccurrence
Set oOcc2 = oCompDef.Occurrences.Item(2)
Dim oPartDef2 As PartComponentDefinition
Set oPartDef2 = oOcc2.Definition
Dim oShoeCenter As WorkPoint
Set oShoeCenter = oPartDef2.WorkPoints.Item("My WorkPoint")

Dim distance As Double
distance = oRingCenter.Point.DistanceTo(oShoeCenter.Point)

MsgBox ("Distance = " & distance)


End Sub


Looking for your sooner reply.

with best regards,

Mahendra Patel,
SKF, Pune


Public Sub GetDistance()

Dim oCompDef As AssemblyComponentDefinition
Set oCompDef = ThisApplication.ActiveDocument.ComponentDefinition

Dim oOcc1 As ComponentOccurrence
Set oOcc1 = oCompDef.Occurrences.Item(1)
Dim oPartDef1 As PartComponentDefinition
Set oPartDef1 = oOcc1.Definition
Dim oRingCenter As WorkPoint
Set oRingCenter = oPartDef1.WorkPoints.Item("Work Point1")

Dim oOcc2 As ComponentOccurrence
Set oOcc2 = oCompDef.Occurrences.Item(2)
Dim oPartDef2 As PartComponentDefinition
Set oPartDef2 = oOcc2.Definition
Dim oShoeCenter As WorkPoint
Set oShoeCenter = oPartDef2.WorkPoints.Item("My WorkPoint")

Dim distance As Double
distance = oRingCenter.Point.DistanceTo(oShoeCenter.Point)

Bob S.

unread,
Nov 2, 2004, 11:36:15 AM11/2/04
to
So, let's see here: 1.6406cm = 2.7501 units?

1.6406cm = 0.6459in
1.6406cm = 16.406mm

Something ain't right here!

"Sanjay Ramaswamy (Autodesk)" <discussio...@autodesk.com> wrote in message news:4187b154$1_2@newsprd01...
> The distance returned thru the API is in database units (centimeters).
>
> Sanjay-


>
> "mahen" <nos...@address.withheld> wrote in message

> news:5744155.109929720...@jiveforum2.autodesk.com...

Sanjay Ramaswamy (Autodesk)

unread,
Nov 2, 2004, 1:24:33 PM11/2/04
to
Sorry, I didn't read the full post and the sample code. Disregard my
previous reply (thanks, Bob).

The problem with the code is that it is attempting to find the distance
between the 2 workpoint objects in part space (which is incorrect). The
workpoints need to be converted to proxies (their representations in
assembly space) before measuring the distance. Here is the modified code (I
have to confess I didn't run this, but I beleive this should work)...

Public Sub GetDistance()

Dim oCompDef As AssemblyComponentDefinition
Set oCompDef = ThisApplication.ActiveDocument.ComponentDefinition

Dim oOcc1 As ComponentOccurrence
Set oOcc1 = oCompDef.Occurrences.Item(1)
Dim oPartDef1 As PartComponentDefinition
Set oPartDef1 = oOcc1.Definition
Dim oRingCenter As WorkPoint
Set oRingCenter = oPartDef1.WorkPoints.Item("Work Point1")

Dim oOcc2 As ComponentOccurrence
Set oOcc2 = oCompDef.Occurrences.Item(2)
Dim oPartDef2 As PartComponentDefinition
Set oPartDef2 = oOcc2.Definition
Dim oShoeCenter As WorkPoint
Set oShoeCenter = oPartDef2.WorkPoints.Item("My WorkPoint")

Dim oRingCenterProxy as WorkPointProxy
Call oOcc1.CreateGeometryProxy(oRingCenter, oRingCenterProxy)

Dim oShoeCenterProxy as WorkPointProxy
Call oOcc2.CreateGeometryProxy(oShoeCenter, oShoeCenterProxy)

Dim distance As Double
distance = oRingCenterProxy.Point.DistanceTo(oShoeCenterProxy.Point)

MsgBox ("Distance = " & distance)


End Sub

Sanjay-

"Bob S." <rschader_NOSPAM_at_NOSPAM_sbcglobal.net> wrote in message
news:4187b780$1_3@newsprd01...

mahen

unread,
Nov 3, 2004, 1:16:46 AM11/3/04
to
Dear Sanjay,

Thanks for your reply, now it is working OK with workpoint proxy in assembly for getting correct distance.

warm regards,

Mahendra Patel
Pune India

0 new messages