See the procedures on this page to create style sheet components.

Creating custom style sheet components

Creating global conditions for a style sheet

In addition to specifying conditions for individual rules in the style sheet (see procedure Specifying conditions for a rule), you can specify a global condition that applies to the entire style sheet. All individual rules declared in the style sheet apply only to the symbols that comply with the global rule.

Creating global conditions for a style sheet

To create global conditions for a style sheet


  1. Create a style sheet.
  2. Within the body of the part definition of the new style sheet, redefine the styleSheetCondition element inherited from the StyleSheet element and define it by the needed condition.
  3. Within the body of the condition, declare a ref item, then redefine the needed item and specify its values.

    The available ref items and their value types depend on the condition definition you are using. For a list of the condition definitions and their available ref items, see the Style sheet rule conditions table on the Style sheet conditions and styles tables page.

  4. Synchronize modifications.

    // the following style sheet contains a global condition 'General View Condition' followed by an individual rule for a specific element metaclass and applicable style

    package NewStylesPackage {
        private import DS_Styles::**;
        private import CoreStylesComponents::*;
        private import Predicates::*;
        private import ColorDefinitions::*;
        private import CompartmentVisibilityDefinitions::*;
        private import KerMLStyles::*;
        private import SysMLStyles::*;

        part def NewStyleSheet :> StyleSheet {
            /* ------- global condition ------- */

            part 'General View Condition' :>> styleSheetCondition : ByDiagramTypeCondition // global style sheet condition targeting symbols by view definition
                ref item :>> diagramType = DS_Views::SymbolicViews::gv.metadata // the condition targets views defined by the General View view definition
            }
            /* ----------------------------------- */ 

            part partRule :> rule {  // an individual rule targets PartUsage metaclasses and applies the specified style to them. Because of the global rule, only part usages displayed on a General View will be affected by the rule
                part :>> condition : ByElementMetaclassCondition 
                    ref item :>> elementMetaclass = SysML::Systems::PartUsage.metadata
                }
                view : ShapeStyle :>> style {
                    attribute :>> textColor default "#2A16FF";
                }
            }
        }
    }

Creating custom rules

Creating custom rules

To create a custom rule


  1. Create a style sheet.
  2. Within the body of the part definition of the new style sheet, specify the rule, declare a part usage, specify a name for the new rule, subset the rule element inherited from the StyleSheet element, and in its body, do any of the following as needed:
    1. Specify the rule's condition.
    2. Specify the rule's style.
  3. Synchronize modifications.

    package NewStylesPackage {
        private import DS_Styles::**;
        private import CoreStylesComponents::*;
        private import Predicates::*;
        private import ColorDefinitions::*;
        private import CompartmentVisibilityDefinitions::*;
        private import KerMLStyles::*;
        private import SysMLStyles::*;

        part def NewStyleSheet :> StyleSheet {
            /* ------- new rule ------- */
            part partRule :> rule {
                   // Specify the rule's condition
                   // Specify the rule's style

            }
            /* ----------------------------------- */
        }
    }

Specifying conditions for a rule

Specifying conditions for a rule

To specify a condition for a rule


  1. Within the body of the part element of the rule, declare a part usage and redefine the condition element inherited from the StyleSheet element, then define it by the needed condition.
  2. Within the body of the condition, declare a ref item, then redefine the needed item and specify its values.
    1. For the FreeFormCondition, declare a calc and redefine test, then specify the needed expression.

      The available ref items and their value types depend on the condition definition you are using. For a list of the condition definitions and their available ref items, see the Style sheet rule conditions table on the (2026x) Style sheet conditions and styles tables page.

  3. Synchronize modifications.

    // ByElementMetaclassCondition example

    part partRule :> rule {
       part :>> condition : ByElementMetaclassCondition {   // the rule's condition is specified as ByElementMetaclassCondition, targeting symbols by element metaclass 
          ref item :>> elementMetaclass = SysML::Systems::PartUsage.metadata // the condition targets elements with the PartUsage metaclasses
       }
    }

    // ByMetadataAnnotationCondition example

    part metadataApprovalRule :> rule {
       part :>> condition : ByMetadataAnnotationCondition {  // the rule's condition is specified as ByMetadataAnnotationCondition, targeting symbols by element metadata
          ref item :>> annotatingMetadataType = 'Vehicle Metadata Definitions'::Approval.metadata;  // the condition targets elements with the applied Approval metadata
       }
    }

    // ByDiagramTypeCondition example

    part generalViewRule :> rule {
       part :>> condition : ByDiagramTypeCondition {  // the rule's condition is specified as ByDiagramTypeCondition, targeting symbols by view definition
          ref item :>> diagramType = DS_Views::SymbolicViews::gv.metadata;   // the condition targets views defined by the General View view definition
       }
    }

    // FreeFormCondition example

    part MyFreeformRule :> rule {
       part :>> condition : FreeFormCondition {   // the rule's condition is specified as FreeFormCondition, targeting symbols by the specified expression
          calc :>> test {
             'VCCU View'.metadata == diagram // targets element symbols on the specific view 'VCCU View'
             // OR
             element == VCCU.metadata // targets the VCCU element symbol on all views (to which the style sheet is applied)     
          }

       }
    }

Specifying styles for a rule

There are two ways you can specify a style for a rule:

Specifying style attributes locally for the style of a rule

To specify style attributes locally for the style of a rule


  1. Within the body of the part element of the rule, after the condition specification, declare a view usage, define it by the needed style definition, and redefine the style element inherited from the StyleSheet element.
  2. Within the body of the view element, declare an attribute usage, redefine the needed attribute and specify its value.
  3. Synchronize modifications.

