Beispiel #1
0
        //creates a LISP compatable list of ObjectIds from an ObjectIdCollection
        public ResultBuffer ListObjectIds(ObjectIdCollection objectIds)
        {
            var nil = new TypedValue((int)LispDataType.Nil);

            try
            {
                using (Transaction ts = Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction())
                {
                    // iterate thru the object ids and create a list to return to LISP
                    ResultBuffer returnValue = new ResultBuffer();
                    if (objectIds.Count == 0)
                    {
                        return(new ResultBuffer(nil));
                    }
                    returnValue.Add(new TypedValue((int)LispDataType.ListBegin));
                    foreach (ObjectId objectId in objectIds)
                    {
                        var item = (new TypedValue((int)LispDataType.ObjectId, objectId));
                        returnValue.Add(item);
                    }
                    returnValue.Add(new TypedValue((int)LispDataType.ListEnd));
                    return(returnValue);
                }
            }
            catch (Autodesk.AutoCAD.Runtime.Exception ex)
            {
                // any error will dump a message to the console and return nil
                Console.WriteLine(ex.Message);
                return(new ResultBuffer(nil));
            }
            // if something else happens, return nil
            return(new ResultBuffer(nil));
        }
Beispiel #2
0
        public ResultBuffer VerifyLicMethod(ResultBuffer inResBuf)
        {
            ResultBuffer resBuf = new ResultBuffer();

            _machineLockCode = GetMachineLockCode();
            String appname = Encrypt(_appname, _keyBytes);

            _licFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +
                                        "\\Autodesk\\", MakeValidFileName(appname));

            //read and find if license type is online or offline.
            int returnVal = isOfflineLic();

            if (returnVal == ONLINE) //online
            {
                int nlic = verifyOnlineEntitlement();
                resBuf.Add(new TypedValue(RTSHORT, nlic));
            }
            else if (returnVal == OFFLINE) //online
            {
                int nLic = verifyofflineEntitlement(STR_OFFLINE);
                resBuf.Add(new TypedValue(RTSHORT, nLic));
            }
            else
            {
                //error
                resBuf.Add(new TypedValue(RTSHORT, returnVal));
            }

            return(resBuf);
        }
        /// <summary>
        /// 拡張ディクショナリのデータを設定
        /// </summary>
        /// <param name="transaction"></param>
        /// <param name="entity"></param>
        /// <param name="count">拡張ディクショナリに設定する値</param>
        private static void AddtExtentionDictionaryData(Transaction transaction, DBObject entity, int count)
        {
            var extentionId = entity.ExtensionDictionary;

            if (extentionId == ObjectId.Null)
            {
                entity.UpgradeOpen();
                entity.CreateExtensionDictionary();
                extentionId = entity.ExtensionDictionary;
            }

            var extentionDict = (DBDictionary)transaction.GetObject(extentionId, OpenMode.ForRead);

            if (extentionDict.Contains("TEST"))
            {
                return;
            }

            extentionDict.UpgradeOpen();
            var xRec         = new Xrecord();
            var resultBuffer = new ResultBuffer();

            resultBuffer.Add(new TypedValue((int)DxfCode.ExtendedDataAsciiString, "Data"));
            resultBuffer.Add(new TypedValue((int)DxfCode.ExtendedDataInteger32, count));

            xRec.Data = resultBuffer;

            extentionDict.SetAt("TEST", xRec);
            transaction.AddNewlyCreatedDBObject(xRec, true);
        }
Beispiel #4
0
        getXRefsContainingTargetDwgName(string nameTarget)
        {
            ObjectIdCollection ids = getXRefBlockReferences();

            if (ids == null)
            {
                return(null);
            }

            ResultBuffer rb = new ResultBuffer();

            foreach (ObjectId id in ids)
            {
                string nameFile = getXRefFileName(id);
                if (nameFile.Contains(nameTarget))
                {
                    if (File.Exists(nameFile))
                    {
                        FileInfo fi        = new FileInfo(nameFile);
                        DateTime lastWrite = fi.LastWriteTime;
                        rb.Add(new TypedValue(1001, nameFile));
                        rb.Add(new TypedValue(1000, lastWrite.ToString()));
                    }
                }
            }
            return(rb);
        }
