Saturday, October 14, 2023

AutoCAD API Programming in Visual Basic.Net

vb.net_api


To start API programming for AutoCAD, some softwares needs to be installed.

1. Prerequisites:

Visual Studio:

Install the latest version of Visual Studio. The Community Edition is free and sufficient for this purpose.

AutoCAD .NET API: 

Ensure you have the AutoCAD .NET API installed. This can be found in the AutoCAD ObjectARX SDK. ObjectARX for 2024 version can be downloaded from Autodesk Platform Services Website.

2. Create a New Project:

  • Open Visual Studio.
  • Go to File > New > Project.
  • Choose Class Library (.NET Framework) as the project type but check if it is VB based.
  • Name your project and choose a location to save it.

3. Add References:

  • Right-click on the References node in the Solution Explorer.
  • Choose Add Reference.
  • Browse to the location where the AutoCAD .NET assemblies are located (typically in the AutoCAD installation directory under ./inc).
  • Add references to following files. The files are usually present in folder (C:\Program Files\Autodesk\AutoCAD 20XX\)
    •  AcMgd.dll (This is the main AutoCAD Managed DLL that provides access to the core AutoCAD functionality.)
    • AcDbMgd.dll (This DLL is responsible for database operations in AutoCAD, including working with drawing objects.)
    • AcCoreMgd.dll (This DLL provides access to core AutoCAD services and application initialization.)

In some cases, additional references may be required for some special functions. The additional references are not necessarily to be added to our project. These are following:

    • AcCui.dll (If you're working with custom user interfaces (e.g., ribbon tabs), you'll need it.)
    •  AcWindows.dll (This DLL is needed for Windows-specific functionality within AutoCAD)

