Tutorial#

Code asciciated with Dips Scripting Tutorial.

Code Snippet: Tutorial#

import math

from dips import DipsApp, BuiltInDataFormatters

from dips.DiscontinuityDataVal import DiscontinuityDataVal
from dips.FillFormatVal import FillFormatVal
from dips.LineFormatVal import LineFormatVal
from dips.OrientationDataSetVal import OrientationDataSetVal
from dips.TextFormatVal import TextFormatVal
from dips.TextToolEntityInfoVal import TextToolEntityInfoVal


# Start up the application with a port number

# this port number must be between 49152 and 65535, and not be in use by another program

app = DipsApp.LaunchApp(62535)


# Access the app model, this object is what allows access to most functionality in Dips

model = app.GetModel()


# Create a traverse with some simple parameters 

ods = model.GetDefaultOrientationDataSet()

ods.name = "Spot Mapping - Example"

ods.orientation_data_type = DipsApp.enums.eOrientationDataType.SpotMapping

ods.discontinuity_orientation_convention = DipsApp.enums.eOrientationConvention.TrendPlungeOrientation


ods.traverse_elevation_unit = BuiltInDataFormatters.LengthMeterDataFormatter

ods.traverse_xyz_unit = BuiltInDataFormatters.LengthMeterDataFormatter

ods.discontinuity_xyz_unit = BuiltInDataFormatters.LengthMeterDataFormatter

ods.discontinuity_persistence_unit = BuiltInDataFormatters.LengthMeterDataFormatter


# Create a variety of sample poles with different orientations

# Format: (trend_deg, plunge_deg) - since above we set discontinuity_orientation_convention to DipsApp.enums.eOrientationConvention.TrendPlungeOrientation

sample_poles = [
(45, 30),
(90, 45),
(135, 60),
(180, 30),
(225, 45),
(270, 60),
(315, 30),
(0, 45),
(60, 75),
(120, 25),
(240, 50),
(300, 40),
]


for trend_deg, plunge_deg in sample_poles:

    discontinuity = DiscontinuityDataVal()

    # Note: From the scripting interface angles are typically specified in radians

    discontinuity.orientation1.angle_radians = math.radians(trend_deg)

    discontinuity.orientation2.angle_radians = math.radians(plunge_deg)

    discontinuity.quantity = 1.0

    ods.discontinuity_list.append(discontinuity)


# Add the new traverse to the model

# This step adds the traverse to the Dips model, and will cause it to be part of current project

traveseRef = model.AddTraverse(ods)


# Now create a new 2D stereonet

# this will create the view, and the object returned will allow further interaction with this view

# you can also access all existing stereonet views in the model with model.Get2DStereonets()

stereonetViewRef = model.CreateStereonet2DView()


# Create a text tool for the stereonet

tool = TextToolEntityInfoVal()

tool.name = "Test Text Tool"

tool.is_visible = True

tool.text = "Hello Dips Scripting!"

tool.anchor_point.coordinate_option = DipsApp.enums.eAnchorCoordinateOption.Spherical

tool.anchor_point.spherical_point.trend.angle_radians = math.radians(45)

tool.anchor_point.spherical_point.plunge.angle_radians = math.radians(45)


# Set line format

line_format = LineFormatVal()

line_format.line_width = 1

tool.line_format = line_format


# Set fill format

fill_format = FillFormatVal()

fill_format.apply_fill = False

tool.fill_format = fill_format


# Set text format

text_format = TextFormatVal()

text_format.text_horizontal_alignment = DipsApp.enums.eTextHorizontalAlignment.Center

text_format.text_color.a = 255

text_format.text_color.r = 15

text_format.text_color.g = 15

text_format.text_color.b = 255

text_format.font_name = "Arial"

text_format.font_size = 12

tool.text_format = text_format


# Add the text tool to the stereonet

# the object returned allows for further modification to the text tool

# you can also access any existing text tools with stereonetViewRef.GetStereonet2DTextTools()

textToolref = stereonetViewRef.AddStereonet2DTextTool(tool)


# Some objects like Traverses, User Planes, and Sets are added to the entire project and will be visible 

# on all stereonets. In order to control how they are visualized on a specific stereonet they can be accessed 

# like this:

traverseVisibilities = stereonetViewRef.GetTraverseEntityVisibilityList()


# There should always be 1 traverse here, since we just added one

if traverseVisibilities:

    # Access the first one (the one we just added)

    traverseVisibility = traverseVisibilities[0]

    # We could also create a new traverseEntityVisibilityVal object (an object which holds all traverse visibilty options)

    # but since we only want to edit one option we can also get this traverses current settings, and edit the single value we want

    entityVisibilityVal = traverseVisibility.GetValue()

    # For example, hide the traverse label

    entityVisibilityVal.options.show_label = False

    # And now this line is what will apply the visiblity options to the traverse

    traverseVisibility.SetStereonet2DTraverseEntityOptions(entityVisibilityVal.options)


# Some objects like contour settings only have one per stereonet and are contolled more directly

stereonetViewRef.SetContourEntityVisibility(True)