Beispiel #5
0
        public static void DrawVectors(this Editor editor, IEnumerable <Point2d> pnts, short colorIndex)
        {
            var itor = pnts.GetEnumerator();

            if (!itor.MoveNext())
            {
                return;
            }
            TypedValue   tvFirst = new TypedValue((int)LispDataType.Point2d, itor.Current);
            ResultBuffer rb      =
                new ResultBuffer
            {
                new TypedValue((int)LispDataType.Int16, colorIndex),
                tvFirst,
            };

            while (itor.MoveNext())
            {
                var tv = new TypedValue((int)LispDataType.Point2d, itor.Current);
                rb.Add(tv);
                rb.Add(tv);
            }
            rb.Add(tvFirst);
            editor.DrawVectors(rb, Matrix3d.Identity);
        }
Beispiel #6
0
        //----------------------------------------------------------------------------------

        private ResultBuffer LeesAttributen()
        {
            ResultBuffer MijnResultBuffer = new ResultBuffer();

            //Lees attributenaantal
            int attributenaantal = binReader.ReadInt32();

            //Lees de attribuutgegevens uit de buffer
            for (int i = 0; i < attributenaantal; i++)
            {
                //Lees attrnaam
                string attrnaam = Leesstring();
                MijnResultBuffer.Add(new TypedValue((int)DxfCode.Text, attrnaam));

                //Lees attrtype
                string attrtype = Leesstring();

                //Lees attrwaarde
                switch (attrtype)
                {
                case "Integer": MijnResultBuffer.Add(new TypedValue((int)DxfCode.Int32, binReader.ReadInt32())); break;

                case "Float": MijnResultBuffer.Add(new TypedValue((int)DxfCode.Real, binReader.ReadSingle())); break;

                case "String": MijnResultBuffer.Add(new TypedValue((int)DxfCode.Text, Leesstring())); break;

                default: break;     //gegevenstype nog niet ondersteund
                }
            }

            return(MijnResultBuffer);
        }
