public ResultBuffer RubyLoadLISP(ResultBuffer rb)
        {
            const int RTSTR = 5005;

              Document doc = Application.DocumentManager.MdiActiveDocument;
              Editor ed = doc.Editor;

              if (rb == null)
              {
            ed.WriteMessage("\nError: too few arguments\n");
              }
              else
              {
            Array args = rb.AsArray();
            TypedValue tv = (TypedValue)args.GetValue(0);

            if (tv != null && tv.TypeCode == RTSTR)
            {
              bool success =
            ExecuteRubyScript(Convert.ToString(tv.Value));
              return
            (success
              ? new ResultBuffer(new TypedValue(RTSTR, tv.Value))
              : null);
            }
              }
              return null;
        }
        public int MyLispFunction(ResultBuffer args)
        {
            // Put your command code here

            // Return a value to the AutoCAD Lisp Interpreter
            return 1;
        }
Beispiel #3
0
        //[CommandMethod("EllipseJigWait")]
        public static bool EllipseJigWait()
        {
            ResultBuffer rb = new ResultBuffer();
            //RTSTR = 5005
            rb.Add(new TypedValue(5005, "_.ELLIPSE"));
            //Start the command
            acedCmd(rb.UnmanagedObject);

            bool quit = false;
            //loop round while the command is active
            while (!quit)
            {
                //see what commands are active
                string cmdNames = (string)Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("CMDNAMES");
                //if the command is active
                if (cmdNames.ToUpper().IndexOf("ELLIPSE") >= 0)
                {
                    rb = new ResultBuffer();
                    //RTSTR = 5005 - send user pause
                    rb.Add(new TypedValue(5005, "\\"));
                    acedCmd(rb.UnmanagedObject);
                }
                else
                {
                    quit = true;
                }
            }
            return quit;
        }
        public static TypedValue ProxyExplodeToBlock(ResultBuffer rbArgs)
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;

            TypedValue res = new TypedValue((int)LispDataType.Text,"");

            if (rbArgs.AsArray().Length == 2)
            {
                TypedValue entity = rbArgs.AsArray()[0];
                TypedValue blkPrefix = rbArgs.AsArray()[1];

                if ((entity.TypeCode == (int)LispDataType.ObjectId) && (blkPrefix.TypeCode == (int)LispDataType.Text))
                {
                    using (Transaction tr = doc.TransactionManager.StartTransaction())
                    {
                        try
                        {
                            ObjectId id = (ObjectId)entity.Value;
                            DBObjectCollection objs = new DBObjectCollection();
                            BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);

                            Entity entx = (Entity)tr.GetObject(id, OpenMode.ForWrite);
                            entx.Explode(objs);

                            string blkName = blkPrefix.Value.ToString() + entx.Handle.ToString();

                            if (bt.Has(blkName) == false)
                            {
                                BlockTableRecord btr = new BlockTableRecord();
                                btr.Name = blkName;

                                bt.UpgradeOpen();
                                ObjectId btrId = bt.Add(btr);
                                tr.AddNewlyCreatedDBObject(btr, true);

                                foreach (DBObject obj in objs)
                                {
                                    Entity ent = (Entity)obj;
                                    btr.AppendEntity(ent);
                                    tr.AddNewlyCreatedDBObject(ent, true);
                                }
                            }
                            res = new TypedValue((int)LispDataType.Text, blkName);

                            tr.Commit();
                        }
                        catch (Autodesk.AutoCAD.Runtime.Exception ex)
                        {
                            tr.Abort();
                            ed.WriteMessage(ex.Message);
                        }
                    }
                }
            }
            return res;
        }
 public static PromptStatus SendBuffer(this Editor ed, ResultBuffer rb)
 {
     using (rb)
     {
         int status = acedCmd(rb.UnmanagedObject);
         if (status == -5002) return PromptStatus.Cancel;
         return ((status == 5100) ? PromptStatus.OK : PromptStatus.Error);
     }
 }
        public static void ProxyExplodeInPlace(ResultBuffer rbArgs)
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;

            if (rbArgs.AsArray().Length == 1)
            {
                TypedValue entity = rbArgs.AsArray().First();

                if (entity.TypeCode == (int)LispDataType.ObjectId)
                {
                    using (Transaction tr = doc.TransactionManager.StartTransaction())
                    {
                        try
                        {
                            ObjectId id = (ObjectId)entity.Value;
                            DBObjectCollection objs = new DBObjectCollection();
                            BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);

                            Entity entx = (Entity)tr.GetObject(id, OpenMode.ForWrite);
                            entx.Explode(objs);

                            entx.Erase();

                            BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);

                            foreach (DBObject obj in objs)
                            {
                                Entity ent = (Entity)obj;
                                btr.AppendEntity(ent);
                                tr.AddNewlyCreatedDBObject(ent, true);
                            }

                            tr.Commit();
                        }
                        catch (Autodesk.AutoCAD.Runtime.Exception ex)
                        {
                            tr.Abort();
                            ed.WriteMessage(ex.Message);
                        }
                    }
                }
            }
        }
            public static ResultBuffer StreamToResBuf(
                Stream ms, string appName)
            {
                var resBuf = new ResultBuffer(
                    new TypedValue(
                        (int)DxfCode.ExtendedDataRegAppName, appName));

                for (var i = 0; i < ms.Length; i += KMaxChunkSize)
                {
                    var length    = (int)Math.Min(ms.Length - i, KMaxChunkSize);
                    var datachunk = new byte[length];
                    ms.Read(datachunk, 0, length);
                    resBuf.Add(
                        new TypedValue(
                            (int)DxfCode.ExtendedDataBinaryChunk, datachunk));
                }

                return(resBuf);
            }
Beispiel #8
0
        public static void WriteToNod(ProfileObject obj)
        {
            Editor      ed    = Application.DocumentManager.MdiActiveDocument.Editor;
            Transaction trans = Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction();

            using (trans)
            {
                if (!AppDictionary.IsWriteEnabled)
                {
                    AppDictionary.UpgradeOpen();
                }

                //create new Xrecord
                Xrecord xrecord = new Xrecord();
                //create the resbuf list
                ResultBuffer data = new ResultBuffer(new TypedValue((int)DxfCode.Text, obj.NodKey),
                                                     new TypedValue((int)DxfCode.Int64, obj.DistanceAtCrossing),
                                                     new TypedValue((int)DxfCode.Text, obj.Layer),
                                                     new TypedValue((int)DxfCode.Text, obj.LineType),
                                                     new TypedValue((int)DxfCode.Int32, obj.Depth));
                //add data to new record
                xrecord.Data = data;

                //create the entry to nod
                AppDictionary.SetAt(obj.NodKey, xrecord);

                try
                {
                    //add to transaction, if exist then handle in catch
                    trans.AddNewlyCreatedDBObject(xrecord, true);
                }
                catch
                {
                    //what todo when xrecord already exists
                }

                //all ok then commit
                trans.Commit();

                //increment object counter
                Count++;
            }
        }
Beispiel #9
0
        public void Insert()
        {
            //ed.writeMessage("Insert Sub \n");
            Database db = Application.DocumentManager.MdiActiveDocument.Database;

            using (DocumentLock docLock = Application.DocumentManager.MdiActiveDocument.LockDocument())
            {
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    DBObject dbObject = tr.GetObject(SelectedObjectId, OpenMode.ForRead);

                    if (dbObject.ExtensionDictionary == ObjectId.Null)
                    {
                        dbObject.UpgradeOpen();

                        dbObject.CreateExtensionDictionary();
                    }

                    Xrecord xrec = new Xrecord();

                    ResultBuffer rb = new ResultBuffer();

                    int i = 0;
                    foreach (ObjectId id in SubIdCollection)
                    {
                        //rb.Add(new TypedValue((int)DxfCode.SoftPointerId + i, id));
                        rb.Add(new TypedValue((int)DxfCode.HardPointerId + i, id));
                        i++;
                    }

                    xrec.Data = rb;

                    DBDictionary extDict = (DBDictionary)tr.GetObject(dbObject.ExtensionDictionary, OpenMode.ForWrite);

                    extDict.SetAt("AT_SUB", xrec);

                    tr.AddNewlyCreatedDBObject(xrec, true);

                    tr.Commit();
                }
            }
            //ed.writeMessage("Insert Sub finished \n");
        }
