Setting up a Basic Workflow

Total Page:16

File Type:pdf, Size:1020Kb

Setting up a Basic Workflow

Basic Workflows

Setting up a basic workflow

1) Open Infrastructure Administrator

2) Open a project. This script assumes you are working with a Water model

3) Click on the Workflow folder in the Industry Model Explorer pane

4) Click the Create button and give your workflow a name (something that is descriptive of what you will be doing)

5) Click Create. Your workflow will be added to the Workflow list

6) Select your workflow. The Script Code text box will automatically be filed with the empty definition of a VB.NET function

7) Add code to the function between Sub Run and End Sub. Use the following code to create some basic workflows.

Basic Message Box

Me.Application.MsgBox("Seemples") Basic Message Box and input box

Dim name As String

name = InputBox("Input Something:", "Anything")

If (not string.IsNullOrEmpty(name)) Then

Me.Application.MsgBox(name)

End If

Select Features

me.Document.Map.SelectFeatures("WA_VALVE")

Select and list

Dim features as FeatureList me.Document.Map.SelectFeatures("WA_VALVE") features = Me.Document.Map.GetFeatures()

Me.Application.MessageBox(features.Item(0).Attributes.Item("FID").Value)

Digitize

Dim dig as FeatureList

Dim fc as FeatureClass fc = Me.Document.Connection.FeatureClasses.Item("WA_LINE") dig = me.Document.Map.DigitizeFeatures(fc, fc.Type ,"", "",true)

Digitize and show dialog

Dim dig as FeatureList Dim fc as FeatureClass fc = Me.Document.Connection.FeatureClasses.Item("WA_LINE") dig = me.Document.Map.DigitizeFeatures(fc, fc.Type ,"", "",true)

Me.Document.OpenDialog(dig) Challenge:

Write a short script that:

 Digitizes a Pipe

 Shows the new FID of the pipe in a Message box

Creating a Plugin Workflow

1) In Visual Studio create new class library: call it MyWorkflow and save.

2) On the menu bar go to Project> MyWorkflow Properties

3) Set the ouput path for the compiled dll to C:\Program Files\Autodesk\AutoCAD Map 3D 2012\bin\ (or 2013)

4) Click the Reference Tab. Set reference folder to C:\Program Files\Autodesk\AutoCAD Map 3D 2012\bin and click Add

5) In Solution Explorer set up the references: Right Click on References and Add:

System.Drawing

System.Windows.Forms Topobase.Data

Topobase.Forms

Topobase.Graphic

Topobase.Map

Topobase.Workflow

6) Rename the .cs file to MyPlugin.cs and double click to open

7) Add the following to create the basic class container code

using System; using System.Collections; using Topobase.Workflows; using Topobase.Workflows.Forms; using Topobase.Data;

namespace MyWorkflow { public class MyPlugin : WorkflowPlugIn

{ public void MyWorkflow1() { this.WorkflowSupport.WorkflowExplorerFlyIn.ShowMessage("Please Digitize a point"); } } }

8) In Solution explorer right click on the MyWorkflow node and select ADD>User Control. In the Add New Item Dialog, select User Control

Name the User Control MyUserControl and click Add

9) Open MyUserControl and using the Toolbox in Visual studio add the following objects to the User Control Panel:

a. Text: set the text to Coordinates in the Properties dialog b. Textbox: select and check that Modifiers in the properties dialog is set to Public c. Button: set the caption to OK 10) View the code for the User Control. Much of the code has been generated. Add the code snippets in red:

using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Windows.Forms;

using Topobase.Workflows;

namespace MyWorkflow { public partial class MyUserControl : UserControl { private Label label1; private TextBox textBox1; private Button button1;

private WorkflowSupport wfs;

public MyUserControl(WorkflowSupport wfs) { InitializeComponent(); this.wfs = wfs; }

public MyUserControl() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) {

this.wfs.WorkflowExplorerFlyIn.HideUserControls(); }

11) Go back to the MyPlugin.cs script. Add the code in red this.WorkflowSupport.WorkflowExplorerFlyIn.ShowMessage("Please Digitize a point");

Topobase.Graphic.Point point = this.WorkflowSupport.Document.Map.GetPoint("Digitize Point");

MyUserControl form = new MyUserControl(this.WorkflowSupport); form.textBox1.Text = point.X.ToString("F2") + "/" + point.Y.ToString("F2"); this.WorkflowSupport.WorkflowExplorerFlyIn.ShowControl(form);

12) Create and .tbp file

If you want to create your own plugin, you have to create a .dll with one or more plugin classes in it and a .tbp file that tells Autodesk Topobase which plugin classes are implemented and where to find them.

To create a .tbp file, create a new text file and name in MyWorkflow.tbp. Add the following text:

13) Add the .tbp file to you project:

In Visual Studio go to the Solution Explorer panel and right click on MyWorkflow>ADD>Existing Item.

Navigate to your MyWorkflow.tbp file (make sure the file filter is set to All Files) and click Add

Select MyWorkflow.tbp in Solution Explorer and view its properties.

Set Copy To Output Directory as Copy Always

14) Compile the project.

In Solution Explorer right click on either Solution or MyWorkflow and select Buid.

15) Open Administrator and add the new workflow and code:

Call the new workflow something relevant to the task and add the following code

Me.RunMethod("MyWorkflow.dll","MyWorkflow.MyPlugin", "MyWorkflow1")

16) In Map3D, open TB_WA.dwg and run your new workflow

Recommended publications