Beispiel #7
0
        public static void save(MyDB2 mydb)
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db  = doc.Database;
            Editor   ed  = doc.Editor;

            try
            {
                using (Transaction trans =
                           db.TransactionManager.StartTransaction())
                {
                    // Find the NOD in the database

                    DBDictionary nod = (DBDictionary)trans.GetObject(
                        db.NamedObjectsDictionaryId, OpenMode.ForWrite);

                    BinaryFormatter bf = new BinaryFormatter();
                    MemoryStream    ms = new MemoryStream();
                    bf.Serialize(ms, mydb);
                    ResultBuffer rf        = new ResultBuffer();
                    byte[]       buf       = ms.GetBuffer();
                    int          position  = 0;
                    int          remaining = buf.Length;
                    while (remaining > 0)
                    {
                        if (remaining >= 255)
                        {
                            byte[] chunk = new byte[255];
                            Buffer.BlockCopy(buf, position, chunk, 0, 255);
                            rf.Add(new TypedValue((int)DxfCode.BinaryChunk, chunk));
                            remaining -= 255;
                            position  += 255;
                        }
                        else
                        {
                            byte[] chunk = new byte[remaining];
                            Buffer.BlockCopy(buf, position, chunk, 0, remaining);
                            rf.Add(new TypedValue((int)DxfCode.BinaryChunk, chunk));
                            remaining = 0;
                        }
                    }

                    Xrecord myXrecord = new Xrecord();

                    myXrecord.Data = rf;

                    nod.SetAt("TerrainComputeC", myXrecord);

                    trans.AddNewlyCreatedDBObject(myXrecord, true);

                    trans.Commit();
                } // using
            }

            catch (System.Exception e)
            {
                ed.WriteMessage(e.ToString());
            }
        }
        //用户添加扩展记录
        public static void UserAddXData()
        {
            Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

            ed.WriteMessage("添加扩充数据 XDATA\n");
            PromptEntityOptions entOps = new PromptEntityOptions("选择实体对象");
            PromptEntityResult  entRes;

            entRes = ed.GetEntity(entOps);
            if (entRes.Status != PromptStatus.OK)
            {
                ed.WriteMessage("选择对象失败,退出");
                return;
            }
            //出现添加扩展数据面板
            AddEntityXDataForm addentityxdataform = new AddEntityXDataForm();

            addentityxdataform.Show();

            ObjectId objId = entRes.ObjectId;
            Database db    = HostApplicationServices.WorkingDatabase;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                RegAppTable appTbl     = trans.GetObject(db.RegAppTableId, OpenMode.ForWrite) as RegAppTable;
                string      DateStr    = DateTime.Now.ToString("yyyyMMddHHmmssms"); //日期
                Random      rd         = new Random();                              //用于生成随机数
                string      AppNamestr = DateStr + rd.Next(10, 99);                 //带日期的随机数
                Entity      ent        = trans.GetObject(objId, OpenMode.ForWrite) as Entity;

                if (!appTbl.Has(AppNamestr))
                {
                    RegAppTableRecord appTblRcd = new RegAppTableRecord();
                    appTblRcd.Name = AppNamestr;
                    appTbl.Add(appTblRcd);
                    trans.AddNewlyCreatedDBObject(appTblRcd, true);
                }

                ResultBuffer resBuf = new ResultBuffer(
                    new TypedValue((int)DxfCode.ExtendedDataRegAppName, AppNamestr),
                    new TypedValue((int)DxfCode.ExtendedDataLayerName, "0"),
                    new TypedValue((int)DxfCode.ExtendedDataReal, 1.23479137438413E+40),
                    new TypedValue((int)DxfCode.ExtendedDataInteger16, 32767),
                    new TypedValue((int)DxfCode.ExtendedDataInteger32, 32767),
                    new TypedValue((int)DxfCode.ExtendedDataScale, 10),
                    new TypedValue((int)DxfCode.ExtendedDataWorldXCoordinate, new Point3d(10, 10, 0)));
                resBuf.Add(new TypedValue((int)DxfCode.ExtendedDataAsciiString, "这是追加的数据"));
                resBuf.Add(new TypedValue((int)DxfCode.ExtendedDataAsciiString, "我又一次追加了数据"));
                resBuf.Add(new TypedValue((int)DxfCode.ExtendedDataInteger16, 32767));

                if (ent.XData != null)
                {
                    ed.WriteMessage("该对象已有扩展记录,不需要再次添加,只需在原有记录进行修改");
                    return;
                }
                ent.XData = resBuf;
                trans.Commit();
            }
        }
Beispiel #9
0
        private void btn_change_pline3D_stack_xdata_Click(object sender, EventArgs e)
        {
            double stack = Convert.ToDouble(tbx_pline3d_xdata_stack.Text.Trim());
            Editor ed    = cadSer.Application.DocumentManager.MdiActiveDocument.Editor;


            Database db     = HostApplicationServices.WorkingDatabase;
            var      middoc = cadSer.Application.DocumentManager.MdiActiveDocument;


            string appname = "zjy_1_1_1";


            ObjectId plineID  = ed.GetEntity(new PromptEntityOptions("\n选取HDM辅助线!!!")).ObjectId;
            var      doc_lock = middoc.LockDocument();

            DBObject dbo;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                dbo = trans.GetObject(plineID, OpenMode.ForWrite);

                while (!dbo.GetType().Equals(typeof(Polyline3d)))
                {
                    ed.WriteMessage("\n刚才选取的不是HDM辅助线,请重新选择!!!");
                    plineID = ed.GetEntity(new PromptEntityOptions("\n选取HDM辅助线!!!")).ObjectId;
                    dbo     = trans.GetObject(plineID, OpenMode.ForWrite);
                }

                Polyline3d pline3d_modify = (Polyline3d)dbo;
                if (pline3d_modify.XData.AsArray().Length > 0)
                {
                    ed.WriteMessage("\n桩号为:" + pline3d_modify.XData.AsArray()[1].Value.ToString() + "\n");
                }
                SortedDictionary <double, Polyline3d> hdm_pline3d_dic = new SortedDictionary <double, Polyline3d>();

                RegAppTable apptb1 = trans.GetObject(db.RegAppTableId, OpenMode.ForWrite) as RegAppTable;
                if (!apptb1.Has(appname))
                {
                    RegAppTableRecord app = new RegAppTableRecord();
                    app.Name = appname;
                    apptb1.Add(app);
                    trans.AddNewlyCreatedDBObject(app, true);
                }



                ResultBuffer resultBuffer = new ResultBuffer();

                resultBuffer.Add(new TypedValue((int)DxfCode.ExtendedDataRegAppName, appname));
                resultBuffer.Add(new TypedValue((int)DxfCode.ExtendedDataInteger32, stack));

                pline3d_modify.XData = resultBuffer;

                zjyCAD.ToModelSpace(pline3d_modify, db);

                trans.Commit();
            }
        }
        public ResultBuffer CreateResultBuffer()
        {
            ResultBuffer resultBuffer = new ResultBuffer();

            resultBuffer.Add(new TypedValue(5005, this.DisplayName));
            resultBuffer.Add(CadField.CreateTypedValue(this.Value));
            return(resultBuffer);
        }
        //保存扩展数据
        public void SaveExtendedData()
        {
            ResultBuffer rb = new ResultBuffer();

            rb.Add(_tvHead);
            rb.Add(new TypedValue((int)DxfCode.ExtendedDataReal, _arrowLength));
            rb.Add(new TypedValue((int)DxfCode.ExtendedDataReal, _scale));
            _line.XData = rb;
        }