Beispiel #10
0
        public void HideAllTriangulate()
        {
            Triangulations  triangulation = new Triangulations();
            AC_Transactions tr            = new AC_Transactions();
            Transaction     trans         = tr.start_Transaction();

            tr.openBlockTables(OpenMode.ForRead, OpenMode.ForRead);
            foreach (ObjectId id in tr.AC_blockTableRecord)
            {
                try{
                    AC_Entity ent = (AC_Entity)tr.openObjectErased(id);
                    if (ent.BaseEntity is Line)
                    {
                        AC_Line      line = (AC_Line)ent;
                        ResultBuffer rb   = line.XData;
                        if (rb != null)
                        {
                            //FIND XDATA GUID
                            int    index = 0;
                            string guid  = null;
                            foreach (TypedValue tv in rb)
                            {
                                if (index == 3)
                                {
                                    guid = tv.Value.ToString();
                                }
                                index++;
                            }

                            if (guid != null)
                            {
                                triangulation.Hide(line);
                            }
                        }
                    }
                    tr.Dispose(trans);
                }
                catch
                {
                    tr.AC_Doc.Editor.WriteMessage("Skipped a not Entity Object");
                }
            }
        }
Beispiel #11
0
    public static void AttachXData(this DBObject obj, string app, IEnumerable <TypedValue> datas, Database db = null)
    {
        db = (db ?? Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument.Database);
        if (GetSymbol(db.RegAppTableId, app, db) == ObjectId.Null)
        {
            ToTable(new RegAppTableRecord
            {
                Name = app
            }, db.RegAppTableId, db);
        }
        ResultBuffer rb = new ResultBuffer();

        rb.Add(new TypedValue(1001, app));
        foreach (TypedValue data in datas)
        {
            rb.Add(data);
        }
        obj.XData = rb;
    }
Beispiel #12
0
 public static Ballon ReadBallonFromBuffer(ResultBuffer buffer)
 {
     try
     {
         Ballon       bal   = new Ballon();
         TypedValue[] rvArr = buffer.AsArray();
         bal.LayerName   = (string)rvArr[1].Value;
         bal.Angle       = (double)rvArr[2].Value;
         bal.Length      = (double)rvArr[3].Value;
         bal.Radius      = (double)rvArr[4].Value;
         bal.ColorIndex  = (int)rvArr[5].Value;
         bal.StringInput = (string)rvArr[6].Value;
         return(bal);
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
Beispiel #13
0
 /// <summary>
 /// Удаление XData связанных с этим приложением
 /// </summary>
 /// <param name="dbo"></param>
 /// <param name="regAppName"></param>
 public static void RemoveXData([NotNull] this DBObject dbo, string regAppName)
 {
     if (dbo.GetXDataForApplication(regAppName) != null)
     {
         var rb             = new ResultBuffer(new TypedValue(1001, regAppName));
         var isWriteEnabled = dbo.IsWriteEnabled;
         if (!isWriteEnabled)
         {
             using (var dboWrite = dbo.Id.Open(OpenMode.ForWrite, false, true))
             {
                 dboWrite.XData = rb;
             }
         }
         else
         {
             dbo.XData = rb;
         }
     }
 }
Beispiel #14
0
        private void ReplaceXData(ResultBuffer rb)
        {
            if (rb != null)
            {
                Document doc = Application.DocumentManager.MdiActiveDocument;

                Transaction tr = doc.TransactionManager.StartTransaction();
                using (tr)
                {
                    DBObject obj     = tr.GetObject(this.id, OpenMode.ForWrite);
                    string   appName = rb.AsArray()[0].Value.ToString();
                    if (appName2values.ContainsKey(appName))
                    {
                        obj.XData = rb;
                    }
                    tr.Commit();
                }
            }
        }
Beispiel #15
0
        public ResultTree(ResultBuffer rb)
        {
            ResultTree rt = this;

            foreach (TypedValue tv in rb)
            {
                ResultTree trt;
                switch (GetNodeType(tv, out trt))
                {
                case ResultNodeType.LogicalOperator:
                case ResultNodeType.RelationalOperatorBegin:
                case ResultNodeType.ListBegin:
                    rt = rt.Add(trt);
                    break;

                case ResultNodeType.DottedPairEnd:
                    rt._treeType = ResultTreeType.DottedPair;
                    rt           = rt._owner;
                    break;

                case ResultNodeType.RelationalOperatorEnd:
                case ResultNodeType.ListEnd:
                    rt = rt._owner;
                    break;

                default:
                    rt.Add(trt);
                    if (rt._treeType == ResultTreeType.RelationalOperator)
                    {
                        rt = rt._owner;
                    }
                    break;
                }
            }
            if (_lst.Count == 1)
            {
                rt = _lst[0];
                _lst.Remove(rt);
                _lst.AddRange(rt);
                _treeType   = rt._treeType;
                _typedValue = rt._typedValue;
            }
        }
Beispiel #16
0
        /// <summary> 清除 XData 中的数据 </summary>
        /// <param name="sectionCenter"> 调用此方法前必须确保直线的写入权限已打开 </param>
        /// <param name="clearAll">如果其值为 true,则<paramref name="type"/>值不起作用</param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static void ClearValue(Line sectionCenter, bool clearAll, InfoType type = InfoType.General)
        {
            ResultBuffer buff = null;

            if (clearAll)
            {
                // 错误方法
                buff = new ResultBuffer(
                    new TypedValue((int)DxfCode.ExtendedDataRegAppName, AppNameGeneral),
                    new TypedValue((int)DxfCode.ExtendedDataRegAppName, AppNameLeft),
                    new TypedValue((int)DxfCode.ExtendedDataRegAppName, AppNameRight));
                sectionCenter.XData = buff;

                // 如果要删除多个 ExtendedDataRegAppName 区域,必须多次对 XData 进行赋值操作,而不能一次性进行多个区域的赋值,后者的操作只会将最后一个区域清除。
                buff = new ResultBuffer(new TypedValue((int)DxfCode.ExtendedDataRegAppName, AppNameGeneral));
                sectionCenter.XData = buff;
                buff = new ResultBuffer(new TypedValue((int)DxfCode.ExtendedDataRegAppName, AppNameLeft));
                sectionCenter.XData = buff;
                buff = new ResultBuffer(new TypedValue((int)DxfCode.ExtendedDataRegAppName, AppNameRight));
                sectionCenter.XData = buff;

                // 此时,Entity中的XData集合里,对应AppName下的所有数据,连同AppName这一项本身,都在实体中删除了。
                // 但是此AppName在 RegAppTable 中对应的 RegAppTableRecord 定义还是存在的。
            }
            else
            {
                switch (type)
                {
                case InfoType.General:
                    buff = new ResultBuffer(new TypedValue((int)DxfCode.ExtendedDataRegAppName, AppNameGeneral));
                    break;

                case InfoType.Left:
                    buff = new ResultBuffer(new TypedValue((int)DxfCode.ExtendedDataRegAppName, AppNameLeft));
                    break;

                case InfoType.Right:
                    buff = new ResultBuffer(new TypedValue((int)DxfCode.ExtendedDataRegAppName, AppNameRight));
                    break;
                }
                sectionCenter.XData = buff;
            }
        }
Beispiel #17
0
        replacePntXData(CogoPoint cogoPnt, CogoPoint cogoPntX, Polyline3d poly3d)
        {
            try
            {
                ResultBuffer  RB0     = poly3d.ObjectId.getXData(apps.lnkBrks);
                List <Handle> handles = RB0.rb_handles();     //get list of unique non Zero handles

                int i = handles.IndexOf(cogoPnt.Handle);
                handles.RemoveAt(i);
                handles.Insert(i, cogoPntX.Handle);

                poly3d.ObjectId.clearXData(apps.lnkBrks);
                poly3d.ObjectId.setXData(handles, apps.lnkBrks3);
            }
            catch (System.Exception ex)
            {
                BaseObjs.writeDebug(ex.Message + " xData.cs: line: 624");
            }
        }
Beispiel #18
0
        public WallSegmentold(string Name, Plot parent, ObjectId centreline)
        {
            this.Parent = parent;
            this.Name   = Name;
            ObjectId    = centreline;

            //Establish links
            Document acDoc   = Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;

            //FoundationWidth = acDoc.GetDocumentStore<CivilDocumentStore>().DefaultWidth;

            using (Transaction tr = acCurDb.TransactionManager.StartTransaction())
            {
                DBObject dbObj = tr.GetObject(centreline, OpenMode.ForRead);

                ObjectId extId = dbObj.ExtensionDictionary;

                if (extId == ObjectId.Null)
                {
                    dbObj.UpgradeOpen();
                    dbObj.CreateExtensionDictionary();
                    extId = dbObj.ExtensionDictionary;
                }

                //now we will have extId...
                DBDictionary dbExt = (DBDictionary)tr.GetObject(extId, OpenMode.ForWrite);

                Xrecord      xRec = new Xrecord();
                ResultBuffer rb   = new ResultBuffer();
                rb.Add(new TypedValue((int)DxfCode.ExtendedDataAsciiString, Parent.PlotName));
                rb.Add(new TypedValue((int)DxfCode.ExtendedDataAsciiString, this.Name));

                //set the data
                xRec.Data = rb;

                dbExt.SetAt("JPP_Plot", xRec);
                tr.AddNewlyCreatedDBObject(xRec, true);

                tr.Commit();
            }
        }
Beispiel #19
0
        /// <summary>
        /// Op-Intersect operation.
        /// </summary>
        /// <param name="args">
        ///            Result from the expressions evaluation. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of operation. </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.api.ResultSequence op_intersect(java.util.Collection args) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence op_intersect(ICollection args)
        {
            ResultBuffer rs = new ResultBuffer();

            // convert arguments
            ICollection cargs = Function.convert_arguments(args, expected_args());

            // get arguments
            IEnumerator iter = cargs.GetEnumerator();

            iter.MoveNext();
            ResultSequence one = (ResultSequence)iter.Current;

            iter.MoveNext();
            ResultSequence two = (ResultSequence)iter.Current;

            // XXX lame
            for (var i = one.iterator(); i.MoveNext();)
            {
                NodeType node  = (NodeType)i.Current;
                bool     found = false;

                // death
                for (var j = two.iterator(); j.MoveNext();)
                {
                    NodeType node2 = (NodeType)j.Current;

                    if (node.node_value() == node2.node_value())
                    {
                        found = true;
                        break;
                    }
                }
                if (found)
                {
                    rs.add(node);
                }
            }
            rs = NodeType.linarize(rs);

            return(rs.Sequence);
        }
Beispiel #20
0
        /// <summary>
        ///  添加扩展记录,如果没有扩展字典,那就创建扩展字典
        /// </summary>
        /// <param name="objId">对象的objectid</param>
        /// <param name="xRecordSearchKey">扩展记录名称</param>
        /// <param name="values">扩展记录的内容</param>
        /// <returns></returns>
        public static void AddNumberToPolyline(ObjectId objId, string values)
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor   ed  = doc.Editor;
            Database db  = doc.Database;

            DocumentLock m_DocumentLock = Application.DocumentManager.MdiActiveDocument.LockDocument();

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                //添加扩展记录之前,先创建对象的扩展字典
                DBObject obj = tr.GetObject(objId, OpenMode.ForRead); //以读的方式打开
                if (obj.ExtensionDictionary.IsNull)                   //如果对象无扩展字典,那就给创建
                {
                    obj.UpgradeOpen();                                //切换对象为写的状态
                    obj.CreateExtensionDictionary();                  //为对象创建扩展字典,一个对象只能拥有一个扩展字典
                    obj.DowngradeOpen();                              //将对象切换为读的状态
                }
                //打开对象的扩展字典
                DBDictionary dict = obj.ExtensionDictionary.GetObject(OpenMode.ForRead) as DBDictionary;
                //如果扩展字典中已包含指定的扩展记录对象
                if (dict.Contains("polylineNumber"))
                {
                    m_DocumentLock.Dispose();
                }
                else //若没有包含扩展记录,则创建一个
                {
                    ResultBuffer valueBuffer = new ResultBuffer();
                    valueBuffer.Add(new TypedValue(5005, values));
                    Xrecord xrec = new Xrecord();                         //为对象创建一个扩展记录
                    xrec.Data = valueBuffer;                              //指定扩展记录的内容,这里用到了自定义类型转换,TypedValueList-->ResultBuffer

                    dict.UpgradeOpen();                                   //将扩展字典切换为写的状态,以便添加一个扩展记录
                    ObjectId xrecId = dict.SetAt("polylineNumber", xrec); //在扩展字典中加入新建的扩展记录,并指定它的搜索关键字
                    tr.AddNewlyCreatedDBObject(xrec, true);
                    dict.DowngradeOpen();                                 //将扩展字典切换为读的状态

                    m_DocumentLock.Dispose();
                }
                tr.Commit();
            }
        }
