Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Intescection

Status
Not open for further replies.

Santa123

Mechanical
Oct 2, 2006
80
PL

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
 
Replies continue below

Recommended for you

Thank you Little Cthulhu, I will try. Could you explain me why is that.

Best Regards
Santa
 
Because all features created with HybridShapeFactory are created without calculating their actual geometry to save processor time.
In your scenario you need that geometry to perform measurement, so you call Compute().
 
Hello,

I am trying to improve my macro adding sketch on surface selected by user. Is there any way to set HDirection of my Sketch to be parallel to selected edge? or do I got only SetAbsoluteAxisData? Could you give me some tips.

Best Regards
Santa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top