Beispiel #12
0
        public static ResultBuffer CreateDottedPair(int type1, object value1, int type2, object value2)
        {
            ResultBuffer resultBuffer = new ResultBuffer();

            resultBuffer.Add(new TypedValue(5016));
            resultBuffer.Add(new TypedValue(type1, value1));
            resultBuffer.Add(new TypedValue(5018));
            resultBuffer.Add(new TypedValue(type2, value2));
            resultBuffer.Add(new TypedValue(5017));
            return(resultBuffer);
        }
Beispiel #13
0
        // TODO: This needs lots of tests added
        public string this[string key]
        {
            get
            {
                if (_XData == null)
                {
                    LoadXData();
                }

                if (!_XData.ContainsKey(key))
                {
                    throw new KeyNotFoundException();
                }

                return(_XData[key]);
            }
            set
            {
                Transaction tr  = BaseObject.Database.TransactionManager.TopTransaction;
                DBObject    obj = tr.GetObject(BaseObject, OpenMode.ForWrite);

                ResultBuffer rb        = obj.XData;
                ResultBuffer newBuffer = new ResultBuffer();
                newBuffer.Add(new TypedValue(1001, "JPP"));

                if (rb != null && _XData.ContainsKey(key))
                {
                    for (int i = 0; i < rb.AsArray().Length; i++)//foreach (TypedValue tv in rb)
                    {
                        TypedValue tv       = rb.AsArray()[i];
                        string     data     = tv.Value as string;
                        string[]   keyvalue = data.Split(':');
                        if (keyvalue[0] == key)
                        {
                            TypedValue newTypedValue = new TypedValue(1000, $"{keyvalue[0]}:{value}");
                            newBuffer.Add(newTypedValue);
                        }
                        else
                        {
                            newBuffer.Add(tv);
                        }
                    }
                }
                else
                {
                    TypedValue newTypedValue = new TypedValue(1000, $"{key}:{value}");

                    newBuffer.Add(newTypedValue);
                }

                obj.XData = newBuffer;
            }
        }
Beispiel #14
0
        public ResultBuffer ToBuffer()
        {
            ResultBuffer rb = new ResultBuffer();

            rb.Add(new TypedValue((int)DxfCode.ExtendedDataRegAppName, Convert.ToString(KEY)));
            for (int i = (int)Fields.KEY + 1; i < PropertiesList.Length; i++)
            {
                rb.Add(new TypedValue((int)DxfCode.ExtendedDataAsciiString,
                                      Convert.ToString(PropertiesList[i])));
            }

            return(rb);
        }