Beispiel #21
0
        flipPointsMove(bool add)
        {
            double           dblEasting  = 0;
            double           dblNorthing = 0;
            List <StakedPnt> stakedPnts  = getStakedPnts();

            try
            {
                for (int i = 0; i < stakedPnts.Count; i++)
                {
                    Alignment objAlign = (Alignment)stakedPnts[i].hAlign.getEnt();

                    objAlign.PointLocation(stakedPnts[i].Station, stakedPnts[i].Offset * -1, ref dblEasting, ref dblNorthing);

                    Point3d      pnt3d   = new Point3d(dblEasting, dblNorthing, stakedPnts[i].Elev);
                    ObjectId     idCgPnt = stakedPnts[i].hCgPnt.getObjectId();
                    ResultBuffer rb      = idCgPnt.getXData("STAKE");
                    if (rb == null)
                    {
                        continue;
                    }
                    TypedValue[] tvs    = rb.AsArray();
                    double       offset = double.Parse(tvs[3].Value.ToString()) * -1;
                    tvs[3] = new TypedValue(1040, offset);

                    if (add)
                    {
                        uint pntNum = 0;
                        idCgPnt = pnt3d.setPoint(out pntNum, "SPNT");
                        idCgPnt.setXData(tvs, "STAKE");
                    }
                    else
                    {
                        idCgPnt.moveCogoPoint(pnt3d);
                        idCgPnt.setXData(tvs, "STAKE");
                    }
                }
            }
            catch (System.Exception)
            {
            }
        }
Beispiel #22
0
        /// <summary>
        /// Concatenate the arguments.
        /// </summary>
        /// <param name="args">
        ///            are concatenated. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> The result of the concatenation of the arguments. </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.api.ResultSequence concat(java.util.Collection args) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence concat(ICollection args)
        {
            // sanity check
            if (args.Count < 2)
            {
                DynamicError.throw_type_error();
            }

            ResultBuffer rs = new ResultBuffer();

            string result = "";

            // go through args
            StringBuilder buf = new StringBuilder();

            for (IEnumerator argi = args.GetEnumerator(); argi.MoveNext();)
            {
                ResultSequence arg = (ResultSequence)argi.Current;

                int size = arg.size();

                // sanity check
                if (size > 1)
                {
                    DynamicError.throw_type_error();
                }

                if (size == 0)
                {
                    continue;
                }

                Item at = arg.first();

                buf.Append(at.StringValue);
            }
            result = buf.ToString();

            rs.add(new XSString(result));

            return(rs.Sequence);
        }
