Macro measure distance between two points : wrong value
Macro measure distance between two points : wrong value
(OP)
Hi,
I've problems with my code. I want to measure with a macro the distance between two points. So I use GetMinimumDistance, and the function return me the value "0".
I don't understand because my 2 points aren't coincident at all.
This is my code:
Sub DistancePoint()
Dim TheSPAWorkbench As Workbench
Dim reference1 As Reference
Dim reference2 As Reference
Dim TheMeasurable As Measurable
Dim MinimumDistance As Double
Set TheSPAWorkbench = CATIA.ActiveDocument.GetWorkbench("SPAWorkbench")
Set partDocument1 = CATIA.ActiveDocument
Set selection1 = partDocument1.Selection
Set visPropertySet1 = selection1.VisProperties
Set part1 = partDocument1.Part
Set hybridBodies1 = part1.HybridBodies
Set hybridBody1 = hybridBodies1.Item(1)
Set hybridShapes1 = hybridBody1.HybridShapes
Set hybridShapePointCoord1 = hybridShapes1.Item(6)
Set hybridShapes1 = hybridShapePointCoord1.Parent
Set hybridShapePointCoord2 = hybridShapes1.Item(7)
Set hybridShapes2 = hybridShapePointCoord2.Parent
Set reference1 = part1.CreateReferenceFromObject(hybridShapes1)
Set reference2 = part1.CreateReferenceFromObject(hybridShapes2)
Set TheMeasurable = TheSPAWorkbench.GetMeasurable(reference1)
MinimumDistance = TheMeasurable.GetMinimumDistance(reference2)
MsgBox (MinimumDistance)
End Sub
Thank you. Bastien
I've problems with my code. I want to measure with a macro the distance between two points. So I use GetMinimumDistance, and the function return me the value "0".
I don't understand because my 2 points aren't coincident at all.
This is my code:
Sub DistancePoint()
Dim TheSPAWorkbench As Workbench
Dim reference1 As Reference
Dim reference2 As Reference
Dim TheMeasurable As Measurable
Dim MinimumDistance As Double
Set TheSPAWorkbench = CATIA.ActiveDocument.GetWorkbench("SPAWorkbench")
Set partDocument1 = CATIA.ActiveDocument
Set selection1 = partDocument1.Selection
Set visPropertySet1 = selection1.VisProperties
Set part1 = partDocument1.Part
Set hybridBodies1 = part1.HybridBodies
Set hybridBody1 = hybridBodies1.Item(1)
Set hybridShapes1 = hybridBody1.HybridShapes
Set hybridShapePointCoord1 = hybridShapes1.Item(6)
Set hybridShapes1 = hybridShapePointCoord1.Parent
Set hybridShapePointCoord2 = hybridShapes1.Item(7)
Set hybridShapes2 = hybridShapePointCoord2.Parent
Set reference1 = part1.CreateReferenceFromObject(hybridShapes1)
Set reference2 = part1.CreateReferenceFromObject(hybridShapes2)
Set TheMeasurable = TheSPAWorkbench.GetMeasurable(reference1)
MinimumDistance = TheMeasurable.GetMinimumDistance(reference2)
MsgBox (MinimumDistance)
End Sub
Thank you. Bastien





RE: Macro measure distance between two points : wrong value
I would try to point the user to pick first those two points (with selection filter) in order to use reference from their names and get minimum distance. Using item number is not always the best idea.
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...