Exemplo n.º 1
0
        private bool DrawCircle(CircleArgs circleArgs)
        {
            Database db  = HostApplicationServices.WorkingDatabase;
            Document doc = Application.DocumentManager.GetDocument(db);

            using (DocumentLock l = doc.LockDocument())
            {
                try
                {
                    using (Transaction tr = db.TransactionManager.StartTransaction())
                    {
                        BlockTableRecord model = tr.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForWrite) as BlockTableRecord;

                        Circle c = new Circle();
                        c.Center = new Autodesk.AutoCAD.Geometry.Point3d(circleArgs.X, circleArgs.Y, circleArgs.Z);
                        c.Radius = circleArgs.Radius;
                        c.SetDatabaseDefaults(db);

                        model.AppendEntity(c);
                        tr.AddNewlyCreatedDBObject(c, true);

                        tr.Commit();
                    }

                    ActionMessage.Append("Cicle has been added into drawing successfully.");
                    return(true);
                }
                catch (Exception ex)
                {
                    ActionMessage.Append("Drawing circle failed:\n" + ex.Message + "\n" + ex.InnerException.Message);
                    return(false);
                }
            }
        }
Exemplo n.º 2
0
        public HttpResponseMessage Put(CircleArgs circleArgs)
        {
            ActionMessage.Length = 0;
            HttpStatusCode code = HttpStatusCode.Created;

            if (circleArgs == null)
            {
                code = HttpStatusCode.ExpectationFailed;
                ActionMessage.Append("Circleargs argument is not supplied.");
            }
            else
            {
                if (!DrawCircle(circleArgs))
                {
                    code = HttpStatusCode.ExpectationFailed;
                }
            }

            if (code != HttpStatusCode.Created)
            {
                return(Request.CreateErrorResponse(code, ActionMessage.ToString()));
            }
            else
            {
                return(Request.CreateResponse <string>(code, ActionMessage.ToString()));
            }
        }
Exemplo n.º 3
0
        public HttpResponseMessage Put([FromBody] AcadSysVar sysVar)
        {
            ActionMessage.Length = 0;
            HttpStatusCode code = HttpStatusCode.Accepted;

            if (sysVar == null)
            {
                code = HttpStatusCode.ExpectationFailed;
                ActionMessage.Append("SysVar argument is not supplied.");
            }
            else
            {
                if (!UpdateSystemVariable(sysVar))
                {
                    code = HttpStatusCode.ExpectationFailed;
                }
            }

            if (code != HttpStatusCode.Accepted)
            {
                return(Request.CreateErrorResponse(
                           code, ActionMessage.ToString()));
            }
            else
            {
                return(Request.CreateResponse <string>(
                           code, ActionMessage.ToString()));
            }
        }
Exemplo n.º 4
0
 private bool UpdateSystemVariable(AcadSysVar sysVar)
 {
     try
     {
         Database db  = HostApplicationServices.WorkingDatabase;
         Document doc = Application.DocumentManager.GetDocument(db);
         using (DocumentLock l = doc.LockDocument())
         {
             Application.SetSystemVariable(sysVar.Name, sysVar.Value);
         }
         ActionMessage.Append(
             "System variable \"" + sysVar.Name +
             "\" is updated successfully.");
         return(true);
     }
     catch (System.Exception ex)
     {
         ActionMessage.Append(
             "Setting system variable \"" + sysVar.Name +
             "\" failed:\n" + ex.Message);
         return(false);
     }
 }