Beispiel #23
0
        public void Initialize()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;

            this.document = doc;
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

            ed.WriteMessage("\nAgile plugin正在初始化...");
            try
            {
                //Type t = InitClass.interopA.GetType("Autodesk.AutoCAD.Interop.AcadApplication");
//Autodesk.AutoCAD.Interop.AcadApplication acadApp = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication as Autodesk.AutoCAD.Interop.AcadApplication;
                //Autodesk.AutoCAD.Interop.AcadApplication acadApp = (Autodesk.AutoCAD.Interop.AcadApplication)Activator.CreateInstance(System.Type.GetTypeFromProgID("AutoCAD.Application.18")); ;
                //Autodesk.AutoCAD.Interop.AcadApplication app = (Autodesk.AutoCAD.Interop.AcadApplication)Marshal.GetActiveObject("AutoCAD.Application.18");
                //ed.WriteMessage(acadApp.ToString());
                //acadApp.MenuGroups
                //MyMenu.ShowMyMenu();
                //MyMenu.cuiMenu();
                //myCommand("mycui ");
                string lispPath = "agilePluginCmds.lsp";
                string loadStr  = "(load \"" + InitClass.AssemblyDirectory + "\\" + lispPath + "\") ";
                loadStr = loadStr.Replace("\\", "\\\\");
                ed.WriteMessage(loadStr);
                //ed.WriteMessage(acedPostCommand12==null);
                myCommand(loadStr);
                ResultBuffer args = new ResultBuffer(
                    new TypedValue((int)LispDataType.Text, loadStr) /*,
                                                                     * new TypedValue((int)LispDataType.Text, "_arc"),
                                                                     * new TypedValue((int)LispDataType.Double, 2.0 / scale),
                                                                     * new TypedValue((int)LispDataType.Double, 6.0 / scale),
                                                                     * new TypedValue((int)LispDataType.Text, "_object"),
                                                                     * new TypedValue((int)LispDataType.ObjectId, id),
                                                                     * new TypedValue((int)LispDataType.Text, "_no")*/);
                //acedCmd(args.UnmanagedObject);
                //ProcessBackground();
                Initialize2();
            }
            catch (System.Exception ex)
            {
                ed.WriteMessage("\n" + ex.Message);
            }
        }
Beispiel #24
0
        public static string LoadXData(ObjectId objId)
        {
            // Get the current database and start a transaction
            Database acCurDb;

            acCurDb = acApp.DocumentManager.MdiActiveDocument.Database;

            Document acDoc = acApp.DocumentManager.MdiActiveDocument;

            string msgstr = "";

            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                // Open the selected object for read
                Entity acEnt = acTrans.GetObject(objId, OpenMode.ForRead) as Entity;

                // Get the extended data attached to each object for MY_APP
                ResultBuffer rb = acEnt.GetXDataForApplication(appName);

                // Make sure the Xdata is not empty
                if (rb != null)
                {
                    // Get the values in the xdata
                    foreach (TypedValue typeVal in rb)
                    {
                        if (typeVal.TypeCode == 1000)
                        {
                            msgstr = typeVal.Value.ToString();
                        }
                    }
                }
                else
                {
                    msgstr = "";
                }

                // Ends the transaction and ensures any changes made are ignored
                acTrans.Abort();
                // Dispose of the transaction
            }
            return(msgstr);
        }
        /// <summary>
        /// Set EED.
        /// </summary>
        /// <param name="objId">The object id of the entity.</param>
        /// <param name="eedDict">The key-value pair of the EED data.</param>
        public static void SetEED(Transaction trans, ObjectId objId, Dictionary <string, string> eedDict, string appname)
        {
            //_logger.Debug("Start SetEED");
            using (ResultBuffer resBuffer = new ResultBuffer())
            {
                resBuffer.Add(new TypedValue((int)DxfCode.ExtendedDataRegAppName, appname));
                resBuffer.Add(new TypedValue((int)DxfCode.ExtendedDataControlString, "{"));

                foreach (KeyValuePair <string, string> kvp in eedDict)
                {
                    string val = string.Format("{0}={1}", kvp.Key, kvp.Value);
                    resBuffer.Add(new TypedValue((int)DxfCode.ExtendedDataAsciiString, val));
                }

                resBuffer.Add(new TypedValue((int)DxfCode.ExtendedDataControlString, "}"));

                SetXData(trans, objId, appname, resBuffer);
            }
            //_logger.Debug("End SetEED");
        }
Beispiel #26
0
        toList(this TypedValue[] tvs, out short[] typeOut, out object[] valOut)
        {
            List <short>  type = new List <short>();
            List <Object> val  = new List <Object>();
            ResultBuffer  rb   = new ResultBuffer(tvs);

            foreach (TypedValue tv in rb)
            {
                type.Add(tv.TypeCode);
                val.Add(tv.Value);
            }
            typeOut = new short[type.Count];
            valOut  = new object[val.Count];

            for (int i = 0; i < type.Count; i++)
            {
                typeOut[i] = type[1];
                valOut[i]  = val[i];
            }
        }
Beispiel #27
0
        /// <summary>
        /// Converts a <see cref="ResultBuffer"/> to <see cref="List{TypedValue}"/>. If the Lisp arguments are below the minimum or above the maximum required, an exception will be thrown.
        /// </summary>
        /// <param name="arguments"></param>
        /// <param name="minimum"></param>
        /// <param name="maximum"></param>
        /// <returns><see cref="List{TypedValue}"/></returns>
        /// <exception cref="System.Exception"/>
        public static List <TypedValue> HandleLispArguments(ResultBuffer arguments, int minimum, int maximum)
        {
            if (arguments == null)
            {
                throw new System.Exception("too few arguments");
            }

            List <TypedValue> Arguments = new List <TypedValue>(arguments.AsArray());

            if (Arguments.Count < minimum)
            {
                throw new System.Exception("too few arguments");
            }
            else if (Arguments.Count > maximum)
            {
                throw new System.Exception("too many arguments");
            }

            return(Arguments);
        }
Beispiel #28
0
        private ResultBuffer BuildResultBuffer(string appName, Dictionary <string, string> dic)
        {
            if (dic.Count == 0)
            {
                return(null);
            }
            else
            {
                ResultBuffer rb = new ResultBuffer();
                rb.Add(new TypedValue((int)DxfCode.ExtendedDataRegAppName, appName));

                foreach (KeyValuePair <string, string> kp in dic)
                {
                    rb.Add(new TypedValue((int)DxfCode.ExtendedDataAsciiString, kp.Key));
                    rb.Add(new TypedValue((int)DxfCode.ExtendedDataAsciiString, kp.Value));
                }

                return(rb);
            }
        }
Beispiel #29
0
        /// <summary> 将静态类中的数据保存到<seealso cref="Xrecord"/>对象中 </summary>
        /// <returns></returns>
        public static ResultBuffer ToResultBuffer_Blocks()
        {
            var generalBuff = new ResultBuffer();
            var count       = RangeBlocks.Count;

            generalBuff.Add(new TypedValue((int)DxfCode.ExtendedDataInteger32, count));
            foreach (var s in RangeBlocks)
            {
                generalBuff.Add(Utils.SetExtendedDataEnum(s.Type));
                generalBuff.Add(new TypedValue((int)DxfCode.ExtendedDataReal, s.StartStation));
                generalBuff.Add(new TypedValue((int)DxfCode.ExtendedDataReal, s.EndStation));
                generalBuff.Add(new TypedValue((int)DxfCode.ExtendedDataReal, s.ConnectedBackStaion));
                generalBuff.Add(new TypedValue((int)DxfCode.ExtendedDataReal, s.ConnectedFrontStaion));
                generalBuff.Add(new TypedValue((int)DxfCode.ExtendedDataAsciiString, s.Description));
            }
            //
            //var rec = new Xrecord();
            //rec.Data = generalBuff;
            return(generalBuff);
        }
