The "Measure Between" measurement tool in CATIA V5 is not exposed to VBA; the macro recorder will not tape anything if you endeavour. Merely in that location are a few piece of work-arounds in order to measure distance between two points using a CATScript macro.measurement tool not exposed to CATIA VBA

Parameters and Relations Method


The first method is to create a parameter then add a formula to it. Before we create a macro, it's a good idea to understand exactly how it will work. If you were to do this manually, you would follow these steps:

1. Create a new parameter of blazon length. Set default value to 0mm and rename it if you lot want.

catia parameter length macros

ii. Click Add Formula.

3. Go to Measures and then select distance (Body, Body); Length

catia formula editor

4. Select the two bodies (objects or pieces of geometry) that are to be measured. That'southward it!

Now we volition recreate this using the post-obit CATScript:

1 2 iii iv 5 6 vii 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37                        
                          'this macro creates a parameter and relation to measure out the distance betwixt two points                                                    Language="VBSCRIPT"                          Sub                          CATMain()                          'active certificate is a unmarried part file                                                    Dim                          partDocument1                          As                          Certificate                          Prepare                          partDocument1 = CATIA.ActiveDocument                          Dim                          part1                          Equally                          Part                          Set                          part1 = partDocument1.Part                          Dim                          parameters1                          As                          Parameters                          Prepare                          parameters1 = part1.Parameters                          'create a new length type parameter, fix its value to 0 for now                                                    Dim                          length1                          Every bit                          Dimension                          Set                          length1 = parameters1.CreateDimension("",                          "LENGTH", 0.000000)                          'if yous want to rename the parameter                                                    length1.Rename                          "MeasureDistance"                          'create a new formula to link to the parameter                                                    Dim                          relations1                          As                          Relations                          Prepare                          relations1 = part1.Relations                          'make sure points are labeled MyEndPt1 and MyEndPt2 respectively                                                    Dim                          formula1                          As                          Formula                          Prepare                          formula1 = relations1.CreateFormula("Formula.2",                          "", length1,                          "distance(`Geometrical Gear up.1\MyEndPt1` ,`Geometrical Set.1\MyEndPt2` ) ")                          'rename the formula                                                    formula1.Rename                          "Distance"                          'brandish the distance the endpoints are apart in a messagebox                                                    Msgbox                          "The endpoints are "                          & length1.ValueAsString &                          " apart."                          Terminate                          Sub                        

'this macro creates a parameter and relation to measure the distance between two points Linguistic communication="VBSCRIPT" Sub CATMain() 'active certificate is a single part file Dim partDocument1 As Document Set partDocument1 = CATIA.ActiveDocument Dim part1 As Role Gear up part1 = partDocument1.Function Dim parameters1 As Parameters Set parameters1 = part1.Parameters 'create a new length type parameter, set its value to 0 for now Dim length1 Equally Dimension Set length1 = parameters1.CreateDimension("", "LENGTH", 0.000000) 'if you want to rename the parameter length1.Rename "MeasureDistance" 'create a new formula to link to the parameter Dim relations1 As Relations Ready relations1 = part1.Relations 'make sure points are labeled MyEndPt1 and MyEndPt2 respectively Dim formula1 As Formula Fix formula1 = relations1.CreateFormula("Formula.two", "", length1, "distance(`Geometrical Gear up.1\MyEndPt1` ,`Geometrical Set.one\MyEndPt2` ) ") 'rename the formula formula1.Rename "Distance" 'display the altitude the endpoints are apart in a messagebox Msgbox "The endpoints are " & length1.ValueAsString & " autonomously." End Sub

Your CATPart should look like this. Notice the parameter and relation that were created automatically (the measure between shown was created manually to double bank check the macro worked properly):

how to measure distance between two points catia

This code can be used to measure between more than simply two points. For example, you tin change it to measure a point to a plane by changing this line of code:

                    Set                    formula1 = relations1.CreateFormula("Formula.2",                    "", length1,                    "distance(`Geometrical Set.1\MyEndPt1` ,`Geometrical Set.i\MyEndPt2` ) ")

Set formula1 = relations1.CreateFormula("Formula.2", "", length1, "altitude(`Geometrical Set.1\MyEndPt1` ,`Geometrical Set.i\MyEndPt2` ) ")