part partRule :> rule {
   part :>> condition : ByElementMetaclassCondition {
      ref item :>> elementMetaclass = SysML::Systems::PartUsage.metadata;
   }
   view : ShapeStyle :>> style { // the rule's style is defined by a primary style definition StyleShape
      attribute :>> textColor default "#FF0F37";  // local modification of an available attribute's value
   }
}

Hiding style attributes from the Symbol Style dialog for specific element kinds

To hide style attributes from the Symbol Style dialog for specific element kinds


  1. Within the body of the part element of the rule, after the condition specification, declare a view usage, define it by the needed style definition, and redefine the style element inherited from the StyleSheet element.
  2. Within the body of the view element, declare an attribute usage and apply the InvisibleInDialog metadata to it, then redefine the style attribute you want to hide from the Symbol Style dialog for the element kind specified in the rule's condition.
  3. Synchronize modifications.

part partRule :> rule {
   part :>> condition : ByElementMetaclassCondition {
      ref item :>> elementMetaclass = SysML::Systems::PartUsage.metadata;
   }
   view : ShapeStyle :>> style
     #InvisibleInDialog attribute :>> contentFillColor;   // the style attribute Content Fill Color is hidden from the Symbol Style dialog for part usages
   }
}

Creating custom style definitions

Unlike local attribute specification, creating custom style definitions allows you to reuse them for style specification of multiple rules. 

You can create custom style definitions specifying the needed attributes and their values. Custom style definitions must subclassify primary style definitions (such as ShapeStyle, ShapeOnBorderStyle, etc.), inheriting their attributes, which you can modify. However, you can only add attributes that are available to the primary style definition that the custom style definition subclassifies. 
For an extensive list of primary style definitions and their available attributes, see the Symbol styles table on the (2026x) Style sheet conditions and styles tables page.

To create a custom style definition


  1. Within the body of the part definition of the new style sheet, declare a view definition element, specify its name, and subclassify a primary style definition from the DS_Styles::CoreStylesComponents::KerMLStyles package. 

    For a list of primary style definitions, their attributes, and value types, see the Symbol styles table on the (2026x) Style sheet conditions and styles tables page.

  2. Within the body of the view definition element, declare an attribute usage, redefine the needed attribute and specify the attribute's value.

    The available attributes and their value types depend on the primary style definition you are using. For an extensive list of the primary style definitions and their available attributes, see the Symbol styles table on the (2026x) Style sheet conditions and styles tables page.

  3. Specify the custom style definition for the style of a rule.
  4. Synchronize modifications.

part def NewStyleSheet :> StyleSheet {
    part partRule :> rule {
        part :>> condition : ByElementMetaclassCondition {   // custom rule
            ref item :>> elementMetaclass = SysML::Systems::PartUsage.metadata;
        }
        view : PartTextStyleRule :>> style; // the style of the rule is updated to be defined by the new custom style definition
    }
    view def PartTextStyleRule :> ShapeStyle {   // new custom style definition subclassifies the primary style definition ShapeStyle
        attribute :>> textColor default "#68FF70";
    }
}

Creating custom reusable style attribute values

You can create custom style attributes whose values you can reuse by referencing them where needed. Additionally, you can create custom style classes grouping such attributes. 

To create custom reusable style attribute values


  1. Declare an attribute, specify its name, then define it by the needed value type, and specify its value. 
  2. (Optional) To group attributes within a custom style class, declare a part usage, specify its name, then place the attributes within the part's body.
  3. Reuse the newly created style attribute values for custom style definition attributes or local attribute specification. Use feature chaining for attributes nested within custom style classes
  4. Synchronize modifications.

part def NewStyleSheet :> StyleSheet {
   part partRule :> rule {
      part :>> condition : ByElementMetaclassCondition {
         ref item :>> elementMetaclass = SysML::Systems::PartUsage.metadata;
      }
      view : PartTextStyleRule :>> style; // the custom style is passed to the rule's style
   }
   view def PartTextStyleRule :> ShapeStyle {
      attribute :>> penColor default customColorPalette.customDarkGreen; // the custom color from a custom style class is reused in a custom style definition
   }
   part customColorPalette {    // custom style class with reusable style attributes for custom color values are specified
      attribute customDarkGreen : Color default "#357F35";      
      attribute customLightGreen : Color default "#BFF7AA";
   }
}

Specifying the compartment style of a rule

To specify the compartment style of a rule 


  1. Within the body of the view element, declare a part usage, specify its name (optional), then define it by the appropriate compartment style definition. 

    To determine which primary compartment style definitions are available for each element symbol, see the Symbol compartment styles table on the (2026x) Style sheet conditions and styles tables page.

  2. Within the body, redefine the needed compartment style attribute followed by the appropriate attribute value.  

    To determine which attributes and what value types are available to each primary compartment style definition, see the Symbol compartment styles table on the (2026x) Style sheet conditions and styles tables page.

  3. Synchronize modifications.

    part partRule :> rule {
       part :>> condition : ByElementMetaclassCondition {
          ref item :>> elementMetaclass = SysML::Systems::PartUsage.metadata;
       }
       view : ShapeStyle :>> style  // defined by a primary style definition
          attributeCompartment : AttributesCompartmentStyle   // attribute for the attributes compartment's 
             :>> showCompartment default true; // modifying the showCompartment value
          }
       }
    }