Beispiel #30
0
        /// <summary>
        ///     Set EED.
        /// </summary>
        /// <param name="objId">The object id of the entity.</param>
        /// <param name="eedDict">The key-value pair of the EED data.</param>
        public static void SetEED(Transaction trans, ObjectId objId, Dictionary <string, string> eedDict, string appname)
        {
            PGA.MessengerManager.MessengerManager.AddLog("Start SetEED");
            using (var resBuffer = new ResultBuffer())
            {
                resBuffer.Add(new TypedValue((int)DxfCode.ExtendedDataRegAppName, appname));
                resBuffer.Add(new TypedValue((int)DxfCode.ExtendedDataControlString, "{"));

                foreach (var kvp in eedDict)
                {
                    var val = string.Format("{0}={1}", kvp.Key, kvp.Value);
                    resBuffer.Add(new TypedValue((int)DxfCode.ExtendedDataAsciiString, val));
                }

                resBuffer.Add(new TypedValue((int)DxfCode.ExtendedDataControlString, "}"));

                SetXData(trans, objId, appname, resBuffer);
            }
            PGA.MessengerManager.MessengerManager.AddLog("End SetEED");
        }
Beispiel #31
0
 public static void SetNodeId(this DBPoint pt, Database db, int id)
 {
     using (Transaction tr = db.TransactionManager.StartTransaction())
     {
         RegAppTable acRegAppTbl = tr.GetObject(db.RegAppTableId, OpenMode.ForRead) as RegAppTable;
         using (RegAppTableRecord acRegAppTblRec = new RegAppTableRecord())
         {
             acRegAppTblRec.Name = "HKB";
             tr.GetObject(db.RegAppTableId, OpenMode.ForWrite);
             acRegAppTbl.Add(acRegAppTblRec);
             tr.AddNewlyCreatedDBObject(acRegAppTblRec, true);
         }
         using (ResultBuffer rb = new ResultBuffer())
         {
             rb.Add(new TypedValue((int)DxfCode.ExtendedDataRegAppName, "HKB"));
             rb.Add(new TypedValue((int)DxfCode.ExtendedDataInteger16, id));
             pt.XData = rb;
         }
     }
 }
Beispiel #32
0
        public static void SetXrecord(ObjectId id, string key, ResultBuffer resbuf)
        {
            Database db = Tools.GetAcadDatabase();

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                Entity ent = tr.GetObject(id, OpenMode.ForRead) as Entity;
                if (ent != null)
                {
                    ent.UpgradeOpen();
                    ent.CreateExtensionDictionary();
                    DBDictionary xDict = (DBDictionary)tr.GetObject(ent.ExtensionDictionary, OpenMode.ForWrite);
                    Xrecord      xRec  = new Xrecord();
                    xRec.Data = resbuf;
                    xDict.SetAt(key, xRec);
                    tr.AddNewlyCreatedDBObject(xRec, true);
                }
                tr.Commit();
            }
        }
Beispiel #33
0
        public static Point3d GetAssocParam(ResultBuffer rb, string tag, Point3d defaultValue)
        {
            object obj = LspUtil.FetchAssocParam(rb, tag);

            if (obj == null)
            {
                return(defaultValue);
            }
            if (obj is Point3d)
            {
                return((Point3d)obj);
            }
            if (obj is Point2d)
            {
                Point2d point2d = (Point2d)obj;
                Point3d result  = new Point3d(point2d.X, point2d.Y, 0.0);
                return(result);
            }
            return(defaultValue);
        }
Beispiel #34
0
        private ResultBuffer BuildQueryResultBuffer()
        {
            ResultBuffer resultBuffer = new ResultBuffer();

            foreach (DataRow dataRow in this._QueryData.Rows)
            {
                DXFCode dXFCode = new DXFCode(dataRow["Type"].ToString());
                object  obj     = dataRow["Value"];
                if (dXFCode.Code == 62)
                {
                    obj = DXFCode.TranslateColorString(obj.ToString());
                }
                if (DXFCode.IsValidTypedValue(dXFCode.Code, obj.ToString()))
                {
                    TypedValue typedValue = DXFCode.CreateTypedValue(dXFCode.Code, obj.ToString());
                    resultBuffer.Add(typedValue);
                }
            }
            return(resultBuffer);
        }
Beispiel #35
0
        //acquire the extents of the frame and convert them from UCS to DCS, in case of view rotation
        static public Extents2d coordinates(Point3d firstInput, Point3d secondInput)
        {
            double minX;
            double minY;
            double maxX;
            double maxY;

            //sort through the values to be sure that the correct first and second are assigned
            if (firstInput.X < secondInput.X)
            {
                minX = firstInput.X; maxX = secondInput.X;
            }
            else
            {
                maxX = firstInput.X; minX = secondInput.X;
            }

            if (firstInput.Y < secondInput.Y)
            {
                minY = firstInput.Y; maxY = secondInput.Y;
            }
            else
            {
                maxY = firstInput.Y; minY = secondInput.Y;
            }


            Point3d first  = new Point3d(minX, minY, 0);
            Point3d second = new Point3d(maxX, maxY, 0);
            //converting numbers to something the system uses (DCS) instead of UCS
            ResultBuffer rbFrom = new ResultBuffer(new TypedValue(5003, 1)), rbTo = new ResultBuffer(new TypedValue(5003, 2));

            double[] firres = new double[] { 0, 0, 0 };
            double[] secres = new double[] { 0, 0, 0 };
            //convert points
            acedTrans(first.ToArray(), rbFrom.UnmanagedObject, rbTo.UnmanagedObject, 0, firres);
            acedTrans(second.ToArray(), rbFrom.UnmanagedObject, rbTo.UnmanagedObject, 0, secres);
            Extents2d window = new Extents2d(firres[0], firres[1], secres[0], secres[1]);

            return(window);
        }
Beispiel #36
0
 public void Write(Database db, Transaction t)
 {
     try
     {
         DBDictionary dBDictionary  = this.ParentDataset.Open(db, t, FieldDomain.DictionaryName, (OpenMode)1);
         DBDictionary dBDictionary2 = new DBDictionary();
         this.Id = dBDictionary.SetAt(this.Name, dBDictionary2);
         dBDictionary2.DisableUndoRecording(true);
         t.AddNewlyCreatedDBObject(dBDictionary2, true);
         this.WriteTypedValue(db, t, dBDictionary2, "KeyName", new TypedValue(1, this.Name));
         this.WriteTypedValue(db, t, dBDictionary2, "DisplayName", new TypedValue(1, this.DisplayName));
         this.WriteTypedValue(db, t, dBDictionary2, "DomainType", new TypedValue(1, this.DomainType));
         this.WriteTypedValue(db, t, dBDictionary2, "DomainFieldType", new TypedValue(90, this.FieldType));
         if (this.DomainType == "RangeDomain")
         {
             this.WriteTypedValue(db, t, dBDictionary2, "DomainMinimum", CadField.CreateTypedValue(this.MinValue));
             this.WriteTypedValue(db, t, dBDictionary2, "DomainMaximum", CadField.CreateTypedValue(this.MaxValue));
         }
         if (this.DomainType == "CodedValueDomain")
         {
             List <TypedValue> list = new List <TypedValue>();
             foreach (KeyValuePair <string, MSCCodedValue> keyValuePair in this.CodedValues)
             {
                 MSCCodedValue value = keyValuePair.Value;
                 list.Add(CadField.CreateTypedValue(value.DisplayName));
                 list.Add(CadField.CreateTypedValue(value.Value));
             }
             try
             {
                 ResultBuffer rb = new ResultBuffer(list.ToArray());
                 this.WriteResultBuffer(db, t, dBDictionary2, "CodedValues", rb);
             }
             catch (System.Exception)
             {
             }
         }
     }
     catch
     {
     }
 }
Beispiel #37
0
 public static void CreatePaletteSet(ResultBuffer rb)
 {
     try
     {
         if (_ps == null)
         {
             _ps = new GPPaletteSet();
         }
         if (!_ps.IsEmpty)
         {
             _ps.Visible = true;
         }
         else
         {
             AcadApp.AcaEd.WriteMessage("\nLUFSGenplan: Нет доступных расширений для загрузки\n");
         }
     }catch (Autodesk.AutoCAD.Runtime.Exception ex)
     {
         AcadApp.AcaEd.WriteMessage("ERROR: Commands.CreatePaletteSet()\n" + ex + "\n");
     }
 }