Beispiel #15
0
        public static int Command(params object[] args)
        {
            if (AcadApp.DocumentManager.IsApplicationContext)
            {
                return(0);
            }
            int  stat         = 0;
            int  cnt          = 0;
            bool supressOSnap = ShouldSupressRunningOSnap();
            bool transform    = ShouldTransformCoords();

            using (ResultBuffer buffer = new ResultBuffer())
            {
                foreach (object o in args)
                {
                    if (supressOSnap && (o is Point3d || o is Point2d))
                    {
                        buffer.Add(new TypedValue(RTSTR, "_non"));
                    }
                    if (transform && (o is Point3d))
                    {
                        buffer.Add(new TypedValue(RT3DPOINT, WorldToCurrent((Point3d)o)));
                    }
                    else
                    {
                        buffer.Add(TypedValueFromObject(o));
                    }
                    ++cnt;
                }
                if (cnt > 0)
                {
                    string s       = (string)AcadApp.GetSystemVariable("USERS1");
                    bool   debug   = string.Compare(s, "DEBUG", true) == 0;
                    int    val     = debug ? 1 : 0;
                    object cmdecho = AcadApp.GetSystemVariable("CMDECHO");
                    Int16  c       = (Int16)cmdecho;
                    if (c != 0 || debug)
                    {
                        AcadApp.SetSystemVariable("CMDECHO", val);
                    }
                    stat = acedCmd(buffer.UnmanagedObject);
                    if (c != 0 || debug)
                    {
                        AcadApp.SetSystemVariable("CMDECHO", cmdecho);
                    }
                }
            }
            return(stat);
        }
Beispiel #16
0
        /// <summary> 将静态类中的数据保存到<seealso cref="Xrecord"/>对象中 </summary>
        /// <returns></returns>
        public static ResultBuffer ToResultBuffer_SortedStations()
        {
            var generalBuff = new ResultBuffer();
            var count       = AllSortedStations.Length;

            generalBuff.Add(new TypedValue((int)DxfCode.ExtendedDataInteger32, count));
            foreach (var s in AllSortedStations)
            {
                generalBuff.Add(new TypedValue((int)DxfCode.ExtendedDataReal, s));
            }
            //
            //var rec = new Xrecord();
            //rec.Data = generalBuff;
            return(generalBuff);
        }
Beispiel #17
0
        /// <summary>
        /// Записать связь в объект objId с объектом writedId
        /// </summary>
        /// <param name="objId">Объект</param>
        /// <param name="linkIds">Связываемые объекты</param>
        /// <param name="code">Тип связи</param>
        /// /// <param name="replace">Перезаписать существующий словарь LinkCode - true, или добавить если уже существует - false</param>
        public static void WriteLinks(this ObjectId objId, List <ObjectId> linkIds, LinkCode code, bool replace = true)
        {
            var dictId     = GetExtDict(objId);
            var existLinks = ReadLinks(objId, code);
            var addLinkIds = linkIds?.Where(w => !w.IsNull).Except(existLinks).ToList() ?? new List <ObjectId>();
            var dxfCode    = GetDxfCode(code);

            using (var dict = dictId.Open(OpenMode.ForWrite) as DBDictionary)
            {
                var entryName = GetLinkRecordName(code);
                if (dict.Contains(entryName) && replace)
                {
                    dict.Remove(entryName);
                }

                if (!addLinkIds.Any())
                {
                    return;
                }
                using (var xrec = new Xrecord())
                    using (var resBuff = new ResultBuffer())
                    {
                        foreach (var addLinkId in addLinkIds)
                        {
                            resBuff.Add(new TypedValue((int)dxfCode, addLinkId));
                        }

                        xrec.Data = resBuff;
                        dict.SetAt(entryName, xrec);
                    }
            }
        }
Beispiel #18
0
        private static ResultBuffer LoadAssembly(ResultBuffer rbArgs)
        {
            ResultBuffer result = null;

            try
            {
                TypedValue[] args = rbArgs.AsArray();
                var          asm  = System.Reflection.Assembly.LoadFrom(args[0].Value.ToString());
                result.Add(new TypedValue(0x138D, "OK"));
            }
            catch
            {
                result.Add(new TypedValue(0x138D, "Catch Error"));
            }
            return(result);
        }