For AutoCAD Civil 3D, additional references are required.

    • AeccDbMgd.dll (This DLL provides access to the AutoCAD Civil 3D database and objects. It's specific to Civil 3D)
    • AecBaseMgd.dll (It facilitates database operations and interactions with AEC-specific objects and data within the drawing)
    • AeccPressurePipesMgd.dll (It provides access to networks and pressure pipe networks)

4. Write Your Code:

In the default class file, add the following imports:

Friday, October 13, 2023

AutoCAD and Civil 3D APIs



APIs for Autodesk Autocad and Autodesk Autocad Civil 3d

The AutoCAD API, or Application Programming Interface, is a powerful framework that allows developers to extend and customize AutoCAD software to meet specific needs and workflows. It provides a set of functions, classes, and libraries that enable the creation of custom applications and tools that seamlessly integrate with AutoCAD's core functionality. With the AutoCAD API, developers can automate repetitive tasks, create custom drawing commands, manipulate drawing elements, and interact with various design data, making it an invaluable resource for industries like architecture, engineering, and construction. Whether it's automating complex design processes or enhancing user productivity, the AutoCAD API empowers developers to unlock the full potential of AutoCAD and tailor it to their unique requirements.

 

Choice of Language:

AutoCAD provides APIs (Application Programming Interfaces) for several programming languages to facilitate custom development and automation. Some of the programming languages for which AutoCAD APIs are available include:


AutoLISP: AutoLISP is a dialect of the Lisp programming language that is specifically designed for AutoCAD. It is one of the most widely used languages for customizing AutoCAD.


Visual Basic for Applications (VBA): VBA is an integrated development environment provided by AutoCAD for creating macros and automating tasks. However, note that VBA support has been phased out in recent versions of AutoCAD.


Visual Basic .NET (VB.NET): VB.NET is a modern version of the Visual Basic language that can be used with AutoCAD through its .NET API.


C# (C Sharp): C# is a popular .NET language and is well-supported for creating AutoCAD add-ins and applications.


C++: AutoCAD provides a comprehensive C++ API for creating high-performance custom applications and plugins.


ObjectARX: ObjectARX is a set of C++ libraries provided by Autodesk for building custom AutoCAD applications. It is particularly useful for complex and high-performance applications.


JavaScript: AutoCAD has a JavaScript API that allows you to create web-based applications and interfaces that interact with AutoCAD.

Python: While not officially supported by Autodesk, there are third-party libraries and wrappers, such as pyautocad and PythonNET, that enable Python developers to interact with AutoCAD.


AutoCAD .NET API: This API allows developers to work with AutoCAD using .NET languages like C# and VB.NET, making it easier to integrate AutoCAD functionality into .NET applications.


It's important to note that the availability and features of these APIs may vary depending on the version of AutoCAD you are using. Autodesk continually updates and enhances these APIs with each new release of AutoCAD, so it's essential to refer to the official Autodesk documentation for the specific version you are working with to get the most accurate and up-to-date information on API capabilities and usage.

Here is link to procedure to setup to create your first program in VB.net program for AutoCAD using AutoCAD and Civil 3D api.

Friday, July 7, 2023

Send an email to a list of email addresses using python and Gmail


Before sending emails using Gmail and python, you will need to enable the 2-step Verification.

Enable 2-step Verification:

1. To Enable 2-step Verification in your google account, go to Gmail.

2. Click on the "profile picture" > "Manage your Google Account"  in top right corner.


3. Now you will be taken to the Settings Screen. On left hand of this screen, there are various options. Click on Security from Left side Tab and scroll down to "How you sign in to Google". 

4. Click on the Arrow to right side of 2-step Then click and Enable the "2-step Verification". It may ask you for your Google account's password for confirmation.

5. Once you have enabled 2-step Verification, scroll down to "App passwords" and under the "App password", click on the arrow to right.


6. Now you will able to create passwords for your Apps. After clicking on the arrow, you will taken to following screen.

7. Here, you will select "Mail" from drop down menu in "Select App" box.

8.  Select "Other" from drop down menu of "Select device".


9. Now enter a custom name for your app in the window shown below and click on "Generate" button to create a password for your custom app.

 

10. Copy and save the password shown in the next window in a text file or where-ever you like. This password will be used in our python code as password to login into your Gmail account.


Code to send Emails:

The following code will send emails to the group separated by a time of 40+ seconds.

Note:
The program contains a list named "mail_list" to send emails to each of these. You can replace them with your own list of emails. A file named "file.txt" is also attached to the email. This 'file.txt' can be changed to any file with allowable size.

You will replace the "from@sender.com" with your own Gmail address and 'password' with password obtained in step 10.

Replace 'Email Subject' with your own email subject and 'email body text' with your email body text. For 'email body text', \n may be inserted to write to a new line.

Since all of the above mentioned changes are in string format, so they should be enclosed in ' ' to keep them in string format.

import smtplib
from email import encoders
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import time

mail_list = ['example1@domain1.com',
             'example2@domain1.com',
             'example3@domain1.com']

for rec_email in mail_list:
    sender_email = "from@sender.com"
    sender_password = 'password'
    recipient_email = rec_email
   
    subject = 'Email Subject'
    body = 'email body text'
   
    attachmentFile = 'file.txt'
    with open(attachmentFile, "rb") as attachment:
       
        # Adding the attachment
        part = MIMEBase("application", "octet-stream")
        part.set_payload(attachment.read())
    encoders.encode_base64(part)
    part.add_header(
        "Content-Disposition",
        f"attachment; filename = {attachmentFile}",
    )

    message = MIMEMultipart()
    message['Subject'] = subject
    message['From'] = sender_email
    message['To'] = recipient_email
    html_part = MIMEText(body)
    message.attach(html_part)
    message.attach(part)

    with smtplib.SMTP_SSL('smtp.gmail.com', 465) as server:
            try:
                server.login(sender_email, sender_password)
                server.sendmail(sender_email,
                                recipient_email, message.as_string())
            except Exception as e:
                print(getattr(e, 'message', repr(e)))
    print(f'sent to {recipient_email}')
    #wait for 40+ seconds before sending second email
    time.sleep(40 + (random.randint(0,9)))




Thursday, April 20, 2023

Traffic Impact Study

 

With time, new development and re-development in various areas of a city or township or even rural areas takes place. These developments may cause further traffic burden on the existing traffic, thereby, causing traffic congestion in the area. Based on the Traffic Impact Assessment, improvement in roadway is identified so that traffic operations in that area remains safe and efficient upon completion of the project. 

The traffic impact study should remain objective assessment (means must be carried out at later stage when required) and should not merely act as means of getting approvals for planning and construction activities of the development.

The cost of these improvements is borne by the developer in form of either cash paid to local authorities or the developer approves drawings of the development from local authorities and construct the required improvement to prevent the wastage of public tax money.

The traffic Impact Assessment shall be mandatory carried out for commercial areas, institutional areas, residential societies, industrial areas during planning and approval stage of the proposed development. Small developments such as houses have very little impact on the existing traffic and can be usually be ignored.


 Example: For above development, the five identified points will need to be analyzed

WHAT IS INCLUDED IN TRAFFIC IMPACT STUDY? 

Traffic Impact Study should contain but not limited to following sections:

  • Description of the Project (site plan including subdivisions if applicable) 
  • Identification of Study Area (map showing study site and area) 
  • Horizon Year and Time Period (usually 25-year or 50-year) for Analysis 
  • Existing Traffic Conditions
  • Background Traffic Demand – Existing traffic and its projection in Future
  • Site Generated Traffic Demands – for current year and its projection in future
  • Total Traffic Demand – summation of traffic from above 2.
  • Evaluation of Impacts of Site Generated Traffic
  • Analysis of feasible Location of Access to site 
  • Alternatives required for Mitigation of Traffic Impact

a.      Traffic impact for background traffic (future case)

b.      Traffic impact for total traffic

                                                    i.     Without mitigation

                                                   ii.     With mitigation

  • Recommendations

CLASSIFICATION

Traffic impact studies are classified into two types:

Traffic Impact Assessment

It deals with interaction of traffic generated by development with road network and intersections on the road.

Traffic Impact Statement

It deals with access/exit of development, internal road network within development and parking details as per guidelines.

 SOFTWARES

Various softwares such as Autodesk Infraworks, Trafficware SynchroTransModeler and PTV Vissim & PTV Visum may be used for studying the various scenarios.

 

Sunday, April 9, 2023

Creating Alignment Using AutoCAD Civil 3D

 

AutoCAD Civil 3D is industry's top software by Autodesk for various types of engineering projects such as roads, highways, motorways, stormwater sewer, sanitary sewer etc. These projects can be classified as Infrastructure projects.

 An Alignment is a Civil 3D entity in two dimension and describes centerline of road or pipe. It's important to create an alignment accurately, as it determines the final layout of the project.

In this article, we will briefly discuss the various options available in autoCAD Civil 3D for creating of Alignments.

Creating an Alignment:

To create an alignment, follow these steps:

  • Open the AutoCAD Civil 3D software and click on the Home > Create Design > Alignment button.

Alignment Command

  • It will open a menu as shown below:

Alignment Creation Menu

  • This menu contains various options for creating an Alignment. I have numbered these options from 1 to 10. Let me describe these one by one briefly.
  • Alignment Creation Tools

It is used to create New Alignment using Tangents and Curves from scratch. It prompts for creation of Tangents and Curves with different options. Also compare it with Create Alignment from Objects.

 This is one of the most frequently used option.

  • Create Best Fit Alignment

If your alignment is very simple alignment and regression equations can be used to describe geometry of your Alignment. Otherwise, you will need to split up your alignment into smaller parts and use the "Create Best Fit Alignment" option. 

  • Create Alignment from Objects

This option can be used to create Alignment from other objects such as Polyline, 3D polylines and Feature lines already created in the drawing. It is also one of the most frequently used options used to create alignments.

  • Create Alignment from Corridor

In certain cases, Alignment needs to be created from feature lines of a corridor. This option will create alignment from feature line of a corridor. 

  • Create Alignment from Network Parts

To represent Network parts on a profile, an alignment will be created so that we can draw its profile and project the network parts on that profile. Further labels can be added to the profile. 

  • Create Alignment from Pressure Network

This option is same as Network Parts but will create Alignment from Pressure Network parts.

  • Create Alignment from Existing Alignment

This option can be used to create Alignment from existing Alignment. 

  • Create Offset Alignments

Offset Alignments are created for various functions such as widening.

  • Create Connected Alignment

Connected alignment can be created using this option. It will associate the alignment with each other at the intersection point and their profile at intersection point will have same elevation. These profiles can be raised or lowered at the same time. It comes handy in creation of intersections.

  • Create Widening

It also creates an offset alignment will widening options.

  Further details of each option can be checked on Autodesk website.

Sunday, March 26, 2023

Roads Planning, Design, Construction and Maintenance

In this modern day world, roads network play major roles in economy of a country as everyday transportation of passengers and goods depends on it. A good network of roads will provide efficient and cheap accessibility to everyone and everywhere. The environmental factors such as noise and air pollution caused due to road networks, however, cannot be ignored. It is therefore, very important that road networks shall be properly planned.


Step 0: Planning of Roads
  • Identify the available routes and new routes between locations
  • Determine the population served by each route
  • Determine the rough cost of each route
  • Determine the traffic impact caused by each new route
  • Identify the most feasible case.

Step 1: Topographic Survey
  • Determine the area to be surveyed
  • Create a survey plan outlining survey boundaries and specific areas of interest
  • Establish control points and benchmarks for the survey
  • Conduct field work to collect data, including elevations, locations of existing features (such as trees, buildings, and waterways), and geotechnical information
  • Use survey equipment such as total stations, GPS units, and/or LiDAR technology to collect data
  • Process the collected data and create a topographic map

Step 2: Preliminary Design
  • Use the topographic map to create a preliminary road alignment
  • Consider factors such as terrain, drainage, existing infrastructure, and environmental impacts when designing the road
  • Conduct geotechnical investigations to determine soil conditions and identify any potential issues that may affect the design
  • Consider safety features such as guardrails, barriers, and signage
  • Estimate the costs associated with the preliminary design

Thursday, March 23, 2023

Pre-Development and Post-Development Stormwater Analysis


Development can have a significant impact on stormwater drainage in an area. The quantity of land available for water to infiltrate into the soil is decreased when natural surfaces like bare ground or grass land are converted to impermeable surfaces like highways, buildings, and parking lots. This can lead to higher runoff during rain events. Flooding, erosion, and property and infrastructure damage may result from this.

Additionally, because development alters the hydrological regime also known as amount and speed of water flowing, it may have an impact on downstream flooding. The amount and speed of water flowing into streams and rivers thus rises along due to increased runoff. As a result, flooding may occur downstream of the built region and stream flows may increase.

Downstream flooding can also be largely caused by the decrease in floodplain storage capacity as a result of development. Natural floodplains have the capacity to temporarily store floodwaters, minimising their effects downstream. Development in flood-prone areas, however, may result in the loss of these natural floodplain storage areas, reducing their capacity to lessen the effects of downstream flooding.

Stormwater management techniques like low-impact development, green infrastructure, and various types of stormwater detention ponds can be used to mitigate these effects. Through encouraging infiltration, evapotranspiration, and the natural treatment of stormwater runoff, these measures work to control the volume and velocity of runoff. By limiting direct runoff of stormwater, these strategies can reduce the likelihood of infrastructure and property damage both locally and further downstream. It can also help in prevent flooding, and protect water quality.
Increased development without mitigation measures can cause flooding in the downstream areas as we have witnessed recently during several events in Pakistan.

ESSENTIAL STEPS TO CARRY OUT STORM WATER ANALYSIS

Before carrying out stormwater analysis, it is essential to collect baseline data on the existing conditions in the area. This data can be used to assess the potential impacts of development on stormwater runoff and design appropriate stormwater management strategies.

The following are the steps to carry out stormwater analysis before and after development:

1. Collect existing data: 

Collect existing data on the area such as topography, land use, soil type, vegetation cover, hydrology, and climate.