Project Demo#
Demonstration of Project-level services in Dips Python API.
This script demonstrates IProjStubService methods including: - Project Management: Save project - Unit System: Get/Set unit system - Reporting Convention: Get/Set reporting convention - Weighting Options: Get/Set weighting settings - Project Summary: Get/Set project summary - Display Options: Kinematic, Stereonet2D, Stereonet3D, General Symbol, Entity Color, Rosette
Code Snippet: ProjectDemo.py#
"""
Demonstration of Project-level services in Dips Python API.
This script demonstrates IProjStubService methods including:
- Project Management: Save project
- Unit System: Get/Set unit system
- Reporting Convention: Get/Set reporting convention
- Weighting Options: Get/Set weighting settings
- Project Summary: Get/Set project summary
- Display Options: Kinematic, Stereonet2D, Stereonet3D, General Symbol, Entity Color, Rosette
"""
import math
from dips import DipsApp
from dips import DipsAPI_pb2
# Settings wrappers
import dips.WeightingSettingsVal
import dips.ProjectSummaryVal
import dips.KinematicAnalysisDisplayOptionsVal
import dips.Stereonet2DDisplayOptionsVal
import dips.Stereonet3DDisplayOptionsVal
import dips.GeneralSymbolDisplayOptionsVal
import dips.EntityColorOptionsVal
import dips.RosettePlotDisplayOptionsVal
# =============================================================================
# PROJECT MANAGEMENT DEMONSTRATIONS
# =============================================================================
def demonstrate_save_project(model):
"""Demonstrate saving the project."""
print("\n" + "=" * 60)
print("PROJECT MANAGEMENT")
print("=" * 60)
# Note: SaveProject requires a file path - this is just for demonstration
# In real usage you would provide a valid path
print(" - SaveProject: Skipped (requires file path)")
print(" Usage: model.SaveProject('C:/path/to/file.dips9')")
# =============================================================================
# UNIT SYSTEM DEMONSTRATIONS
# =============================================================================
def demonstrate_unit_system(model):
"""Demonstrate unit system get/set."""
print("\n" + "=" * 60)
print("UNIT SYSTEM")
print("=" * 60)
# Get current unit system
try:
result = model.GetUnitSystem()
unit_name = DipsAPI_pb2.eUnitSystem.Name(result.Value)
print(f" ✓ GetUnitSystem: {unit_name}")
except Exception as e:
print(f" ✗ GetUnitSystem: {e}")
# Set unit system to Imperial
try:
model.SetUnitSystem(DipsAPI_pb2.eUnitSystem.Imperial)
print(" ✓ SetUnitSystem: Imperial")
except Exception as e:
print(f" ✗ SetUnitSystem: {e}")
# =============================================================================
# REPORTING CONVENTION DEMONSTRATIONS
# =============================================================================
def demonstrate_reporting_convention(model):
"""Demonstrate reporting convention get/set."""
print("\n" + "=" * 60)
print("REPORTING CONVENTION")
print("=" * 60)
# Get current reporting convention
try:
result = model.GetReportingConvention()
convention_name = DipsAPI_pb2.eOrientationConvention.Name(result.Value)
print(f" ✓ GetReportingConvention: {convention_name}")
except Exception as e:
print(f" ✗ GetReportingConvention: {e}")
# Set reporting convention
try:
model.SetReportingConvention(DipsAPI_pb2.eOrientationConvention.DipDipDirectionOrientation)
print(" ✓ SetReportingConvention: DipDipDirectionOrientation")
except Exception as e:
print(f" ✗ SetReportingConvention: {e}")
try:
model.SetReportingConvention(DipsAPI_pb2.eOrientationConvention.TrendPlungeOrientation)
print(" ✓ SetReportingConvention: TrendPlungeOrientation")
except Exception as e:
print(f" ✗ SetReportingConvention: {e}")
# =============================================================================
# WEIGHTING OPTIONS DEMONSTRATIONS
# =============================================================================
def demonstrate_weighting_options(model):
"""Demonstrate weighting options get/set."""
print("\n" + "=" * 60)
print("WEIGHTING OPTIONS")
print("=" * 60)
# Get current weighting options
try:
weighting = model.GetWeightingOptions()
option_name = DipsAPI_pb2.eWeightingOption.Name(weighting.weighting_option)
min_bias_angle = weighting.minimum_bias_angle
print(f" ✓ GetWeightingOptions: weighting_option={option_name} min bias angle={math.degrees(min_bias_angle.angle_radians)}°")
except Exception as e:
print(f" ✗ GetWeightingOptions: {e}")
# Set weighting options
try:
weighting = model.GetDefaultWeightingSettings()
weighting.weighting_option = DipsAPI_pb2.eWeightingOption.TerzaghiWeighting
weighting.minimum_bias_angle.angle_radians = math.radians(10)
model.SetWeightingOptions(weighting)
print(" ✓ SetWeightingOptions: TerzaghiWeighting")
except Exception as e:
print(f" ✗ SetWeightingOptions: {e}")
# =============================================================================
# PROJECT SUMMARY DEMONSTRATIONS
# =============================================================================
def demonstrate_project_summary(model):
"""Demonstrate project summary get/set."""
print("\n" + "=" * 60)
print("PROJECT SUMMARY")
print("=" * 60)
# Get current project summary
try:
summary = model.GetProjectSummary()
print(f" ✓ GetProjectSummary: title='{summary.project_title}'")
except Exception as e:
print(f" ✗ GetProjectSummary: {e}")
# Set project summary
try:
summary = model.GetDefaultProjectSummary()
summary.project_title = "Demo Project"
summary.company = "Demo Company"
summary.author = "Demo Author"
summary.comments = "This is a demo project created by the Python API."
model.SetProjectSummary(summary)
print(" ✓ SetProjectSummary: Updated project info")
except Exception as e:
print(f" ✗ SetProjectSummary: {e}")
# =============================================================================
# DISPLAY OPTIONS DEMONSTRATIONS
# =============================================================================
def demonstrate_kinematic_display_options(model):
"""Demonstrate kinematic analysis display options."""
print("\n" + "=" * 60)
print("KINEMATIC ANALYSIS DISPLAY OPTIONS")
print("=" * 60)
try:
options = model.GetKinematicAnalysisDisplayOptions()
print(f" ✓ GetKinematicAnalysisDisplayOptions")
except Exception as e:
print(f" ✗ GetKinematicAnalysisDisplayOptions: {e}")
try:
options = model.GetDefaultKinematicAnalysisDisplayOptions()
model.SetKinematicAnalysisDisplayOptions(options.to_proto())
print(" ✓ SetKinematicAnalysisDisplayOptions")
except Exception as e:
print(f" ✗ SetKinematicAnalysisDisplayOptions: {e}")
def demonstrate_stereonet2d_display_options(model):
"""Demonstrate Stereonet2D display options."""
print("\n" + "=" * 60)
print("STEREONET 2D DISPLAY OPTIONS")
print("=" * 60)
try:
options = model.GetStereonet2DDisplayOptions()
print(f" ✓ GetStereonet2DDisplayOptions")
except Exception as e:
print(f" ✗ GetStereonet2DDisplayOptions: {e}")
try:
options = model.GetDefaultStereonet2DDisplayOptions()
model.SetStereonet2DDisplayOptions(options.to_proto())
print(" ✓ SetStereonet2DDisplayOptions")
except Exception as e:
print(f" ✗ SetStereonet2DDisplayOptions: {e}")
def demonstrate_stereonet3d_display_options(model):
"""Demonstrate Stereonet3D display options."""
print("\n" + "=" * 60)
print("STEREONET 3D DISPLAY OPTIONS")
print("=" * 60)
try:
options = model.GetStereonet3DDisplayOptions()
print(f" ✓ GetStereonet3DDisplayOptions")
except Exception as e:
print(f" ✗ GetStereonet3DDisplayOptions: {e}")
try:
options = model.GetDefaultStereonet3DDisplayOptions()
model.SetStereonet3DDisplayOptions(options.to_proto())
print(" ✓ SetStereonet3DDisplayOptions")
except Exception as e:
print(f" ✗ SetStereonet3DDisplayOptions: {e}")
def demonstrate_general_symbol_display_options(model):
"""Demonstrate general symbol display options."""
print("\n" + "=" * 60)
print("GENERAL SYMBOL DISPLAY OPTIONS")
print("=" * 60)
try:
options = model.GetGeneralSymbolDisplayOptions()
print(f" ✓ GetGeneralSymbolDisplayOptions")
except Exception as e:
print(f" ✗ GetGeneralSymbolDisplayOptions: {e}")
try:
options = model.GetDefaultGeneralSymbolDisplayOptions()
model.SetGeneralSymbolDisplayOptions(options.to_proto())
print(" ✓ SetGeneralSymbolDisplayOptions")
except Exception as e:
print(f" ✗ SetGeneralSymbolDisplayOptions: {e}")
def demonstrate_entity_color_options(model):
"""Demonstrate entity color options."""
print("\n" + "=" * 60)
print("ENTITY COLOR OPTIONS")
print("=" * 60)
try:
options = model.GetEntityColorOptions()
print(f" ✓ GetEntityColorOptions")
except Exception as e:
print(f" ✗ GetEntityColorOptions: {e}")
try:
options = model.GetDefaultEntityColorOptions()
model.SetEntityColorOptions(options.to_proto())
print(" ✓ SetEntityColorOptions")
except Exception as e:
print(f" ✗ SetEntityColorOptions: {e}")
def demonstrate_rosette_display_options(model):
"""Demonstrate rosette plot display options."""
print("\n" + "=" * 60)
print("ROSETTE PLOT DISPLAY OPTIONS")
print("=" * 60)
try:
options = model.GetRosettePlotDisplayOptions()
print(f" ✓ GetRosettePlotDisplayOptions")
except Exception as e:
print(f" ✗ GetRosettePlotDisplayOptions: {e}")
try:
options = model.GetDefaultRosettePlotDisplayOptions()
model.SetRosettePlotDisplayOptions(options.to_proto())
print(" ✓ SetRosettePlotDisplayOptions")
except Exception as e:
print(f" ✗ SetRosettePlotDisplayOptions: {e}")
# =============================================================================
# MAIN
# =============================================================================
def main():
"""Main demonstration function."""
print("=" * 60)
print("Dips API - Project Services Demo")
print("=" * 60)
# Connect to Dips
print("\nConnecting to Dips application...")
try:
app = DipsApp.LaunchApp(62535)
print("✓ Connected to Dips")
except Exception as e:
print(f"✗ Failed to connect: {e}")
print("Make sure Dips is running with scripting enabled on port 62535")
return
model = app.GetModel()
# Run all demonstrations
demonstrate_save_project(model)
demonstrate_unit_system(model)
demonstrate_reporting_convention(model)
demonstrate_weighting_options(model)
demonstrate_project_summary(model)
demonstrate_kinematic_display_options(model)
demonstrate_stereonet2d_display_options(model)
demonstrate_stereonet3d_display_options(model)
demonstrate_general_symbol_display_options(model)
demonstrate_entity_color_options(model)
demonstrate_rosette_display_options(model)
# Show the application
app.Show()
# Summary
print("\n" + "=" * 60)
print("DEMONSTRATION COMPLETE")
print("=" * 60)
print("""
Project services demonstrated (23 methods):
PROJECT MANAGEMENT (1 method):
- SaveProject (skipped - requires file path)
UNIT SYSTEM (2 methods):
- GetUnitSystem
- SetUnitSystem
REPORTING CONVENTION (2 methods):
- GetReportingConvention
- SetReportingConvention
WEIGHTING OPTIONS (2 methods):
- GetWeightingOptions
- SetWeightingOptions
PROJECT SUMMARY (2 methods):
- GetProjectSummary
- SetProjectSummary
DISPLAY OPTIONS (12 methods):
- GetKinematicAnalysisDisplayOptions
- SetKinematicAnalysisDisplayOptions
- GetStereonet2DDisplayOptions
- SetStereonet2DDisplayOptions
- GetStereonet3DDisplayOptions
- SetStereonet3DDisplayOptions
- GetGeneralSymbolDisplayOptions
- SetGeneralSymbolDisplayOptions
- GetEntityColorOptions
- SetEntityColorOptions
- GetRosettePlotDisplayOptions
- SetRosettePlotDisplayOptions
""")
if __name__ == "__main__":
main()