How to add your knowledge

Snippets

    Table of contents
    No headers

    What are snippets?

    Code snippets provide "short cuts" for frequently used pieces of code. You can insert snippets in your rules to enter strings of characters that you would normally have to type in using the keyboard. Snippets also reduce the possibility of typographical errors in your code.

    You access the available snippets from the Snippets area of the Edit Rule dialog box. This area features two tabs:

    • The System tab includes a set of pre-defined snippets, arranged by category. Hover over each snippet to display a tooltip describing its function in more detail.
    • The Custom tab allows you to add your own snippets, or create custom copies of System snippets.

    What are favorite snippets?

    Favorites allow you to choose which snippets appear on the System tab. You can mark specific snippets as favorites, and then toggle the display of the list to show only those snippets marked as favorites.

     

    Procedures:

    Snippets

    Work with System snippets

    Define favorite snippets

    1. icon_ilogic_snippet_favorite_select.pngClick Edit favorite snippets at the top of the System tab.
    2. Select the snippets to be marked as favorites from the tree. Select a category to include all the snippets in the category, or expand a category and select individual snippets.
    3. Click OK when finished.

    Display favorite snippets

    icon_ilogic_snippet_favorite_toggle.pngTo display only your favorite snippets, click the favorites toggle at the top of the System tab.

    To display all snippets, click the favorites toggle again.

    Copy System snippets to Custom snippets

    1. Right-click on a snippet in the System tab.
    2. Select Copy to Custom from the context menu.

      A copy of the snippet is placed on the Custom tab, in the same category as it appears on the System tab. If the category does not exist, it is created.

    Work with Custom snippets

    Create a Custom snippet

    1. Highlight the snippet text in the editing window, then right-click and select Capture Snippet.

      The Edit Snippet dialog box displays, with a copy of the snippet text in the Code text box.

    2. Enter the Title of the snippet, to be displayed in the snippets list.
    3. Select the Category in which the snippet is listed, or enter the name of a new category.
    4. Optionally, enter a text string to display as a tooltip when you hover the mouse pointer over the snippet in the list. Click Use Code as Tooltip to place a copy of the snippet text into the tooltip text box, and then edit the text as necessary.
    5. Edit the snippet in the Code text box as necessary. For complicated or long snippets, click the right arrow above the vertical scroll bar on the right to enable automatic outlining.
    6. Click Save or press Ctrl-S to save your snippet.

    Snippets are also saved when you click OK in the Edit Rule dialog box. The first time you save custom snippets, you are prompted to choose the save location.

    Manage custom snippet categories

    Once you have created custom snippets, arrange them in different categories.

    • To create a category, right-click and select Insert Category from the context-menu.
    • To place a snippet into a category, drag it into its proper location within the tree.
    • To rename a code snippet category, select the snippet or category, then right-click and select Rename from the context menu.
    • Use Save As on the toolbar to create different collections of code snippets for specific projects.

    Edit a custom snippet

    1. Right-click on a snippet, and select Edit.
    2. Make the necessary changes in the Edit Snippets dialog box.
    3. Click OK when finished.

    Replace custom snippets from external file

    1. Click icon_ilogic_snippet_openreplace.pngat the top of the System tab.
    2. Select the file to replace the snippets in the Custom tab, and click Open.

    Merge custom snippets from external file

    1. Click icon_ilogic_snippet_openmerge.pngat the top of the System tab.
    2. Select the file to merge with the snippets in the Custom tab, and click Open.

    Delete a custom snippet

    To delete a custom snippet, right-click on the snippet, and select Delete.

    Create custom snippet collections for specific projects

    1. Click icon_ilogic_snippet_saveas.pngat the top of the System tab.
    2. Specify a filename and location, and click Save to save a copy of all the Custom snippets in the list as an external .xml file.
    3. If necessary, open the saved file using an XML editor and remove or edit the saved snippets.

    Move or hide the Snippets area

    icon_snippets_pin.png Use the Pin symbol at the top of the Snippets area to customize its behavior.

    • Click the pin to change between show/hide mode and docking/undocking mode.
    • When the pin symbol points down, click in the title bar to the left of the pin symbol to undock the area. Then, drag the Snippets area and pin it to another location on the screen. Use the docking icons that display in the Autodesk Inventor work area if you want to dock the Snippets area to either side of the Inventor window. Click the Snippets area, then drag it over a docking icon, and release the mouse button.
    • When the pin symbol points left, a Snippets tab replaces the Snippets area when it is not in use. Click the Snippets tab to show the Snippets area.

     

    References

    System snippet categories

    Parameters

    Work with part and assembly parameters. Get or set single and multiple values, Excel spreadsheet values, or xml read/write parameters.

    Features

    Turn a feature on or off, change the color, or work with threads.

    Components

    Suppress or activate (unsuppress) a component, replace one component with another component or an iPart, change the color of a component, or find a subcomponent.

    iProperties

    Access several different iProperties of a part, assembly, or component.

    Excel Data Links

    Read data from and store data to an Excel spreadsheet. The spreadsheet can be an external file or embedded in the Inventor model.

    iParts

    Manipulate iParts.

    iFeatures

    Manipulate table-driven iFeatures.

    Constraints

    Manipulate assembly model constraints.

    Measure

    Measure distances, angles, areas, perimeters, and extents.

    Work Features

    Provide access to Inventor work features.

    MessageBox

    Display messages or quickly construct a simple UI to obtain user input while a rule is running.

    Document

    Obtain path information about the current document, save the document, update the document, or open a new document.

    Run Other

    Run other iLogic rules, rules in other components, external rules, Autodesk Inventor macros, and rules defined in VB.NET.

    BOM

    Access Autodesk Inventor Bill of Material functionality.

    Math

    Access several mathematical routines and functions. Refer to the VB.NET documentation for complete details.

    You can also access math snippets by right-clicking from within the rule text area and selecting Math Functions.

    Strings

    Access several string routines. Refer to the VB.NET documentation for complete details.

    Variables

    Declare and manipulate variables. Create shared variables to use between rules.

    This category also includes snippets for "pure" VB.NET functions that allow you to use local (temporary) VB.NET variables in rules. Refer to the VB.NET documentation for complete details.

    Material Properties

    Access various material properties stored on the component definition in the Inventor API model.

    Sheet Metal

    Manipulate sheet metal models from iLogic rules.

    Drawing

    Reflect changes to the model in the drawing sheets and views.

    Advanced Drawing API

    Can be used to take advantage of API functions in drawings.

    Advanced API

    Access the Autodesk Inventor API.

     

    Edit Snippet

    Use this dialog box to define or modify the contents of a snippet, or to change its name or category..

    Access:

    In the Edit Rule dialog box, right-click on a snippet in the Snippets area and select Edit. This dialog box also displays when you select the text of a snippet in the rule text area and select Capture Snippet from the context menu.
    TitleThe name of the snippet to display in the list.
    CategoryThe category in which the snippet is placed.
    TooltipThe text of the tooltip to display when the mouse pointer hovers over the snippet in the list.
    Use Code as TooltipCopy the text of the snippet into the Tooltip text box. The text can then be used as it appears in this field, or it can be edited as necessary.
    CodeThe text of the snippet, which can be edited in this field.
    OKSaves the edits.
    CancelCancels the operation.