Welcome to 3DCADForums

Join our CAD community forums where over 25,000 users interact to solve day to day problems and share ideas. We encourage you to visit, invite you to participate and look forward to your input and opinions. Acrobat 3D, AutoCAD, Catia, Inventor, IronCAD, Creo, Pro/ENGINEER, Solid Edge, SolidWorks, and others.

Register Log in

MACRO to get the coordinates of a reference Axis

Dael

New member
Hi,

I was wondering if anyone knows of a way to get the coordinates of the reference axis that is used by a coincidence constraint in Assembly design.
I am after the location where the axis intersects the plane of the part.

I have been able to get the direction of the axis using

Set oRef1 = Constraint1.getconstraintelement(1)
Set constraintaxis1 = TheSPAWorkbench.GetMeasurable(oRef1)
Dim aAxisVector(2)
constraintaxis1.GetDirection aAxisVector

And I can get the center point of a hole that an axis runs through, using.

Dim SelectionA As Selection
Set SelectionA = productDocument1.Selection
SelectionA.Search "CATPrtSearch.Hole,all"

Dim theHole As Hole
Set theHole = SelectionA.Item(i).Value
Dim vHole As Variant
Set vHole = theHole
Dim origin(2)
vHole.GetOrigin origin

The origin of the hole printed will correspond to the Axis vector in the case where there is only one hole per part and one coincidence. As soon as further complexity is introduced using this method becomes useless.

Is there a way to get the origin of the axis that has been derived from the constraint. or even link the hole to the constraint so the information is paired?

Thanks for your time.

Dael
 

MrCATIA

Super Moderator
Interactively, the Measure tool will give the coordinates of the axis relative to the assembly. The Measure Between tool will give the coordinates between two axis systems.

Maybe you could record a macro of running both tools, and see what commands are called?
 

Dael

New member
I did have a look into doing this but for some reason the Macro recorder will not record anything happening in the measure tool, be it distance or inertia,mass CoG.

I have found a work around that selects the hole that is reference by the constraint element by opening each part and then using the search function to select the hole using its name. I am still having trouble with the coordinates. in the initial case they appear to be fine but when I move the part using the manipulate tool so that it is in a different location with reference to the absolute axis they coordinates returned are still the same.

Do you know how I can get the coordinates of the hole with reference to something else in the assembly rather than just the part it is in?

A sample of the code is below, Is it possible that because the search tool is using PartDocument1 that it is taking the part origin as a reference and not the Assembly origin?

Thanks.

This will work for an assembly that has coincidence constraints made using holes. ( I have been using a simple 2-bar linkage)

Code:
Sub CATMain()

Set productDocument1 = CATIA.ActiveDocument                     ' top, active product
Dim product1 As Product
Set product1 = productDocument1.Product

Dim constraints1 As Constraints
Set constraints1 = product1.Connections("CATIAConstraints")     ' all the contraints in  the product document.
Dim constraint1 As Constraint
Dim oRef1 As Reference

For i = 1 To constraints1.Count
On Error Resume Next
    Set constraint1 = constraints1.Item(i)
    Select Case constraint1.Type
    Case Is = 2
            Cons = "Coincident"
            Elema = Replace(constraint1.GetConstraintElement(1).DisplayName, "Axis", "point")
            Elemb = Replace(constraint1.GetConstraintElement(2).DisplayName, "Axis", "point")
            Set oRef1 = constraint1.GetConstraintElement(1)
            Set oref2 = constraint1.GetConstraintElement(2)
            holename = constraint1.GetConstraintElement(1).DisplayName
    End Select
            Dim TheSPAWorkbench As Workbench
            Set TheSPAWorkbench = productDocument1.GetWorkbench("SPAWorkbench")
            Elema1 = Elema
          
            FirstSlash = InStr(Elema1, "/")
            SecondSlash = InStr(FirstSlash + 1, Elema1, "/")
            ThePart = Mid(Elema1, FirstSlash + 1, SecondSlash - FirstSlash - 1)
            temp1 = Split(ThePart, "")
          
            Set Constraintaxis1 = TheSPAWorkbench.GetMeasurable(oRef1)
            Dim aAxisVector(2)
            Constraintaxis1.GetDirection aAxisVector
   
            Dim selection2 As Selection
            Set selection2 = productDocument1.Selection
            selection2.Search "Name= " & temp1(0) & " ,all"
            CATIA.StartCommand "Open in New Window"
            
                Dim partDocument2 As PartDocument
                Set partDocument2 = CATIA.ActiveDocument
                Dim selectiony As Selection
                Set selectiony = partDocument2.Selection
            
                holes = Split(holename, "e:(Brp:(")
                FullName = holes(UBound(holes))
                holes = Split(FullName, ";0:(Brp")
                selectiony.Search "Name=" & holes(0) & ",all"
           
                holex = Split(holename, "e:(Brp:(")
                FullName = holex(UBound(holex))
                holex = Split(FullName, ".")
                        
                    If holex(0) = "Hole" Then
           
                    Dim theHole As Hole
                    Set theHole = selectiony.Item(1).Value
                    Dim vHole As Variant
                    Set vHole = theHole
                    Dim origin(2)
                    vHole.GetOrigin origin
            
                    Else
                    'do nothing, continue t next i as per error
                    End If
 MsgBox " The Constraint Element name is:  " & Elema
 MsgBox " The Origin is: " & origin(0) & ", " & origin(1) & ", " & origin(2)
 MsgBox " The Direction is: " & aAxisVector(0) & ", " & aAxisVector(1) & ", " & aAxisVector(2)
                    
partDocument2.Close
Next i
partDocument2.Close
                        
End Sub
 

Sponsor

Top