Beispiel #38
0
        public ResultBuffer PythonLoadLISP(ResultBuffer rb)
        {
            const int RTSTR = 5005;

            Document doc =
              Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;

            if (rb == null)
            {
                ed.WriteMessage("\nError: too few arguments\n");
            }
            else
            {
                // We're only really interested in the first argument

                Array args = rb.AsArray();
                TypedValue tv = (TypedValue)args.GetValue(0);

                // Which should be the filename of our script

                if (tv != null && tv.TypeCode == RTSTR)
                {
                    // If we manage to execute it, let's return the
                    // filename as the result of the function
                    // (just as (arxload) does)

                    bool success =
                      ExecutePythonScript(Convert.ToString(tv.Value));
                    return
                      (success ?
                        new ResultBuffer(
                          new TypedValue(RTSTR, tv.Value)
                        )
                        : null);
                }
            }
            return null;
        }
Beispiel #39
0
        public void SetXData(Handle handle, XDataCollection extendedData)
        {
            Transaction trans = doc.TransactionManager.StartTransaction();
            using (trans)
            {
                ObjectId objId;
                if (db.TryGetObjectId(handle, out objId))
                {
                    DBObject dbObj = trans.GetObject(objId, OpenMode.ForWrite);
                    ResultBuffer rb = new ResultBuffer();
                    foreach (XData xData in extendedData)
                    {
                        AddRegAppTableRecord(xData.AppName);
                        rb.Add(new TypedValue(1001, xData.AppName));
                        rb.Add(new TypedValue(xData.Code, xData.Data.ToString()));
                    }

                    dbObj.XData = rb;
                    rb.Dispose();
                    trans.Commit();
                }
            }
        }
Beispiel #40
0
 public void Modify(AC_Line line)
 {
     if (Remove(line))
     {
         buildTriangulations build = new buildTriangulations();
         if (build.askForDistances(line))
         {
             ResultBuffer rb = new ResultBuffer(new TypedValue((int)DxfCode.ExtendedDataRegAppName, "TRIANGULATE"), new TypedValue((int)DxfCode.ExtendedDataAsciiString, build.radius[0].ToString()), new TypedValue((int)DxfCode.ExtendedDataAsciiString, build.radius[1].ToString()), new TypedValue((int)DxfCode.ExtendedDataAsciiString, Guid.NewGuid().ToString()));
             line.XData = rb;
             Show(line);
         }
     }
 }
Beispiel #41
0
            private void createObjects(AC_Line line)
            {
                AC_Circle t1 = new AC_Circle();
                AC_Circle t2 = new AC_Circle();
                AC_Polyline p = new AC_Polyline();
                t1.Center = line.StartPoint;
                t2.Center = line.EndPoint;
                t1.Radius = BaseRadius[0];
                t2.Radius = BaseRadius[1];
                t1.addToDrawing();
                t2.addToDrawing();
                p.addToDrawing();

                //APPLY COLORS
                applyLineStyle((AC_Entity)p, Color.FromRgb(255, 51, 51), "ACAD_ISO02W100",3);
                applyLineStyle((AC_Entity)t1, Color.FromRgb(255, 135, 51), "ACAD_ISO03W100",1);
                applyLineStyle((AC_Entity)t2, Color.FromRgb(255, 135, 51), "ACAD_ISO03W100",1);

                //COPY XDATA GUID
                int index = 0;
                string guid = "";
                foreach (TypedValue tv in line.XData as ResultBuffer)
                {
                    if(index == 3){
                        guid = tv.Value.ToString();
                    }
                    index++;
                }

                ResultBuffer rb = new ResultBuffer(new TypedValue((int)DxfCode.ExtendedDataRegAppName, "TRIANGULATE"), new TypedValue((int)DxfCode.ExtendedDataAsciiString, guid));
                t1.XData = rb;
                t2.XData = rb;
                p.XData = rb;

                Point3dCollection pts = new Point3dCollection();
                t1.IntersectWith((Circle)t2, Intersect.OnBothOperands, pts, IntPtr.Zero, IntPtr.Zero);

                if (pts.Count == 0)
                {
                    tr.AC_Doc.Editor.WriteMessage("Cannot Calculate Triangulation \n");
                    t1.Erase(true);
                    t2.Erase(true);
                    p.Erase(true);
                }
                else if (pts.Count == 1)
                {
                    p.AddVertexAt(0, new Point2d(line.StartPoint.X, line.StartPoint.Y), 0, 0, 0);
                    p.AddVertexAt(1, new Point2d(pts[0].X, pts[0].Y), 0, 0, 0);
                    p.AddVertexAt(2, new Point2d(line.EndPoint.X, line.EndPoint.Y), 0, 0, 0);
                }
                else if (pts.Count == 2)
                {
                    p.AddVertexAt(0, new Point2d(line.StartPoint.X, line.StartPoint.Y), 0, 0, 0);
                    p.AddVertexAt(1, new Point2d(pts[0].X, pts[0].Y), 0, 0, 0);
                    p.AddVertexAt(2, new Point2d(line.EndPoint.X, line.EndPoint.Y), 0, 0, 0);
                    p.AddVertexAt(3, new Point2d(pts[1].X, pts[1].Y), 0, 0, 0);
                    p.Closed = true;
                }
            }
        // add attributes to group object
        // <param name="groupId"></param>
        // <param name="pairs"></param>
        public static void addData(ObjectId groupId, Dictionary<String, String> pairs)
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            Transaction trans = ed.Document.Database.TransactionManager.StartTransaction();
            try
            {
                Group ent = (Group)trans.GetObject(groupId, OpenMode.ForRead);
                if (ent.ExtensionDictionary.IsNull)
                {
                    ent.UpgradeOpen();
                    ent.CreateExtensionDictionary();
                }

                DBDictionary extensionDict = (DBDictionary)trans.GetObject(ent.ExtensionDictionary, OpenMode.ForRead);
                foreach (KeyValuePair<string, string> item in pairs)
                {
                    String key = item.Key;
                    String value = item.Value;
                    Xrecord myXrecord;
                    if (extensionDict.Contains(key))
                    {
                        // Check to see if the entry we are going to add is already there.
                        ObjectId entryId = extensionDict.GetAt(key);
                        // Extract the Xrecord. Declare an Xrecord variable.
                        myXrecord = default(Xrecord);
                        extensionDict.UpgradeOpen();
                        // Instantiate the Xrecord variable
                        myXrecord = (Xrecord)trans.GetObject(entryId, OpenMode.ForWrite);
                        ResultBuffer data = new ResultBuffer(new TypedValue((int)DxfCode.Text, value));
                        myXrecord.Data = data;

                    }
                    else
                    {
                        // If the code gets to here then the data entry does not exist
                        // upgrade the ExtensionDictionary created in step 5 to write
                        extensionDict.UpgradeOpen();
                        //  Create a new XRecord.
                        myXrecord = new Xrecord();
                        // Create the resbuf list.
                        ResultBuffer data = new ResultBuffer(new TypedValue((int)DxfCode.Text, value));
                        // Add the ResultBuffer to the Xrecord
                        myXrecord.Data = data;
                        // Create the entry in the ExtensionDictionary.
                        extensionDict.SetAt(key, myXrecord);
                        // Tell the transaction about the newly created Xrecord
                        trans.AddNewlyCreatedDBObject(myXrecord, true);
                    }
                }
                trans.Commit();
            }
            catch (System.Exception ex)
            {
                // a problem occured, lets print it
                ed.WriteMessage("a problem occured because " + ex.Message);
            }
            finally
            {
                trans.Dispose();
            }
        }
        public void Save()
        {
            if(WriteLock == true)
            {
                return;
            }
            if(BaseObjectId == ObjectId.Null)
            {
                return;
            }
            using (DocumentLock docLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument())
            {
                attrs.Clear();
                this.GetAttributes();
                if (attrs.ContainsKey("type"))
                {
                    attrs["type"] = this.ModelType();
                }
                else
                {
                    attrs.Add("type", this.ModelType());
                }
                if(attrs.ContainsKey("modelid"))
                {
                    attrs["modelid"] = Utils.ModelIdManager.toString(this.BaseModelId);
                }
                else
                {
                    attrs.Add("modelid", Utils.ModelIdManager.toString(this.BaseModelId));
                }
                Dictionary<String, String> pairs = attrs;
                Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
                Transaction trans = ed.Document.Database.TransactionManager.StartTransaction();
                try
                {
                    DBObject ent = trans.GetObject(BaseObjectId, OpenMode.ForRead);

                    if (ent.ExtensionDictionary.IsNull)
                    {
                        ent.UpgradeOpen();
                        ent.CreateExtensionDictionary();
                    }

                    DBDictionary extensionDict = (DBDictionary)trans.GetObject(ent.ExtensionDictionary, OpenMode.ForRead);
                    foreach (KeyValuePair<string, string> item in pairs)
                    {
                        String key = item.Key;
                        String value = item.Value;
                        Xrecord myXrecord;
                        if (extensionDict.Contains(key))
                        {
                            ObjectId entryId = extensionDict.GetAt(key);
                            myXrecord = default(Xrecord);
                            extensionDict.UpgradeOpen();
                            myXrecord = (Xrecord)trans.GetObject(entryId, OpenMode.ForWrite);
                            ResultBuffer data = new ResultBuffer(new TypedValue((int)DxfCode.Text, value));
                            myXrecord.Data = data;
                        }
                        else
                        {
                            extensionDict.UpgradeOpen();
                            myXrecord = new Xrecord();
                            ResultBuffer data = new ResultBuffer(new TypedValue((int)DxfCode.Text, value));
                            myXrecord.Data = data;
                            extensionDict.SetAt(key, myXrecord);
                            trans.AddNewlyCreatedDBObject(myXrecord, true);
                        }
                    }
                    trans.Commit();
                }
                catch (System.Exception ex)
                {
                    ed.WriteMessage("a problem occured because " + ex.Message);
                }
                finally
                {
                    trans.Dispose();
                }
            }
        }