Beispiel #19
0
        /// <summary>
        /// 调用AutoCad命令
        /// </summary>
        /// <param name="endCommandByUser">命令结束方式</param>
        /// <param name="args">参数</param>
        public static void RunCommand(bool endCommandByUser, params object[] args)
        {
            ResultBuffer rb    = new ResultBuffer();
            ResultBuffer rbend = new ResultBuffer();

            foreach (object val in args)
            {
                AddValueToResultBuffer(ref rb, val);
            }
            try
            {
                Document doc         = cadApplication.DocumentManager.MdiActiveDocument;
                string   currCmdName = doc.CommandInProgress;
                acedCmd(rb.UnmanagedObject);
                if (endCommandByUser)
                {
                    rbend.Add(new TypedValue((int)LispDataType.Text, "\\"));
                }
                while (doc.CommandInProgress != currCmdName)
                {
                    acedCmd(rbend.UnmanagedObject);
                }
            }
            catch { }
            finally
            {
                rb.Dispose();
                rbend.Dispose();
            }
        }
        public object ESRI_GetConnections(ResultBuffer rb)
        {
            object result;

            try
            {
                if (!AGSConnection.bConnectionsLoaded)
                {
                    AGSConnection.LoadConnections();
                }
                if (App.Connections.Count > 0)
                {
                    ResultBuffer resultBuffer = new ResultBuffer();
                    foreach (AGSConnection current in App.Connections)
                    {
                        resultBuffer.Add(new TypedValue(5005, current.Name));
                    }
                    result = resultBuffer;
                }
                else
                {
                    result = null;
                }
            }
            catch
            {
                result = null;
            }
            return(result);
        }
Beispiel #21
0
        public static int Command(params object[] args)
        {
#if !bcad
            if (Application.DocumentManager.IsApplicationContext)
            {
                throw new InvalidCastException("Invalid execution context");
            }
#endif
            int stat = 0;
            int cnt  = 0;
            using (ResultBuffer buffer = new ResultBuffer())
            {
                foreach (object o in args)
                {
                    buffer.Add(TypedValueFromObject(o));
                    ++cnt;
                }
                if (cnt > 0)
                {
#if acad2012
                    stat = acedCmd2012(buffer.UnmanagedObject);
#endif
#if acad2013
                    stat = acedCmd2013(buffer.UnmanagedObject);
#endif
#if bcad
                    Bricscad.Global.Editor.Command(buffer);
#endif
                }
            }
            return(stat);
        }
Beispiel #22
0
        // Função para gravar os dados no Extension Dictionary do objeto dado.
        public void RecOnXDict(DBObject dbObj, string location, DxfCode dxfC, dynamic data, Transaction tr)
        {
            // Pega o Id do XDic do objeto.
            ObjectId extId = dbObj.ExtensionDictionary;

            // Se não existe um XDic, cria-o
            if (extId == ObjectId.Null)
            {
                dbObj.CreateExtensionDictionary();
                extId = dbObj.ExtensionDictionary;
            }

            // Pega o XDic a partir do seu Id.
            DBDictionary dbExt = (DBDictionary)tr.GetObject(extId, OpenMode.ForWrite);

            // Cria um XRecord, que guardará a informação
            Xrecord      xRec = new Xrecord();
            ResultBuffer rb   = new ResultBuffer();

            rb.Add(new TypedValue((int)dxfC, data));

            xRec.Data = rb;

            // Adiciona a informação no XDic do objeto.
            dbExt.SetAt(location, xRec);
            tr.AddNewlyCreatedDBObject(xRec, true);
        }
Beispiel #23
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 #24
0
        public object ESRI_GetFeatureClassList(ResultBuffer rb)
        {
            object result;

            try
            {
                MSCDataset docDataset = AfaDocData.ActiveDocData.DocDataset;
                if (docDataset.FeatureClasses.Count > 0)
                {
                    ResultBuffer resultBuffer = new ResultBuffer();
                    foreach (string current in docDataset.FeatureClasses.Keys)
                    {
                        resultBuffer.Add(new TypedValue(5005, current));
                    }
                    result = resultBuffer;
                }
                else
                {
                    result = null;
                }
            }
            catch
            {
                result = null;
            }
            return(result);
        }
Beispiel #25
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;
        }
