CATIA Rules

CATIA Rules

Absorb what is useful, reject what is useless, add what is specifically your own.”  Bruce Lee

Home_Innovatie_versnellen

Introduction

We like to figure out new things and to make progress. We don’t like passivity, because it’s kinda bad for the creative mind. This time we are coming with a new post about CATIA rules. CATIA rules are not something new, there are here for a long time. So why this post now? This post aims to show our way of writing them. We use powercopies a lot. Certainly, a lot of them are connected with excel tables because of different versions of the same part. These tables can cause a lot of problems with some checkers. Hence this is a place where rules can be very good in our case. So we want to change this excel tables with rules. 

Change dimensions with the rule

Certainly, you can find on Google a lot of things about CATIA rules, and also it’s not that hard to understand. Here are some references: Creating a Rule and Knowledge-Based Engineering PDF. Duo to this second reference we were enabled to create what we need. As a result, we will demonstrate to you what we did. Maybe you will need much more, but at least you can get some basic information.

Certainly, during this implementation, we figure out that there is a lot of possibilities. 

CATIA Rules

On the picture, you can see three rules, for part version, for activation, and color change. The first one will change length, height, width, and radius depending on the version. 

From this rule, you can see some basic, while you need some conduction to make it work. In our case, it is part version. So when it is “1” it will set value for other parameters. When you want to choose the parameter you need to click on it in the tree. We tried just to write it like the text but it didn’t work. We will show it in the video anyway. So with this knowledge, you can parameterize any kind of model without an Excel table. That was our goal in the beginning. Finally, let’s see some other CATIA rule possibilities.

Activity with the rule

Furthermore, in the process of the parameterization, you also need to activate or deactivate some things in the model, like a number of holes, etc. For example, one plate in the shorter version has 3 holes for screws and in the bigger version four. So you need to activate that one or deactivate it. Certainly, you can do it with the rule.

Of course with this approach, you can activate or deactivate any element.

Color with the rule

Even more, you can also change the color of the elements using CATIA rule. We found two ways to change color, first with the name of the color and second with the hex code. 

So this is our implementation of CATIA rules. In conclusion, from our experience, part parametrization is one of the best. We hope that we helped you with this topic.   