Beispiel #44
0
        public static void SaveRenamedMarkArToDict(List<MarkArRename> renameMarkARList)
        {
            ObjectId idRec = getRec(_recNameRenameMarkAR + MarkArRename.Abbr.ToUpper());
            if (idRec.IsNull)
                return;

            using (var xRec = idRec.Open(OpenMode.ForWrite) as Xrecord)
            {
                using (ResultBuffer rb = new ResultBuffer())
                {
                    foreach (var renameMark in renameMarkARList)
                    {
                        if (renameMark.IsRenamed)
                        {
                            string value = getValueRenameMark(renameMark);
                            rb.Add(new TypedValue((int)DxfCode.Text, value));
                        }
                    }
                    xRec.Data = rb;
                }
            }
        }
Beispiel #45
0
            public void Create(AC_Line line)
            {
                if (line.XData == null)
                {
                    if (askForDistances(line))
                    {
                        tr.start_Transaction();
                        RegAppTable rat = (RegAppTable)tr.AC_Tr.GetObject(tr.AC_Db.RegAppTableId,OpenMode.ForRead,false);
                        if (!rat.Has("TRIANGULATE"))
                        {
                            rat.UpgradeOpen();
                            RegAppTableRecord ratr = new RegAppTableRecord();
                            ratr.Name = "TRIANGULATE";
                            rat.Add(ratr);
                            tr.AC_Tr.AddNewlyCreatedDBObject(ratr, true);
                        }
                        tr.AC_Tr.Commit();
                        tr.AC_Tr.Dispose();

                        ResultBuffer rb = new ResultBuffer(new TypedValue((int)DxfCode.ExtendedDataRegAppName, "TRIANGULATE"), new TypedValue((int)DxfCode.ExtendedDataAsciiString, radius[0].ToString()), new TypedValue((int)DxfCode.ExtendedDataAsciiString, radius[1].ToString()), new TypedValue((int)DxfCode.ExtendedDataAsciiString, Guid.NewGuid().ToString()));
                        line.XData = rb;

                        Triangulations triang = new Triangulations();
                        triang.Show(line);
                    }
                }
                else
                {
                    tr.AC_Doc.Editor.WriteMessage("This line is alredy triangulated \n");
                }
            }
Beispiel #46
0
 /// <summary>
 /// Включение/отключение бергштрихов для полилинии - запись xdata
 /// Должна быть запущена транзакция!!!
 /// </summary>
 private void Activate(bool activate)
 {
    using (var curve = IdCurve.GetObject(OpenMode.ForRead, false, true) as Curve)
    {
       //ResultBuffer rb = curve.GetXDataForApplication(RegAppNAME);
       ResultBuffer rb;
       if (activate)
       {
          rb = new ResultBuffer(new TypedValue(1001, RegAppNAME),
                                    // 0 - прямой штрих, 1 - обратный
                                    new TypedValue((int)DxfCode.ExtendedDataInteger16, 0),
                                    // 0 - изолиния, 1 - бергштрих
                                    new TypedValue((int)DxfCode.ExtendedDataInteger16, 0)
                                );
       }
       else
       {
          rb = new ResultBuffer(new TypedValue(1001, RegAppNAME));
       }
       curve.UpgradeOpen();
       curve.XData = rb;
    }
 }
Beispiel #47
0
 /// <summary>
 /// обратить бергштрихи у полилинии
 /// Должна быть запущена транзакция!!!
 /// </summary>
 public void ReverseIsoline()
 {
    using (var curve = IdCurve.GetObject(OpenMode.ForWrite, false, true) as Curve)
    {
       ResultBuffer rb = curve.GetXDataForApplication(RegAppNAME);
       if (rb != null)
       {
          var data = rb.AsArray();
          bool isFound = false;
          for (int i = 0; i < data.Length; i++)
          {
             var tv = data[i];
             if (tv.TypeCode == (short)DxfCode.ExtendedDataInteger16)
             {
                data[i] = new TypedValue((int)DxfCode.ExtendedDataInteger16, IsNegate ? 0 : 1);
                IsNegate = !IsNegate;
                isFound = true;
                break;
             }
          }
          if (isFound)
          {
             using (ResultBuffer rbNew = new ResultBuffer(data))
             {
                curve.XData = rbNew;
             }
          }
       }
    }
 }
Beispiel #48
0
        public static void SaveAbbr(string abbr)
        {
            ObjectId idRec = getRec(_recNameAbbr);
            if (idRec.IsNull)
                return;

            using (var xRec = idRec.Open(OpenMode.ForWrite) as Xrecord)
            {
                using (ResultBuffer rb = new ResultBuffer())
                {
                    rb.Add(new TypedValue((int)DxfCode.Text, abbr));
                    xRec.Data = rb;
                }
            }
        }
Beispiel #49
0
 private void GetRadiusList(ResultBuffer rb)
 {
     BaseRadius = new List<double>();
     int n = 0;
     foreach (TypedValue tv in rb)
     {
         if (tv.Value.ToString() == "TRIANGULATE")
         {
             foreach (TypedValue intv in rb)
             {
                 if (n == 0)
                 {
                     n++;
                     continue;
                 }
                 else if(n <= 2)
                 {
                     BaseRadius.Add(Convert.ToDouble(intv.Value));
                     n++;
                 }
             }
             break;
         }
         else
         {
             tr.AC_Doc.Editor.WriteMessage("This Line doesn't have triangulations \n");
         }
         break;
     }
 }