Into this:

                    Set                    formula1 = relations1.CreateFormula("Formula.2",                    "", length1, Distance('Geometrical                    Set.1\MyEndPt1' , 'Geometrical                    Gear up.1\Plane.1')")                  

Set formula1 = relations1.CreateFormula("Formula.2", "", length1, Distance('Geometrical Set.1\MyEndPt1' , 'Geometrical Set.1\Airplane.1')")

SPAWorkbench Method

An alternative method to measure the altitude between two points with a CATIA macro is to use the SPAWorkbench properties and methods. This requires a license of DMU. Without the license, the calls will non work. The CATScript code is shown beneath:

1 2 iii 4 v 6 7 8 nine ten 11 12 13 14 xv sixteen 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46                        
                          Sub                          CATMain()                          'active document must exist a CATPart                                                    Dim                          documents1                          Every bit                          Documents                          Set                          documents1 = CATIA.Documents                          Dim                          pDocument1                          Equally                          PartDocument                          Set                          pDocument1 = CATIA.ActiveDocument                          Dim                          part1                          As                          Part                          Set                          part1 = pDocument1.Role                          Dim                          hybridBodies1                          As                          HybridBodies                          Gear up                          hybridBodies1 = part1.HybridBodies                          Dim                          reference1                          As                          Reference                          Dim                          hybridBody1                          As                          HybridBody                          Set                          hybridBody1 = hybridBodies1.Particular(i)                          Set                          hybridShapes1 = hybridBody1.HybridShapes                          Set                          reference1 = hybridShapes1.Particular("MyEndPt1")                          'if code non working properly apply msgbox to cheque reference proper name                                                    'MsgBox ("ref1=" & reference1.Name)                                                    Dim                          reference2                          As                          Reference                          Set                          reference2 = hybridShapes1.Item("MyEndPt2")                          'built in check if needed                                                    'MsgBox ("ref2=" & reference2.Proper name)                                                    'get the SPAworkbench                                                    Dim                          TheSPAWorkbench                          As                          Workbench                          Set                          TheSPAWorkbench = CATIA.ActiveDocument.GetWorkbench("SPAWorkbench")                          Dim                          TheMeasurable                          As                          Measurable                          Set                          TheMeasurable = TheSPAWorkbench.GetMeasurable(reference1)                          Dim                          MinimumDistance                          Every bit                          Double                          MinimumDistance = TheMeasurable.GetMinimumDistance(reference2)                          'display the effect                                                    MsgBox MinimumDistance                          End                          Sub                        

Sub CATMain() 'active document must be a CATPart Dim documents1 Every bit Documents Ready documents1 = CATIA.Documents Dim pDocument1 As PartDocument Set pDocument1 = CATIA.ActiveDocument Dim part1 Equally Role Fix part1 = pDocument1.Part Dim hybridBodies1 As HybridBodies Set hybridBodies1 = part1.HybridBodies Dim reference1 As Reference Dim hybridBody1 Equally HybridBody Fix hybridBody1 = hybridBodies1.Item(i) Set hybridShapes1 = hybridBody1.HybridShapes Set reference1 = hybridShapes1.Item("MyEndPt1") 'if code not working properly apply msgbox to check reference name 'MsgBox ("ref1=" & reference1.Proper name)   Dim reference2 Every bit Reference Ready reference2 = hybridShapes1.Item("MyEndPt2") 'congenital in check if needed 'MsgBox ("ref2=" & reference2.Name) 'get the SPAworkbench Dim TheSPAWorkbench Every bit Workbench Set TheSPAWorkbench = CATIA.ActiveDocument.GetWorkbench("SPAWorkbench") Dim TheMeasurable Equally Measurable Set TheMeasurable = TheSPAWorkbench.GetMeasurable(reference1) Dim MinimumDistance As Double MinimumDistance = TheMeasurable.GetMinimumDistance(reference2) 'brandish the result MsgBox MinimumDistance End Sub

spaworkbench measure

P.S. The GetWorkbench command takes a cord every bit an argument and returns a Workbench object. Each Workbench has an associated ID. To determine the ID of a workbench, open a workbench and the script that can be downloaded here.There'south likewise a listing of workbench IDs in the latest edition of VB Scripting for CATIA V5 hither.