Beispiel #26
0
 /// <summary>
 /// acedCmd
 /// eg.
 /// CppImport.RunCommand(false, new object[] { "draworder", id, "", "f" });
 /// CppImport.RunCommand(false, new object[] { "._zoom", "e" });
 /// </summary>
 public static void RunCommand(bool echoCommand, params object[] args)
 {
     if (!Application.DocumentManager.IsApplicationContext)
     {
         int num  = 0;
         int num2 = Convert.ToInt32(Application.GetSystemVariable("CMDECHO"));
         using (ResultBuffer buffer = new ResultBuffer())
         {
             foreach (object obj2 in args)
             {
                 buffer.Add(TypedValueFromObject(obj2));
                 num++;
             }
             if (num > 0)
             {
                 if (!echoCommand)
                 {
                     Application.SetSystemVariable("CMDECHO", 0);
                 }
                 else
                 {
                     Application.SetSystemVariable("CMDECHO", 1);
                 }
                 acedCmd(buffer.UnmanagedObject);
             }
         }
         Application.SetSystemVariable("CMDECHO", num2);
     }
 }
        public void MarkCurrentDrawingAsCivil3D()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;

            using (Transaction trans = doc.TransactionManager.StartTransaction())
            {
                Transaction tr = doc.TransactionManager.TopTransaction;

                // Find the NOD in the database
                DBDictionary nod = (DBDictionary)tr.GetObject(doc.Database.NamedObjectsDictionaryId, OpenMode.ForWrite);

                // We use Xrecord class to store data in Dictionaries
                Xrecord      plotXRecord = new Xrecord();
                ResultBuffer rb          = new ResultBuffer();

                TypedValue tv = new TypedValue((int)DxfCode.Bool, true);
                rb.Add(tv);
                plotXRecord.Data = rb;

                // Create the entry in the Named Object Dictionary
                string id = this.GetType().FullName + "Civil3DRequired";
                nod.SetAt(id, plotXRecord);
                tr.AddNewlyCreatedDBObject(plotXRecord, true);
                trans.Commit();
            }
        }
Beispiel #28
0
        public static void SaveXdata(string data, ObjectId objId)
        {
            // Get the current database and start a transaction
            Database acCurDb;

            acCurDb = acApp.DocumentManager.MdiActiveDocument.Database;

            Document acDoc = acApp.DocumentManager.MdiActiveDocument;

            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                // Open the Registered Applications table for read
                RegAppTable acRegAppTbl;
                acRegAppTbl = acTrans.GetObject(acCurDb.RegAppTableId, OpenMode.ForRead) as RegAppTable;

                // Check to see if the Registered Applications table record for the custom app exists
                if (acRegAppTbl.Has(appName) == false)
                {
                    using (RegAppTableRecord acRegAppTblRec = new RegAppTableRecord())
                    {
                        acRegAppTblRec.Name = appName;

                        acRegAppTbl.UpgradeOpen();
                        acRegAppTbl.Add(acRegAppTblRec);
                        acTrans.AddNewlyCreatedDBObject(acRegAppTblRec, true);
                    }
                }

                // Define the Xdata to add to each selected object
                using (ResultBuffer rb = new ResultBuffer())
                {
                    rb.Add(new TypedValue((int)DxfCode.ExtendedDataRegAppName, appName));
                    rb.Add(new TypedValue((int)DxfCode.ExtendedDataAsciiString, data));

                    // Open the selected object for write
                    Entity acEnt = acTrans.GetObject(objId, OpenMode.ForWrite) as Entity;

                    // Append the extended data to each object
                    acEnt.XData = rb;
                }

                // Save the new object to the database
                acTrans.Commit();

                // Dispose of the transaction
            }
        }