Beispiel #50
0
        public void SetXData()
        {
            PromptEntityOptions opt = new PromptEntityOptions("\nSelect entity: ");
            PromptEntityResult res = editor.GetEntity(opt);
            if (res.Status == PromptStatus.OK)
            {
                Transaction trans = doc.TransactionManager.StartTransaction();
                using (trans)
                {
                    DBObject obj =
                      trans.GetObject(
                        res.ObjectId,
                        OpenMode.ForWrite
                      );

                    AddRegAppTableRecord("skd");
                    AddRegAppTableRecord("l2p");
                    AddRegAppTableRecord("l1p");
                    AddRegAppTableRecord("g_d");
                    AddRegAppTableRecord("kom");
                    AddRegAppTableRecord("dds");
                    AddRegAppTableRecord("typ");
                    AddRegAppTableRecord("ilp");
                    AddRegAppTableRecord("ilw");
                    AddRegAppTableRecord("sko");
                    AddRegAppTableRecord("sre");
                    AddRegAppTableRecord("np-69");
                    AddRegAppTableRecord("el-100");
                    AddRegAppTableRecord("pro");
                    AddRegAppTableRecord("nop");
                    AddRegAppTableRecord("npo");
                    AddRegAppTableRecord("zn1");
                    AddRegAppTableRecord("zna");

                    ResultBuffer rb =

                      new ResultBuffer(

                        new TypedValue(1001, "skd"),
                        new TypedValue(1040, 0),
                        new TypedValue(1001, "l2p"),
                        new TypedValue(1040, 9),
                        new TypedValue(1001, "l1p"),
                        new TypedValue(1040, 9),
                        new TypedValue(1001, "g_d"),
                        new TypedValue(1000, "glo"),
                        new TypedValue(1001, "kom"),
                        new TypedValue(1000, "\u0020"),
                        new TypedValue(1001, "dds"),
                        new TypedValue(1040, 0.4),
                        new TypedValue(1001, "typ"),
                        new TypedValue(1070, 1),
                        new TypedValue(1001, "ilp"),
                        new TypedValue(1070, 7),
                        new TypedValue(1001, "ilw"),
                        new TypedValue(1070, 8),
                        new TypedValue(1001, "sko"),
                        new TypedValue(1040, 0.21),
                        new TypedValue(1001, "sre"),
                        new TypedValue(1040, 0.016),
                        new TypedValue(1001, "np-69"),
                        new TypedValue(1000, "bw"),
                        new TypedValue(1001, "el-100"),
                        new TypedValue(1000, "bw"),
                        new TypedValue(1001, "pro"),
                        new TypedValue(1000, "sys01-v4"),
                        new TypedValue(1001, "nop"),
                        new TypedValue(1070, 9999),
                        new TypedValue(1001, "npo"),
                        new TypedValue(1070, 30),
                        new TypedValue(1001, "zn1"),
                        new TypedValue(1000, "bw"),
                        new TypedValue(1001, "zna"),
                        new TypedValue(1000, "zn1")
                      );

                    obj.XData = rb;
                    rb.Dispose();
                    trans.Commit();
                }
            }
        }
Beispiel #51
0
        public static void AddXData(this DBObject dbobject, Grevit.Types.Component comp, Transaction tr)
        {
            AddRegAppTableRecord("Grevit",tr);

            Entity ent = (Entity)tr.GetObject(dbobject.Id, OpenMode.ForWrite);

            ResultBuffer rbs = new ResultBuffer(new TypedValue(1001, "Grevit"), new TypedValue(1000, comp.GID));
            ent.XData = rbs;
            rbs.Dispose();

            ent.Dispose();

        }
Beispiel #52
0
 public void PIK_LispLog(ResultBuffer rb)
 {
     var tvs = rb.AsArray();
     if (tvs.Any())
     {
         Logger.Log.InfoLisp(tvs[0].Value.ToString());
     }
 }
Beispiel #53
0
        private void ReplaceXData(ResultBuffer rb)
        {
            if (rb != null)
            {
                Document doc = Application.DocumentManager.MdiActiveDocument;

                Transaction tr = doc.TransactionManager.StartTransaction();
                using (tr)
                {
                    DBObject obj = tr.GetObject(this.id, OpenMode.ForWrite);
                    string appName = rb.AsArray()[0].Value.ToString();
                    if (appName2values.ContainsKey(appName))
                    {
                        obj.XData = rb;
                    }
                    tr.Commit();
                }
            }
        }
Beispiel #54
0
 private static void SetDashXData(Line line)
 {
    using (ResultBuffer rb = new ResultBuffer(new TypedValue(1001, RegAppNAME),
                                 new TypedValue((int)DxfCode.ExtendedDataInteger16, 0),
                                 new TypedValue((int)DxfCode.ExtendedDataInteger16, 1)))
    {
       line.XData = rb;
    }
 }
Beispiel #55
0
 public static void RemoveXData(DBObject dbo)
 {
    if (dbo.GetXDataForApplication(RegAppNAME) != null)
    {
       ResultBuffer rb = rb = new ResultBuffer(new TypedValue(1001, RegAppNAME));
       dbo.UpgradeOpen();
       dbo.XData = rb;
       dbo.DowngradeOpen();
    }
 }
Beispiel #56
0
        public static void SaveBool(bool value, string key)
        {
            ObjectId idRec = getRec(key);
            if (idRec.IsNull)
                return;

            using (var xRec = idRec.Open(OpenMode.ForWrite) as Xrecord)
            {
                using (ResultBuffer rb = new ResultBuffer())
                {
                    rb.Add(new TypedValue((int)DxfCode.Bool, value));
                    xRec.Data = rb;
                }
            }
        }
Beispiel #57
0
        public void Save(double number, string keyName)
        {
            ObjectId idRec = GetRec(keyName, true);
            if (idRec.IsNull)
                return;

            using (var xRec = idRec.Open(OpenMode.ForWrite) as Xrecord)
            {
                using (ResultBuffer rb = new ResultBuffer())
                {
                    rb.Add(new TypedValue((int)DxfCode.Real, number));
                    xRec.Data = rb;
                }
            }
        }
Beispiel #58
0
        public void Save(string text, string key)
        {
            ObjectId idRec = GetRec(key, true);
            if (idRec.IsNull)
                return;

            using (var xRec = idRec.Open(OpenMode.ForWrite) as Xrecord)
            {
                using (ResultBuffer rb = new ResultBuffer())
                {
                    rb.Add(new TypedValue((int)DxfCode.Text, text));
                    xRec.Data = rb;
                }
            }
        }
Beispiel #59
0
        public void Save(List<TypedValue> values, string key)
        {
            if (values == null || values.Count == 0) return;
            ObjectId idRec = GetRec(key, true);
            if (idRec.IsNull)
                return;

            using (var xRec = idRec.Open(OpenMode.ForWrite) as Xrecord)
            {
                using (ResultBuffer rb = new ResultBuffer(values.ToArray()))
                {
                    xRec.Data = rb;
                }
            }
        }
Beispiel #60
0
        public void AddXData()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            ed.WriteMessage("�����������XDATA\n");
            PromptEntityOptions entOps = new PromptEntityOptions("ѡ��Ҫ�򿪵Ķ���\n");
            PromptEntityResult entRes;
            entRes = ed.GetEntity(entOps);
            if (entRes.Status != PromptStatus.OK)
            {
                ed.WriteMessage("ѡ�����ʧ�ܣ��˳�");
                return;
            }
            ObjectId objId = entRes.ObjectId;
            Database db = HostApplicationServices.WorkingDatabase;
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                Entity ent = trans.GetObject(objId, OpenMode.ForWrite) as Entity ;
                ent.ColorIndex = 1;

                RegAppTable appTbl = trans.GetObject(db.RegAppTableId, OpenMode.ForWrite) as RegAppTable ;
                if (!appTbl.Has("MyAppName"))
                {
                    RegAppTableRecord appTblRcd = new RegAppTableRecord();
                    appTblRcd.Name = "MyAppName";
                    appTbl.Add(appTblRcd);
                    trans.AddNewlyCreatedDBObject(appTblRcd, true);
                }
                ResultBuffer resBuf = new ResultBuffer();//new TypedValue(1001, "MyAppName"), new TypedValue(1000, "��������"));

                resBuf.Add(new TypedValue(1001, "MyAppName"));//ע���������
                resBuf.Add(new TypedValue(1000 , " ����"));//����
                resBuf.Add(new TypedValue(1000 , " ���̲�"));//����
                resBuf.Add(new TypedValue(1040, 2000.0));//нˮ
                ent.XData =  resBuf;
                trans.Commit();
            }
        }