8 thoughts on “CATIA Rules

  • April 26, 2020 at 7:35 am
    Permalink

    Hi
    I am a begineer in CATScript. I recorded a macro and modified to create Point on a surface and then a line normal to surface.
    Input is GS with surfaces & output expected is for each surface respective point to be created and line to be created. Its failing. Will you kindly help me in correcting this macro so that I can run as well learn the correct syntax.
    Any help is much appreciated.

    Language=”VBSCRIPT”

    Sub CATMain()

    Set partDocument1 = CATIA.ActiveDocument

    Set part1 = partDocument1.Part

    Set hybridBodies1 = part1.HybridBodies

    ‘Set hybridShapeFactory1 = part1.HybridShapeFactory

    Set parameters1 = part1.Parameters

    MsgBox “Select Geometrical set.”

    Dim oSelection ‘ ‘As Selection
    Dim InputObjectType(0)

    Set hybridBody1 = hybridBodies1.Add()
    Set hybridBody1 = CATIA.ActiveDocument.Part.InWorkObject

    Set oSelection = CATIA.ActiveDocument.Selection
    oSelection.Clear
    InputObjectType(0) = “HybridBody”
    Status = oSelection.SelectElement2(InputObjectType, “Select Geometrical set.”, True)

    Set oHB = oSelection.Item(1).Value

    For Each oShape In oHB.HybridShapes

    Set hybridShapeFactory1 = part1.HybridShapeFactory

    Set parameters1 = part1.Parameters

    Dim hybridShapeSurfaceExplicit1 ‘As hybridShapeSurfaceExplicit1

    ‘Set hybridShapeSurfaceExplicit1 = parameters1.Item(“Surface.679”)

    Set hybridShapeSurfaceExplicit1 = parameters.Item(“Surface. & i”)

    ‘Set hybridBody1 = hybridBodies1.Add()
    ‘Set hybridBody1 = CATIA.ActiveDocument.Part.InWorkObject

    ‘part1.UpdateObject hybridBody1

    Set hybridShapeDirection1 = hybridShapeFactory1.AddNewDirectionByCoord(0, 0,1)

    Set parameters2 = part1.Parameters

    ‘Set reference1 = part1.CreateReferenceFromObject(hybridShapeSurfaceExplicit1)

    Set reference1 = part1.CreateReferenceFromObject(hybridShapeSurfaceExplicit1)

    Set hybridShapePointOnSurface1 = hybridShapeFactory1.AddNewPointOnSurface(reference1, hybridShapeDirection1, 0.000000)

    Set hybridBodies1 = part1.HybridBodies

    hybridBody1.AppendHybridShape hybridShapePointOnSurface1

    part1.InWorkObject = hybridShapePointOnSurface1

    part1.UpdateObject hybridBody1
    ‘part1.Update

    ‘Set hybridShapes1 = hybridBody1.HybridShapes

    ‘Set reference2 = hybridShapePointOnSurface1

    ‘Set hybridShapeLineNormal1 = hybridShapeFactory1.AddNewLineNormal(reference1, reference2, 0.000000, 1000.000000, False)

    ‘hybridBody1.AppendHybridShape hybridShapeLineNormal1

    ‘part1.InWorkObject = hybridShapeLineNormal

    Next

    ‘part1.Update

    End Sub

    Reply
    • May 2, 2020 at 10:16 am
      Permalink

      Hello, sry for the late reply.

      Here is the simplified solution, you can add more stuff to fit your needs.
      First I created two GS, first with the name “INPUT” and second with the name “OUTPUT”, in the first one I put “dead surfaces” and the second one I used for the results.
      I used multiple selection so you can select all surfaces from first GS(you can change this so you can use only simple selection and select that first GS, and using it get all surfaces inside).

      For the results, I just use “OUTPUT” GS, you can make this one with macro, and also give the name for lines and points.

      Language=”VBSCRIPT”

      Sub CATMain()

      Dim partDocument1 As Document
      Set partDocument1 = CATIA.ActiveDocument

      Dim part1 As Part
      Set part1 = partDocument1.Part

      Dim hybridShapeFactory1 As Factory
      Set hybridShapeFactory1 = part1.HybridShapeFactory

      Dim hybridShapeDirection1 As HybridShapeDirection
      Set hybridShapeDirection1 = hybridShapeFactory1.AddNewDirectionByCoord(1, 1, 1)

      Dim axisSystems1 As AxisSystems
      Set axisSystems1 = part1.AxisSystems

      Dim axisSystem1 As AxisSystem
      Set axisSystem1 = axisSystems1.Item(“Absolute Axis System”)

      Dim reference1 As Reference
      Set reference1 = part1.CreateReferenceFromObject(axisSystem1)

      hybridShapeDirection1.RefAxisSystem = reference1

      Dim parameters1 As Parameters
      Set parameters1 = part1.Parameters

      ‘For loop

      Dim oSel as Selection
      Set oSel=CATIA.ActiveDocument.Selection

      Dim strArray(0)
      strArray(0) = “AnyObject”
      Dim sStatus As String
      sStatus = oSel.SelectElement3(strArray, “Select surfaces”, False, CATMultiSelectionMode.CATMultiSelTriggWhenUserValidatesSelection, False)

      For i=1 to oSel.count

      Dim hybridShapeSurfaceExplicit1 As Parameter
      Set hybridShapeSurfaceExplicit1 = parameters1.Item(osel.item(i).value.name)

      Dim reference2 As Reference
      Set reference2 = part1.CreateReferenceFromObject(hybridShapeSurfaceExplicit1)

      Dim hybridShapePointOnSurface1 As HybridShapePointOnSurface
      Set hybridShapePointOnSurface1 = hybridShapeFactory1.AddNewPointOnSurface(reference2, hybridShapeDirection1, 0.000000)

      Dim hybridBodies1 As HybridBodies
      Set hybridBodies1 = part1.HybridBodies

      Dim hybridBody1 As HybridBody
      Set hybridBody1 = hybridBodies1.Item(“OUTPUT”)

      hybridBody1.AppendHybridShape hybridShapePointOnSurface1

      part1.InWorkObject = hybridShapePointOnSurface1

      part1.Update

      Dim reference3 As Reference
      Set reference3 = part1.CreateReferenceFromObject(hybridShapeSurfaceExplicit1)

      Dim reference4 As Reference
      Set reference4 = part1.CreateReferenceFromObject(hybridShapePointOnSurface1)

      Dim hybridShapeLineNormal1 As HybridShapeLineNormal
      Set hybridShapeLineNormal1 = hybridShapeFactory1.AddNewLineNormal(reference3, reference4, 0.000000, 20.000000, False)

      hybridBody1.AppendHybridShape hybridShapeLineNormal1

      part1.InWorkObject = hybridShapeLineNormal1

      part1.Update

      Next

      End Sub

      Feel free to ask any q.

      Reply
  • May 3, 2020 at 1:54 pm
    Permalink

    thank you for your kind response.

    Reply
  • May 3, 2020 at 2:02 pm
    Permalink

    Hi ,
    Below is the Macro which will offset the all the surfaces in the selected GS.
    I have two issues in which I need guidance/help & it will help me to learn.

    1. All the surfaces to be offset based on the user request Like – In / Out. Currently its happening on the side based on iorientation = True/False.
    2. Ignore the element which is failing by deactivating and go to next
    —> Here even though I have included “On Error Resume Next” – upon fist encounter of error element – MACRO is not able to update the successful element

    Language=”VBSCRIPT”

    Sub CATMain()

    Set partDocument1 = CATIA.ActiveDocument

    Set part1 = partDocument1.Part

    Set hybridBodies1 = part1.HybridBodies

    Offsetvalue = Inputbox(“Enter the value offset”)

    Dim InputObjectType(0)

    Set hybridBody1 = hybridBodies1.Add()
    Set hybridBody1 = CATIA.ActiveDocument.Part.InWorkObject

    msgbox (“Select the geometrical set”)

    Set oSelection = CATIA.ActiveDocument.Selection
    oSelection.Clear
    InputObjectType(0) = “HybridBody”
    Status = oSelection.SelectElement2(InputObjectType, “Select Geometrical set.”, True)

    Set hybridBody1 = hybridBodies1.Add()
    Set hybridBody1 = CATIA.ActiveDocument.Part.InWorkObject

    Dim iCount
    Dim i ‘As Integer

    oSelection.Search “CATGmoSearch.Surface,sel”
    iCount = oSelection.Count
    For i =1 to iCount

    ‘———–With the statement as below each item name in the selected GS will be displayed
    Set USel = CATIA.ActiveDocument.Selection
    ‘MsgBox(USel.Item(i).Value.Name)
    ‘————— 09-Macro_to_display_selected_items.catvbs – reference macro for this statement

    On Error Resume Next

    Set hybridShapeFactory1 = part1.HybridShapeFactory

    Set hybridShapeSurfaceExplicit1 = oSelection.Item(i).Value

    Dim reference1 ‘As Reference

    Set reference1 = part1.CreateReferenceFromObject(hybridShapeSurfaceExplicit1)

    Set hybridShapeOffset1 = hybridShapeFactory1.AddNewOffset(reference1, Offsetvalue, True, 0.010000)

    Set hybridBodies1 = part1.HybridBodies

    hybridBody1.AppendHybridShape hybridShapeOffset1

    part1.InWorkObject = hybridShapeOffset1

    If Err.Number 0 Then

    Selection.Clear
    Selection.Delete
    End If

    part1.Update
    Err.Clear
    Next
    part1.Update

    msgbox (“Total number of surfaces offseted are ” &iCount)

    End Sub

    Reply
  • May 3, 2020 at 8:22 pm
    Permalink

    Hello, again I simplified your idea, so you can add more stuff to the code. Again I used multiple selection for input surface selection. I made again “OUTPUT” GS for offset results. Ofc you can add more to this code, I just make a simple solution for you.

    Sub CATMain()
    Dim partDocument1
    Set partDocument1 = CATIA.ActiveDocument

    Dim part1
    Set part1 = partDocument1.Part

    Dim hybridBodies1
    Set hybridBodies1 = part1.HybridBodies

    Dim hybridBody1 As HybridBody
    Set hybridBody1 = hybridBodies1.Item(“OUTPUT”)

    Dim Offsetvalue as String
    Offsetvalue = InputBox (“Enter the value offset”)

    Dim oSelection
    Set oSelection = CATIA.ActiveDocument.Selection
    oSelection.Clear

    Dim strArray(0)
    strArray(0)=”AnyObject”
    Dim sStatus As String
    sStatus = oSelection.SelectElement3(strArray, “Select surfaces”, False, CATMultiSelectionMode.CATMultiSelTriggWhenUserValidatesSelection, False)

    Dim iCount
    Dim i As Integer

    For i =1 to oSelection.count

    Dim parameters1 As Parameters
    Set parameters1 = part1.Parameters

    Dim hybridShapeSurfaceExplicit1 As Parameter
    Set hybridShapeSurfaceExplicit1 = parameters1.Item(oSelection.item(i).value.name)

    Dim reference1 As Reference
    Set reference1 = part1.CreateReferenceFromObject(hybridShapeSurfaceExplicit1)

    Dim hybridShapeFactory1 As Factory
    Set hybridShapeFactory1 = part1.HybridShapeFactory

    Dim hybridShapeOffset1 As HybridShapeOffset
    Set hybridShapeOffset1 = hybridShapeFactory1.AddNewOffset(reference1, Offsetvalue, True, 0.010000)

    hybridBody1.AppendHybridShape hybridShapeOffset1

    part1.InWorkObject = hybridShapeOffset1

    part1.Update
    Next

    MsgBox (“Total number of surfaces offseted are: ” & oSelection.count)

    End Sub

    Reply
  • May 4, 2020 at 5:49 am
    Permalink

    Thank you for kind response.
    May I request to let me know
    1. on error issues -like if a surface is failed to offset – it should be deactivated and go to next element
    2. Like all the offset to be on the same side.

    This will help me to understand since my macro is failing.

    Reply
    • May 4, 2020 at 4:26 pm
      Permalink

      Hello, I add some code for the error, for the second I m not sure that it can be done, it should offset on the same side. If you have an example were macro offset on different sides pls send me to check.

      Sub CATMain()
      Dim partDocument1
      Set partDocument1 = CATIA.ActiveDocument

      Dim part1
      Set part1 = partDocument1.Part

      Dim hybridBodies1
      Set hybridBodies1 = part1.HybridBodies

      Dim hybridBody1 As HybridBody
      Set hybridBody1 = hybridBodies1.Item(“OUTPUT”)

      Dim Offsetvalue as String
      Offsetvalue = InputBox (“Enter the value offset”)

      Dim oSelection
      Set oSelection = CATIA.ActiveDocument.Selection
      oSelection.Clear

      Dim strArray(0)
      strArray(0)=”AnyObject”
      Dim sStatus As String
      sStatus = oSelection.SelectElement3(strArray, “Select surfaces”, False, CATMultiSelectionMode.CATMultiSelTriggWhenUserValidatesSelection, False)

      Dim iCount
      Dim i As Integer

      For i =1 to oSelection.count

      Dim parameters1 As Parameters
      Set parameters1 = part1.Parameters

      Dim hybridShapeSurfaceExplicit1 As Parameter
      Set hybridShapeSurfaceExplicit1 = parameters1.Item(oSelection.item(i).value.name)

      Dim reference1 As Reference
      Set reference1 = part1.CreateReferenceFromObject(hybridShapeSurfaceExplicit1)

      Dim hybridShapeFactory1 As Factory
      Set hybridShapeFactory1 = part1.HybridShapeFactory

      Dim hybridShapeOffset1 As HybridShapeOffset
      Set hybridShapeOffset1 = hybridShapeFactory1.AddNewOffset(reference1, Offsetvalue, True, 0.010000)

      hybridBody1.AppendHybridShape hybridShapeOffset1

      part1.InWorkObject = hybridShapeOffset1

      part1.Update

      If Err.Number <> 0 Then
      part1.Inactivate hybridShapeOffset1
      End if

      On Error Resume Next
      Next

      MsgBox (“Total number of surfaces offseted are: ” & oSelection.count)

      End Sub

      Reply
  • May 8, 2020 at 12:43 pm
    Permalink

    Hi,

    May I request your help on below macro.
    Requirement is to create a sphere with points in a selected GS.
    My issue is not able to connect parameter and relations / Formula for dia of sphere.

    Any guidance to complete this will be of great help.

    I have declared a parameter but don’t know how to connect using relations/formula.

    Language=”VBSCRIPT”
    ‘ * * * * * * * * * * * * *
    ‘This MACRO is to create a parametric spehere with diametere as input
    ‘points in GS
    ‘ * * * * * * * * * * * * * – – – – – – – – – – – * * * * * * *

    Sub CATMain()

    Set partDocument1 = CATIA.ActiveDocument

    Set part1 = partDocument1.Part

    Set parameters1 = part1.Parameters

    Set hybridBodies1 = part1.HybridBodies

    ‘Set hybridShapes1 = hybridBody1.HybridShapes

    Set axisSystems1 = part1.AxisSystems

    Set axisSystem1 = axisSystems1.Add()

    axisSystem1.OriginType = catAxisSystemOriginByCoordinates

    Dim arrayOfVariantOfDouble1(2)
    arrayOfVariantOfDouble1(0) = 0.000000
    arrayOfVariantOfDouble1(1) = 0.000000
    arrayOfVariantOfDouble1(2) = 0.000000
    axisSystem1.PutOrigin arrayOfVariantOfDouble1

    axisSystem1.XAxisType = catAxisSystemAxisByCoordinates

    Dim arrayOfVariantOfDouble2(2)
    arrayOfVariantOfDouble2(0) = 1.000000
    arrayOfVariantOfDouble2(1) = 0.000000
    arrayOfVariantOfDouble2(2) = 0.000000
    axisSystem1.PutXAxis arrayOfVariantOfDouble2

    axisSystem1.YAxisType = catAxisSystemAxisByCoordinates

    Dim arrayOfVariantOfDouble3(2)
    arrayOfVariantOfDouble3(0) = 0.000000
    arrayOfVariantOfDouble3(1) = 1.000000
    arrayOfVariantOfDouble3(2) = 0.000000
    axisSystem1.PutYAxis arrayOfVariantOfDouble3

    axisSystem1.ZAxisType = catAxisSystemAxisByCoordinates

    Dim arrayOfVariantOfDouble4(2)
    arrayOfVariantOfDouble4(0) = 0.000000
    arrayOfVariantOfDouble4(1) = 0.000000
    arrayOfVariantOfDouble4(2) = 1.000000
    axisSystem1.PutZAxis arrayOfVariantOfDouble4

    part1.UpdateObject axisSystem1

    axisSystem1.IsCurrent = True

    part1.UpdateObject axisSystem1

    msgbox (“Select the geometrical set with I/P points for creating Sphere”)

    Dim oSelection ‘as Selection
    Dim InputObjectType(0)

    Set oSelection = CATIA.ActiveDocument.Selection
    oSelection.Clear
    InputObjectType(0) = “HybridBody”
    Status = oSelection.SelectElement2(InputObjectType, “Select Geometrical set.”, True)

    Set hybridBody1 = hybridBodies1.Add()
    Set hybridBody1 = CATIA.ActiveDocument.Part.InWorkObject

    Set parameters1 = part1.Parameters

    Dim Spheredia ‘As integer
    Spheredia=Inputbox(“Enter Diameter of sphere to be created”)

    Set length1 = parameters1.CreateDimension(“”, “LENGTH”,Spheredia )

    length1.Rename “SPRDIA”

    Dim iCount

    Dim i ‘As Integer

    oSelection.Search “CATGmoSearch.Point,sel”

    iCount = oSelection.Count

    For i = 1 to iCount

    Set hybridShapePointOnSurface1 = oSelection.Item(i).Value

    ‘Set axisSystem1 = axisSystems1.Item(“Axis System.1”)

    ‘Set axisSystem1 = axisSystems1.Item(i)

    ‘Dim reference1 ‘As reference
    Set reference1 = part1.CreateReferenceFromObject(hybridShapePointOnSurface1)

    Dim reference2 ‘As Reference
    Set reference2 = part1.CreateReferenceFromObject(axisSystem1)

    Set hybridShapeFactory1 = part1.HybridShapeFactory

    Set hybridShapeSphere1 = hybridShapeFactory1.AddNewSphere(reference1, reference2, SPRDIA, -45.000000, 45.000000, 0.000000, 180.000000)

    hybridShapeSphere1.Limitation = 1

    hybridBody1.AppendHybridShape hybridShapeSphere1

    part1.InWorkObject = hybridShapeSphere1

    hybridShapeSphere1.name = “Shpere for-” & oSelection.Item(i).Value.name

    ‘part1.Update

    NEXT

    part1.Update

    msgbox (“Total number of sphere created -” & iCount)

    End Sub

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *