I want to define the ‘Select Object’ command as a function using Civil3D Dynamo Python script.
Because I want to create a User Interface using the WindowsForm module in my Dynamo script, I plan to utilize various types of input parameters like buttons, browser buttons, etc. Particularly, I want to enhance the script so that when a polyline (object) is selected from the current drawing through the User Interface, that object is outputted. This part is quite challenging for me. I would be very grateful if you could suggest a method related to this.
# Load the Python Standard and DesignScript Libraries
import sys
import clr
# Add Assemblies for AutoCAD and Civil3D
clr.AddReference('AcMgd')
clr.AddReference('AcCoreMgd')
clr.AddReference('AcDbMgd')
clr.AddReference('AecBaseMgd')
clr.AddReference('AecPropDataMgd')
clr.AddReference('AeccDbMgd')
clr.AddReference('System.Windows.Forms')
clr.AddReference('System.Drawing')
# Import references from AutoCAD
from Autodesk.AutoCAD.Runtime import *
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.EditorInput import *
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.AutoCAD.Geometry import *
# Import references from Civil3D
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *
from System.Windows.Forms import Application, Form, Label, Button, DialogResult
from System.Drawing import Size, Point
from System.Windows.Forms import TextBox
from System.Windows.Forms import OpenFileDialog
from Autodesk.AutoCAD.EditorInput import PromptEntityOptions, PromptEntityResult
# The inputs to this node will be stored as a list in the IN variables.
global userInput, fileInput
userInput = None
fileInput = None
class MyForm(Form):
def __init__(self):
self.Text = 'DHBIM'
self.Size = Size(700, 400)
self.outputLabel = Label()
self.outputLabel.Location = Point(10, 70)
self.outputLabel.Size = Size(280, 20)
self.Controls.Add(self.outputLabel)
self.label = Label()
self.label.Text = '설계유량(m3/day):'
self.label.Location = Point(10, 15)
self.label.Size = Size(180, 30)
self.Controls.Add(self.label)
self.textBox = TextBox()
self.textBox.Location = Point(200, 10)
self.textBox.Size = Size(150, 20)
self.Controls.Add(self.textBox)
self.label = Label()
self.label.Text = '관경별 공사비:'
self.label.Location = Point(10, 100)
self.label.Size = Size(180, 30)
self.Controls.Add(self.label)
self.browseButton = Button()
self.browseButton.Text = '찾아보기'
self.browseButton.Location = Point(200,100)
self.browseButton.Click += self.on_browse_click
self.browseButton.Size = Size(100, 40) # '찾아보기' 버튼 크기 설정
self.Controls.Add(self.browseButton)
self.button = Button()
self.button.Text = '확인'
self.button.Location = Point(200, 300)
self.button.Click += self.on_button_click
self.button.Size = Size(100, 30) # '확인' 버튼 크기 설정
self.Controls.Add(self.button)
def on_browse_click(self, sender, args):
fileDialog = OpenFileDialog()
if fileDialog.ShowDialog() == DialogResult.OK:
global fileInput
fileInput = fileDialog.FileName
def on_button_click(self, sender, args):
global userInput
userInput = self.textBox.Text
self.Close() # 폼을 닫습니다
Application.EnableVisualStyles()
form = MyForm()
Application.Run(form)
OUT = [userInput, fileInput] if userInput is not None and fileInput is not None else "No Input"```
I appreciate your helpful response, and I’m grateful for your efforts. However, I have no programming background, so I’m finding it difficult to update my user interface solely with the Dynamo script you’ve shared. I’m really sorry to ask, but could you share the complete script that produces results like the ones shown in the second image?
I will study based on the script you shared and try to apply it in various ways. I don’t know how to repay your kindness…I’m so grateful. I will study hard and test to see if other types of input are possible as well. Can I ask for your help if I have more questions? ^^