Hej,
I try to get coordinates of my intersection. User select vertical and horizontal edge and macro create intersection and read coordinates of that point.
Unfortunately line: TheMeasurable.GetPoint aCoordinates - cause an error. Treacing my code, I found that array aCoordinates is empty.
If I use already created referenced point, it works fine.
Code:
Sub MyIntersectionCoordinates()
Dim MyPartDocument As PartDocument
Dim MyPart As Part
Dim MyRef As Reference
Dim MyPad As Pad
Dim MyHEdgeReference As Reference, MyVEdgeReference As Reference
Dim MyHEdgeRefStatus As String, MyVEdgeRefeStatus As String, ReferenceName As String, FullName As String
Dim MySelection As Selection
Dim MySelectionObj As Object
Dim InputObjectTypeEdge(0)
Dim MyHybridShapeFactory As HybridShapeFactory
Dim MyHybridBody As HybridBody
Dim MyInstersection As HybridShapeIntersection
Dim TheSPAWorkbench As SPAWorkbench
Dim MyPointReference As Reference
Dim TheMeasurable
Dim aCoordinates(2)
InputObjectTypeEdge(0) = "Edge"
Set MyPartDocument = CATIA.ActiveDocument
Set MyPart = MyPartDocument.Part
Set MyPad = MyPart.Bodies.Item("PartBody").Shapes.Item("Pad.1")
Set MyHybridShapeFactory = MyPart.HybridShapeFactory
Set MySelection = MyPartDocument.Selection
Set MySelectionObj = MySelection
Set MyHybridShapeFactory = MyPart.HybridShapeFactory
Set MyHybridBody = MyPart.HybridBodies.Add()
MyHybridBody.Name = "Intersection_point"
MySelectionObj.Clear
'select hirizontal edge
MyHEdgeRefStatus = MySelectionObj.SelectElement2(InputObjectTypeEdge, "Select hirizontal edge", False)
If MyHEdgeRefStatus <> "Normal" Then Exit Sub
ReferenceName = MySelectionObj.Item(1).Value.DisplayName
FullName = CreateStringFromSelection(ReferenceName)
Set MyHEdgeReference = MyPart.CreateReferenceFromBRepName(FullName, MyPad)
MySelectionObj.Clear
'select vertical edge
MyVEdgeRefeStatus = MySelectionObj.SelectElement2(InputObjectTypeEdge, "Select vertical edge", False)
If MyVEdgeRefeStatus <> "Normal" Then Exit Sub
ReferenceName = MySelectionObj.Item(1).Value.DisplayName
FullName = CreateStringFromSelection(ReferenceName)
Set MyVEdgeReference = MyPart.CreateReferenceFromBRepName(FullName, MyPad)
MySelectionObj.Clear
'create Intersection from selected edges
Set MyInstersection = MyHybridShapeFactory.AddNewIntersection(MyVEdgeReference, MyHEdgeReference)
MyInstersection.PointType = 1
MyHybridBody.AppendHybridShape MyInstersection
MyInstersection.Name = "Reference point"
'------------------------------- read Intersection coordinates ---------------------------------------------------
Set TheSPAWorkbench = CATIA.ActiveDocument.GetWorkbench("SPAWorkbench")
Set MyPointReference = MyPart.CreateReferenceFromObject(MyInstersection)
Set TheMeasurable = TheSPAWorkbench.GetMeasurable(MyPointReference)
TheMeasurable.GetPoint aCoordinates
'----------------------------------------------------------------------------------------------------------------------
MyPart.Update
End Sub