Beispiel #29
0
        public static void SaveTechProsess(CamDocument camDocument)
        {
            if (camDocument.Hash == 0 && !camDocument.TechProcessList.Any())
            {
                return;
            }
            try
            {
                const int kMaxChunkSize = 127;
                using (var resultBuffer = new ResultBuffer())
                {
                    using (MemoryStream stream = new MemoryStream())
                    {
                        BinaryFormatter formatter = new BinaryFormatter();
                        formatter.Serialize(stream, camDocument.TechProcessList);
                        stream.Position = 0;
                        for (int i = 0; i < stream.Length; i += kMaxChunkSize)
                        {
                            int    length    = (int)Math.Min(stream.Length - i, kMaxChunkSize);
                            byte[] datachunk = new byte[length];
                            stream.Read(datachunk, 0, length);
                            resultBuffer.Add(new TypedValue((int)DxfCode.Text, Convert.ToBase64String(datachunk)));
                        }
                    }
                    var newHash = resultBuffer.ToString().GetHashCode();
                    if (newHash == camDocument.Hash)
                    {
                        return;
                    }

                    using (DocumentLock acLckDoc = Acad.ActiveDocument.LockDocument())
                        using (Transaction tr = Acad.Database.TransactionManager.StartTransaction())
                            using (DBDictionary dict = tr.GetObject(Acad.Database.NamedObjectsDictionaryId, OpenMode.ForWrite) as DBDictionary)
                            {
                                if (dict.Contains(DataKey))
                                {
                                    using (var xrec = tr.GetObject(dict.GetAt(DataKey), OpenMode.ForWrite) as Xrecord)
                                        xrec.Data = resultBuffer;
                                }
                                else
                                {
                                    using (var xrec = new Xrecord {
                                        Data = resultBuffer
                                    })
                                    {
                                        dict.SetAt(DataKey, xrec);
                                        tr.AddNewlyCreatedDBObject(xrec, true);
                                        //xrec.ObjectClosed += new ObjectClosedEventHandler(OnDataModified);
                                    }
                                }
                                tr.Commit();
                            }
                }
            }
            catch (Exception e)
            {
                Acad.Alert($"Ошибка при сохранении техпроцессов", e);
            }
        }
Beispiel #30
0
        public static void TestInvokeLisp()
        {
            ResultBuffer args = new ResultBuffer();
            int          stat = 0;

            args.Add(new TypedValue(RTSTR, "testfunc"));
            args.Add(new TypedValue(RTLONG, 100));
            args.Add(new TypedValue(RTLONG, 200));

            ResultBuffer res = InvokeLisp(args, ref stat);

            if (stat == RTNORM && res != null)
            {
                PrintResbuf(res);
                res.Dispose();
            }
        }
Beispiel #31
0
        private static ResultBuffer SoftPointerForId(ObjectId id)
        {
            var rb = new ResultBuffer();
            //var gc = (int)DxfCode.SoftPointerId;
            var gc = (int)DxfCode.HardPointerId;

            rb.Add(new TypedValue(gc, id));
            return(rb);
        }
Beispiel #32
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 #33
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 #34
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 #35
0
        public void UpdateXData()//更新扩展数据
        {
            if (isChanged)
            {
                //下面2行代码锁住文档
                DocumentLock docLock = Autodesk.AutoCAD.ApplicationServices.Application.

              DocumentManager.MdiActiveDocument.LockDocument();

                Document doc = Application.DocumentManager.MdiActiveDocument;

                Transaction tr = doc.TransactionManager.StartTransaction();
                using (tr)
                {
                    DBObject obj = tr.GetObject(this.id, OpenMode.ForWrite);
                    ResultBuffer rb = new ResultBuffer();
                    foreach (KeyValuePair<string, Dictionary<string, string>> kp in this.appName2values)
                    {
                        rb.Add(new TypedValue((int)DxfCode.ExtendedDataRegAppName, kp.Key));
                        foreach (KeyValuePair<string, string> pair in kp.Value)
                        {
                            rb.Add(new TypedValue((int)DxfCode.ExtendedDataAsciiString, pair.Key));
                            rb.Add(new TypedValue((int)DxfCode.ExtendedDataAsciiString, pair.Value));
                        }

                        obj.XData = rb;//替换对应appname的扩展数据
                        rb = new ResultBuffer();
                    }

                    rb.Dispose();
                    tr.Commit();
                }
                isChanged = false;

                //PurgeDatabase(doc.Database);//作为实验,看是否能够清除多余的appname,(暂时不考虑,如果出现问题在考虑这个问题)

                docLock.Dispose();
            }
        }
Beispiel #36
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 #37
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();
            }
        }
Beispiel #38
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 #39
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 #40
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;
                }
            }
        }