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-
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...
See you on Monday.
with best regards,
Mahendra
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)
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...
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...
Thanks for your reply, now it is working OK with workpoint proxy in assembly for getting correct distance.
warm regards,
Mahendra Patel
Pune India