snippets with tag '.NET'

.NET : Launch Autocad from a .NET applicationThis code in C# .NET launch AutoCAD from an application, and handle the process to interact with it.
public static void Launch_Autocad()
        {
            // "AutoCAD.Application.16.2" uses 2006
            // "AutoCAD.Application.17" uses 2007 or 2008, whichever was most recently run
            // "AutoCAD.Application.17.1" uses 2008, specifically
            // "AutoCAD.Application.18" uses 2010

            const string progID = "AutoCAD.Application.17.1";

            AcadApplication acApp = null;
            try
            {
                acApp = (AcadApplication)Marshal.GetActiveObject(progID);
            }
            catch
            {
                try
                {
                    Type acType = Type.GetTypeFromProgID(progID);
                    acApp = (AcadApplication)Activator.CreateInstance(acType, true);
                }
                catch
                {
                    MessageBox.Show("Cannot create object of type \"" +progID + "\"");
                }
            }
            if (acApp != null)
            {
                try
                {
                    // By the time this is reached AutoCAD is fully
                    // functional and can be interacted with through code
                    acApp.Visible = true;

                   //Here you can call AutoCAD functions or interact with a dll based on OBJECTARX and COM registered

                }
                catch (System.Exception ex)
                {
                    MessageBox.Show("Problem executing component: " + ex.Message);
                }
            }
        }
tags : .NET

.NET : Get the intersection point of 2 segments(x1, y1) / (x2, y2) are the 2 points defining the first segment (x3, y3) / (x4, y4) are the 2 points defining the second segment
        private static string Get_Intersect_Point(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
        {
            double x;
            double y;
            
            double denominateur = ((y4 - y3)*(x2 - x1)) - ((x4 - x3)*(y2 - y1));
            double nominateur_1 = ((x4 - x3)*(y1 - y3)) - ((y4 - y3)*(x1 - x3));
            double nominateur_2 = ((x2 - x1)*(y1 - y3)) - ((y2 - y1)*(x1 - x3));
   
            //Check if the segments have a unique common point
            if (denominateur == 0 | nominateur_1 == 0 | nominateur_2 == 0)
                return "Colinear or Paralelle";

            //Get the coordonates of the common point
            double ua = nominateur_1 / denominateur;
            double ub = nominateur_2 / denominateur;

            if(ua >= 0.0f && ua <= 1.0f && ub >= 0.0f && ub <= 1.0f)
            {
                // Get the intersection point
                x = x1 + ua*(x2 - x1);
                y = y1 + ua*(y2 - y1);
                return "X = " + x + " and Y = " + y;
            }

            return "No intersection point";
        }
tags : .NET

all tags : python, system, vlc, video, apache, proxy, linux, django, MySQL, .NET, XML, XSL, regexp, bat, windows, bash, git

back to snippets home
site réalisé et hébergé par revolunet © 2009 - informations légales