コード例 #1
0
 /// <summary>
 /// 在AutoCAD图形中插入块参照
 /// </summary>
 /// <param name="spaceId">块参照要加入的模型空间或图纸空间的Id</param>
 /// <param name="layer">块参照要加入的图层名</param>
 /// <param name="blockName">块参照所属的块名</param>
 /// <param name="position">插入点</param>
 /// <param name="scale">缩放比例</param>
 /// <param name="rotateAngle">旋转角度</param>
 /// <param name="attNameValues">属性的名称与取值</param>
 /// <returns>返回块参照的Id</returns>
 public static ObjectId InsertBlockReference(this ObjectId spaceId, string layer, string blockName, Point3d position, Scale3d scale, double rotateAngle)
 {
     DocumentLock docLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
     ObjectId blockRefId;
     Database db = spaceId.Database;
     BlockTable bt = (BlockTable)db.BlockTableId.GetObject(OpenMode.ForRead);
     if (!bt.Has(blockName)) return ObjectId.Null;
     BlockTableRecord space = (BlockTableRecord)spaceId.GetObject(OpenMode.ForWrite);
     BlockReference br = new BlockReference(position, bt[blockName]);
     br.ScaleFactors = scale;
     br.Layer = layer;
     br.Rotation = rotateAngle;
     ObjectId btrId = bt[blockName];
     BlockTableRecord record = (BlockTableRecord)btrId.GetObject(OpenMode.ForRead);
     if (record.Annotative == AnnotativeStates.True)
     {
         ObjectContextCollection contextCollection = db.ObjectContextManager.GetContextCollection("ACDB_ANNOTATIONSCALES");
         ObjectContexts.AddContext(br, contextCollection.GetContext("1:1"));
     }
     blockRefId = space.AppendEntity(br);
     db.TransactionManager.AddNewlyCreatedDBObject(br, true);
     space.DowngradeOpen();
     docLock.Dispose();
     return blockRefId;
 }
コード例 #2
0
        /// <summary>
        /// 在AutoCAD图形中插入块参照
        /// </summary>
        /// <param name="spaceId">块参照要加入的模型空间或图纸空间的Id</param>
        /// <param name="layer">块参照要加入的图层名</param>
        /// <param name="blockName">块参照所属的块名</param>
        /// <param name="position">插入点</param>
        /// <param name="scale">缩放比例</param>
        /// <param name="rotateAngle">旋转角度</param>
        /// <returns>返回块参照的Id</returns>
        public static ObjectId InsertBlockReference(this ObjectId spaceId, string layer, string blockName, Point3d position, Scale3d scale, double rotateAngle)
        {
            ObjectId blockRefId;            //存储要插入的块参照的Id
            Database db = spaceId.Database; //获取数据库对象
            //以读的方式打开块表
            BlockTable bt = (BlockTable)db.BlockTableId.GetObject(OpenMode.ForRead);

            //如果没有blockName表示的块,则程序返回
            if (!bt.Has(blockName))
            {
                return(ObjectId.Null);
            }
            //以写的方式打开空间(模型空间或图纸空间)
            BlockTableRecord space = (BlockTableRecord)spaceId.GetObject(OpenMode.ForWrite);
            //创建一个块参照并设置插入点
            BlockReference br = new BlockReference(position, bt[blockName]);

            br.ScaleFactors = scale;        //设置块参照的缩放比例
            br.Layer        = layer;        //设置块参照的层名
            br.Rotation     = rotateAngle;  //设置块参照的旋转角度
            ObjectId btrId = bt[blockName]; //获取块表记录的Id
            //打开块表记录
            BlockTableRecord record = (BlockTableRecord)btrId.GetObject(OpenMode.ForRead);

            //添加可缩放性支持
            if (record.Annotative == AnnotativeStates.True)
            {
                ObjectContextCollection contextCollection = db.ObjectContextManager.GetContextCollection("ACDB_ANNOTATIONSCALES");
                ObjectContexts.AddContext(br, contextCollection.GetContext("1:1"));
            }
            blockRefId = space.AppendEntity(br);                     //在空间中加入创建的块参照
            db.TransactionManager.AddNewlyCreatedDBObject(br, true); //通知事务处理加入创建的块参照
            space.DowngradeOpen();                                   //为了安全,将块表状态改为读
            return(blockRefId);                                      //返回添加的块参照的Id
        }
コード例 #3
0
 public void Write(Scale3d t)
 {
     Write(t.V);
 }
コード例 #4
0
        /// <summary>
        /// 在AutoCAD图形中插入块参照
        /// </summary>
        /// <param name="spaceId">块参照要加入的模型空间或图纸空间的Id</param>
        /// <param name="layer">块参照要加入的图层名</param>
        /// <param name="blockName">块参照所属的块名</param>
        /// <param name="position">插入点</param>
        /// <param name="scale">缩放比例</param>
        /// <param name="rotateAngle">旋转角度</param>
        /// <param name="attNameValues">属性的名称与取值</param>
        /// <returns>返回块参照的Id</returns>
        public static ObjectId InsertBlockReference(this ObjectId spaceId, string layer, string blockName, Point3d position, Scale3d scale, double rotateAngle, Dictionary <string, string> attNameValues)
        {
            Database db = spaceId.Database;//获取数据库对象
            //以读的方式打开块表
            BlockTable bt = (BlockTable)db.BlockTableId.GetObject(OpenMode.ForRead);

            //如果没有blockName表示的块,则程序返回
            if (!bt.Has(blockName))
            {
                return(ObjectId.Null);
            }
            //以写的方式打开空间(模型空间或图纸空间)
            BlockTableRecord space = (BlockTableRecord)spaceId.GetObject(OpenMode.ForWrite);
            ObjectId         btrId = bt[blockName];//获取块表记录的Id
            //打开块表记录
            BlockTableRecord record = (BlockTableRecord)btrId.GetObject(OpenMode.ForRead);
            //创建一个块参照并设置插入点
            BlockReference br = new BlockReference(position, bt[blockName]);

            br.ScaleFactors = scale;       //设置块参照的缩放比例
            br.Layer        = layer;       //设置块参照的层名
            br.Rotation     = rotateAngle; //设置块参照的旋转角度
            space.AppendEntity(br);        //为了安全,将块表状态改为读
            //判断块表记录是否包含属性定义
            if (record.HasAttributeDefinitions)
            {
                //若包含属性定义,则遍历属性定义
                foreach (ObjectId id in record)
                {
                    //检查是否是属性定义
                    AttributeDefinition attDef = id.GetObject(OpenMode.ForRead) as AttributeDefinition;
                    if (attDef != null)
                    {
                        //创建一个新的属性对象
                        AttributeReference attribute = new AttributeReference();
                        //从属性定义获得属性对象的对象特性
                        attribute.SetAttributeFromBlock(attDef, br.BlockTransform);
                        //设置属性对象的其它特性
                        attribute.Position = attDef.Position.TransformBy(br.BlockTransform);
                        attribute.Rotation = attDef.Rotation;
                        attribute.AdjustAlignment(db);
                        //判断是否包含指定的属性名称
                        if (attNameValues.ContainsKey(attDef.Tag.ToUpper()))
                        {
                            //设置属性值
                            attribute.TextString = attNameValues[attDef.Tag.ToUpper()].ToString();
                        }
                        //向块参照添加属性对象
                        br.AttributeCollection.AppendAttribute(attribute);
                        db.TransactionManager.AddNewlyCreatedDBObject(attribute, true);
                    }
                }
            }
            db.TransactionManager.AddNewlyCreatedDBObject(br, true);
            return(br.ObjectId);//返回添加的块参照的Id
        }
コード例 #5
0
ファイル: Block.cs プロジェクト: vildar82/AcadLib
        public static void Normalize(this BlockReference blRef)
        {
            // Корректировка масштабирования и зеркальности
            var scale1 = new Scale3d(1);
            if (blRef.ScaleFactors != scale1)
            {
                blRef.ScaleFactors = scale1;
                //var matScale = blRef.ScaleFactors.GetMatrix();
                //matScale = matScale.Inverse();
                //mat = mat * matScale;
            }

            if (blRef.Rotation != 0)
            {
                var matRotate = Matrix3d.Rotation(-blRef.Rotation, Vector3d.ZAxis, blRef.Position);
                blRef.TransformBy(matRotate);
            }

            //if (mat != Matrix3d.Identity)
            //{
            //    blRef.TransformBy(mat);
            //    var boundsNew = blRef.GeometricExtents;
            //    var vecMove = boundsBefore.MinPoint - boundsNew.MinPoint;
            //    if (vecMove.Length != 0)
            //    {
            //        var move = Matrix3d.Displacement(vecMove);
            //        blRef.TransformBy(move);
            //    }
            //}
        }
コード例 #6
0
ファイル: ComLibClass.cs プロジェクト: zuiyuewu1102/ML
        /// <summary>
        /// 用于在AutoCAD图形中插入块参照
        /// </summary>
        /// <param name="spaceId">块参照要加入的模型空间或图纸空间的Id</param>
        /// <param name="layer">块参照要加入的图层名</param>
        /// <param name="blockName">块参照所属的块名</param>
        /// <param name="position">块参照的插入点</param>
        /// <param name="scale">块参照的缩放比例</param>
        /// <param name="rotateAngle">块参照的旋转角度</param>
        /// <returns></returns>
        public static ObjectId InsertBlockReference(this ObjectId spaceId, string layer, string blockName, Point3d position, Scale3d scale, double rotateAngle)
        {
            ObjectId blockRefId;
            Database db = spaceId.Database;
            //打开块表
            BlockTable bt = (BlockTable)db.BlockTableId.GetObject(OpenMode.ForRead);

            if (!bt.Has(blockName))
            {
                return(ObjectId.Null);
            }
            //以写的方式打开空间(模型空间或图纸空间)
            BlockTableRecord space = (BlockTableRecord)spaceId.GetObject(OpenMode.ForWrite);
            //创建一个块参照并设置插入点
            BlockReference br = new BlockReference(position, bt[blockName]);

            //设置块参照的缩放比例
            br.ScaleFactors = scale;
            //设置块参照的层名
            br.Layer = layer;
            //设置块参照的旋转角度
            br.Rotation = rotateAngle;
            //在空间中加入创建的块参照
            blockRefId = space.AppendEntity(br);
            //通知事务处理加入创建的块参照
            db.TransactionManager.AddNewlyCreatedDBObject(br, true);
            space.DowngradeOpen();
            return(blockRefId);
        }
コード例 #7
0
ファイル: SubClass.cs プロジェクト: caobinh92/Autocad
        public Extents3d GetExtents3dFromInsertPointOfBlockReferenceAndTwoVectorsWithScale(BlockReference acBlkRef, Vector3d[] acVec3dOrgArr, Scale3d acScl3dOrg)
        {
            Point3d acPtIns = acBlkRef.Position;
            //Application.ShowAlertDialog(acPtIns.ToString());
            //Application.ShowAlertDialog(acScl3dOrg.X.ToString());
            //Application.ShowAlertDialog("Insert Point: \n" + acPtIns.ToString() + "\nScale: \n" + acBlkRef.ScaleFactors.X.ToString() + "\nVector 0: \n" + acVec3dOrgArr[0].ToString());
            Point3d   acPt1   = new Point3d(acPtIns.X + acVec3dOrgArr[0].X * acBlkRef.ScaleFactors.X / acScl3dOrg.X, acPtIns.Y + acVec3dOrgArr[0].Y * acBlkRef.ScaleFactors.Y / acScl3dOrg.Y, 0);
            Point3d   acPt2   = new Point3d(acPtIns.X + acVec3dOrgArr[1].X * acBlkRef.ScaleFactors.X / acScl3dOrg.X, acPtIns.Y + acVec3dOrgArr[1].Y * acBlkRef.ScaleFactors.Y / acScl3dOrg.Y, 0);
            Extents3d acExt3d = new Extents3d(acPt1, acPt2);

            //Application.ShowAlertDialog(acExt3d.ToString());
            return(acExt3d);
        }
コード例 #8
0
 public override void WriteScale3d(Scale3d value)
 {
 }
コード例 #9
0
ファイル: XrefTools.cs プロジェクト: coordinate/MyLearnning
        /// <summary>
        /// 将外部参照插入到图形
        /// </summary>
        /// <param name="db">数据库对象</param>
        /// <param name="fileName">包含完整路径的外部参照文件名</param>
        /// <param name="blockName">参照名</param>
        /// <param name="insertionPoint">外部参照块的插入点</param>
        /// <param name="scaleFactors">外部参照块的缩放因子</param>
        /// <param name="rotation">外部参照块的旋转角度,以弧度表示</param>
        /// <param name="isOverlay">外部参照块的类型,为true时表示覆盖,为false时表示附着</param>
        /// <returns></returns>
        public static ObjectId AttachXref(this Database db, string fileName, string blockName, Point3d insertionPoint, Scale3d scaleFactors, double rotation, bool isOverlay)
        {
            ObjectId xrefId = ObjectId.Null;//外部参照的Id

            //选择以覆盖的方式插入外部参照
            if (isOverlay)
            {
                xrefId = db.OverlayXref(fileName, blockName);
            }
            //选择以附着的方式插入外部参照
            else
            {
                xrefId = db.AttachXref(fileName, blockName);
            }
            //根据外部参照创建一个块参照,并指定其插入点
            BlockReference bref = new BlockReference(insertionPoint, xrefId);

            bref.ScaleFactors = scaleFactors; //外部参照块的缩放因子
            bref.Rotation     = rotation;     //外部参照块的旋转角度
            db.AddToModelSpace(bref);         //将外部参照块添加到模型空间
            return(xrefId);                   //返回外部参照的Id
        }
コード例 #10
0
ファイル: SubClass.cs プロジェクト: caobinh92/Autocad
        public Extents3d[] GetExtents3dBlockReferenceCollection(DocumentCollection acDocMgr, string BlockName, Vector3d[] acVec3dOrgArr, Scale3d acScl3dOrg)
        {
            DBObjectCollection acBlkRefCol = GetBlockReferenceCollectionByName(acDocMgr, BlockName);

            Extents3d[] acExt3dCol = new Extents3d[acBlkRefCol.Count];
            for (int i = 0; i < acBlkRefCol.Count; i++)
            {
                acExt3dCol[i] = GetExtents3dFromInsertPointOfBlockReferenceAndTwoVectorsWithScale((BlockReference)acBlkRefCol[i], acVec3dOrgArr, acScl3dOrg);
            }
            return(acExt3dCol);
        }
コード例 #11
0
 public static void FromTrafo3d()
 => TrafoTesting.GenericConversionTest(TrafoTesting.GetRandomScale3, a => (Trafo3d)a, b => Scale3d.FromTrafo3d(b));
コード例 #12
0
 public static void FromSimilarity3d()
 => TrafoTesting.GenericConversionTest(rnd => new Scale3d(rnd.UniformDouble() * 10), a => Similarity3d.FromScale3d(a), b => Scale3d.FromSimilarity3d(b));
コード例 #13
0
        public override void Add()
        {
            Document doc = AcAp.DocumentManager.MdiActiveDocument;
            Database db  = doc.Database;
            Editor   ed  = doc.Editor;

            var intensity1 = ed.GetString(new PromptStringOptions("Nhap gia tri luc cua diem dau tien"));

            if (intensity1.Status != PromptStatus.OK)
            {
                ed.WriteMessage("\nDa huy lenh them luc.");
                return;
            }

            var intensity2 = ed.GetString(new PromptStringOptions("Nhap gia tri luc cua diem sau"));

            if (intensity2.Status != PromptStatus.OK)
            {
                ed.WriteMessage("\nDa huy lenh them luc.");
                return;
            }

            PromptEntityResult objectId = ed.GetEntity("\nChon vat ma luc phan bo tac dong vao");

            if (objectId.Status != PromptStatus.OK)
            {
                ed.WriteMessage("\nDa huy lenh them luc phan bo.");
                return;
            }

            PromptPointResult point1 = ed.GetPoint(new PromptPointOptions("\nChon cac diem dat luc dau tien"));

            if (point1.Status != PromptStatus.OK)
            {
                ed.WriteMessage("\nDa huy lenh them luc phan bo.");
                return;
            }

            PromptPointResult point2 = ed.GetPoint(new PromptPointOptions("\nChon cac diem dat luc thu hai"));

            if (point2.Status != PromptStatus.OK)
            {
                ed.WriteMessage("\nDa huy lenh them luc phan bo.");
                return;
            }

            PromptAngleOptions pdo = new PromptAngleOptions("\nNhap goc nghieng:");

            pdo.AllowArbitraryInput = true;
            pdo.AllowNone           = true;
            pdo.AllowZero           = true;
            pdo.DefaultValue        = 0;
            pdo.UseDefaultValue     = true;
            PromptDoubleResult angle = ed.GetAngle(pdo);

            if (angle.Status != PromptStatus.OK)
            {
                ed.WriteMessage("\nDa huy lenh them luc phan bo. Vi khong lay duoc goc.");
                return;
            }

            string partDwg = @"Drawings\DistributedLoad.dwg";

            ////////////////////////
            Point3d point  = new Point3d((point1.Value.X + point2.Value.X) / 2, (point1.Value.Y + point2.Value.Y) / 2, 0);
            double  length = Math.Sqrt(Math.Pow(point1.Value.X - point2.Value.X, 2) + Math.Pow(point1.Value.Y - point2.Value.Y, 1));

            if (Math.Round(length, Common.numberOfMathRound) == 0)
            {
                ed.WriteMessage("\nDa huy lenh them luc phân bo. Vì kich thuoc khong the trung nhau.");
                return;
            }
            Scale3d scale = new Scale3d(Common.scale, length / Common.lengthOfDistributedLoad, 1);

            if (Common.InsertDrawing(partDwg, scale, point, angle.Value, out ObjectId idDistributedLoad) == false)
            {
                ed.WriteMessage("\nDa huy lenh them luc phân bo. Vi khong the ve duoc ban ve.");
                return;
            }

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                Common.AddRegAppTableRecord("Data_MechanicalCalculation");
                TypedValue   typedValue = new TypedValue(1000, intensity1 + "," + intensity2 + "," + objectId.ToString() + "," + point1.Value.X + "," + point1.Value.Y + "," + point2.Value.X + "," + point2.Value.Y);
                ResultBuffer rb         = new ResultBuffer(new TypedValue(1001, "Data_MechanicalCalculation"), typedValue);
                tr.GetObject(idDistributedLoad, OpenMode.ForWrite).XData = rb;
                rb.Dispose();
                tr.Commit();
            }
        }
コード例 #14
0
        /// DocumentLock m_DocumentLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
        ///  代码...
        /// m_DocumentLock.Dispose();
        ///
        public bool GenerateBlockPreview(string openFilePath)
        {
            bool     proEnd  = false;
            Database db      = HostApplicationServices.WorkingDatabase;
            ObjectId spaceId = db.CurrentSpaceId;//获取当前空间(模型空间或图纸空间)
            Editor   ed      = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            // 提示用户选择文件
            //PromptFileNameResult result = ed.GetFileNameForOpen("请选择需要预览的文件");
            //if (result.Status != PromptStatus.OK) return; // 如果未选择,则返回
            //string filename = result.StringResult; // 获取带有路径的文件名
            string filename = openFilePath;
            // 在C盘根目录下创建一个临时文件夹,用来存放文件中的块预览图标
            string path = string.Empty;

#if DEBUG
            path = StockLocation;// "C:\\Temp";

            //string b=
#else
            path = "..\\Resourse\\";
#endif

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                try
                {
                    DocumentLock m_DocumentLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();

                    // 导入外部文件中的块
                    db.ImportBlocksFromDwg(filename);
                    //打开块表
                    BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
                    // 循环遍历块表中的块表记录
                    //int i=0;
                    foreach (ObjectId blockRecordId in bt)
                    {
                        // 打开 块表 记录对象
                        BlockTableRecord btRecord = (BlockTableRecord)trans.GetObject(blockRecordId, OpenMode.ForRead);
                        // 如果是匿名块、布局块及没有预览图形的块,则返回
                        if (btRecord.IsAnonymous || btRecord.IsLayout || !btRecord.HasPreviewIcon)
                        {
                            continue;
                        }

                        Bitmap preview;
                        try
                        {
                            StringBuilder str = new StringBuilder();
                            if (!btRecord.IsDynamicBlock)
                            {
                                str.Append("D");
                            }

                            if (btRecord.ExtensionDictionary == null)
                            {
                                str.Append("E");
                            }

                            // 获取块预览图案(适用于AutoCAD 2008及以下版本)
                            //preview = BlockThumbnailHelper.GetBlockThumbanail(btr.ObjectId);

                            preview = btRecord.PreviewIcon;                                            // 适用于AutoCAD 2009及以上版本
                            preview.Save(path + "\\" + btRecord.Name + "_" + str.ToString() + ".bmp"); // 保存块预览图案


                            //自动整理图块比例
                            //listBox1.Items.Add(btRecord.Name);
                            autoBlockFit(db, btRecord, trans);

                            /*if (sizeEntity.ContainsKey(btRecord.Name))
                             * {
                             *  objectBound objectSize=new objectBound();
                             *  objectSize= sizeEntity[btRecord.Name];
                             *  objectSize.GetType();
                             *  Point3d downLeft = objectSize.downLeftPoint;
                             *  double objSize = objectSize.upRightPoint.X - objectSize.downLeftPoint.X;// objectSize.upRightPoint.Y - objectSize.downLeftPoint.Y);
                             * double scaleSize=30/objSize;
                             *  //string a = objectSize.;
                             *  //Scale(blockRecordId, downLeft, scaleSize);
                             * }*/


                            //int numa = sizeEntity.Count;
                            //重新生成块
                            //btr.
                            //在图中插入 块参照 (画块)
                            objectBound objectSize = sizeEntity[btRecord.Name];

                            Point3d insetP = new Point3d(Point3d.Origin.X - objectSize.downLeftPoint.X, Point3d.Origin.Y - objectSize.downLeftPoint.Y, 0);
                            Scale3d scaleX = new Scale3d(30 / (objectSize.upRightPoint.X - objectSize.downLeftPoint.X));
                            Scale3d scaleY = new Scale3d(30 / (objectSize.upRightPoint.X - objectSize.downLeftPoint.Y));
                            Scale3d scaleE;
                            Point3d a = btRecord.Origin;
                            if (scaleX.X > scaleY.X)
                            {
                                scaleE = scaleY;
                            }
                            else
                            {
                                scaleE = scaleX;
                            }


                            //spaceId.InsertBlockReference("0", btRecord.Name, new Point3d(Point3d.Origin.X, Point3d.Origin.Y, 0), scaleE, 0);


                            LayerTable lt = db.LayerTableId.GetObject(OpenMode.ForRead) as LayerTable;
                            if (!lt.Has("1"))
                            {
                                LayerTableRecord ltr = new LayerTableRecord();
                                ltr.Name = "1";
                                lt.UpgradeOpen();
                                lt.Add(ltr);
                                db.TransactionManager.AddNewlyCreatedDBObject(ltr, true);
                                lt.DowngradeOpen();
                            }

                            if ((btRecord.Origin.X <= objectSize.upRightPoint.X || btRecord.Origin.X >= objectSize.downLeftPoint.X) && (btRecord.Origin.Y <= objectSize.upRightPoint.Y || btRecord.Origin.Y >= objectSize.downLeftPoint.Y))
                            {
                                spaceId.InsertBlockReference("0", btRecord.Name, new Point3d(Point3d.Origin.X, Point3d.Origin.Y, 0), scaleE, 0);
                            }
                            else
                            {
                                spaceId.InsertBlockReference("1", btRecord.Name, insetP, scaleE, 0);
                            }
                            //spaceId.InsertBlockReference("1", btRecord.Name, insetP, scaleE, 0);

                            /*
                             * DBText text1 = new DBText();
                             * text1.TextString = "layer0";
                             * text1.Height = 20;
                             * text1.Position = new Point3d(Point3d.Origin.X, Point3d.Origin.Y, 0);
                             * DBText text2 = new DBText();
                             * text2.TextString = "layer1";
                             * text2.Height = 20;
                             * text2.Position = insetP;
                             * db.AddToModelSpace(text1, text2);
                             * trans.Commit();
                             */
                        }
                        catch (Exception ee)
                        {
                            trans.Abort();
                            ed.WriteMessage("错误;  " + ee.ToString());
                            //preview = btr.PreviewIcon; // 适用于AutoCAD 2009及以上版本
                        }
                    }
                    //
                    trans.Commit();
                    int numa = sizeEntity.Count;
                    foreach (var item in typeAndNum)
                    {
                        listBox1.Items.Add("type " + item.Key + "; Number: " + item.Value);
                    }
                    m_DocumentLock.Dispose();


                    fillImageList("C:\\Temp", defSize);
                    fileListView("C:\\Temp");
                    proEnd = true;
                }
                catch (Exception ee)
                {
                    trans.Abort();
                    MessageBox.Show("" + ee, "error");
                }
            }
            return(proEnd);
        }
コード例 #15
0
        public ObjectId InsertBlockReference(Database db, string layerName,
                                             string blockName, Point3d position, double rotation, Scale3d scale, Dictionary <string, string> attNamevalues)
        {
            using (var trans = db.TransactionManager.StartTransaction())
            {
                var blkTbl = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;


                if (!blkTbl.Has(blockName))
                {
                    return(ObjectId.Null);
                }

                var oId = blkTbl[blockName];

                var spaceRec = trans.GetObject(db.CurrentSpaceId, OpenMode.ForRead) as BlockTableRecord;

                var blkTblRec = trans.GetObject(oId, OpenMode.ForRead) as BlockTableRecord;



                BlockReference br = new BlockReference(position, oId);

                br.ScaleFactors = scale;

                br.Rotation = rotation;

                br.Layer = layerName;


                spaceRec.UpgradeOpen();
                ObjectId brId = spaceRec.AppendEntity(br);
                trans.AddNewlyCreatedDBObject(br, true);
                spaceRec.DowngradeOpen();

                if (blkTblRec.HasAttributeDefinitions)
                {
                    foreach (ObjectId id in blkTblRec)
                    {
                        var attr = trans.GetObject(id, OpenMode.ForRead) as AttributeDefinition;

                        if (attr != null)
                        {
                            AttributeReference attrRef = new AttributeReference();

                            attrRef.SetAttributeFromBlock(attr, br.BlockTransform);

                            attrRef.Position = attr.Position.TransformBy(br.BlockTransform);

                            attrRef.Rotation = attr.Rotation;

                            attrRef.AdjustAlignment(db);

                            if (attNamevalues.ContainsKey(attr.Tag.ToString()))
                            {
                                attrRef.TextString = attNamevalues[attr.Tag.ToUpper()];
                            }

                            br.AttributeCollection.AppendAttribute(attrRef);
                            trans.AddNewlyCreatedDBObject(attrRef, true);
                        }
                    }
                }
                trans.Commit();
                return(brId);
            }
        }
コード例 #16
0
ファイル: Misc.cs プロジェクト: 15831944/EM
 ScaleToStr(Scale3d sc)
 {
     return(ScaleToStr(sc, DistanceUnitFormat.Current, -1));
 }
コード例 #17
0
        public ObjectId InsertBlockReference(Database db, string layerName,
                                             string blockName, Point3d position, double rotation, Scale3d scale)
        {
            using (var trans = db.TransactionManager.StartTransaction())
            {
                var blkTbl = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;

                if (!blkTbl.Has(blockName))
                {
                    return(ObjectId.Null);
                }

                var oId = blkTbl[blockName];

                var spaceRec = trans.GetObject(db.CurrentSpaceId, OpenMode.ForRead) as BlockTableRecord;

                BlockReference br = new BlockReference(position, oId);

                br.ScaleFactors = scale;

                br.Rotation = rotation;

                br.Layer = layerName;

                spaceRec.UpgradeOpen();

                ObjectId brId = spaceRec.AppendEntity(br);

                trans.AddNewlyCreatedDBObject(br, true);

                spaceRec.DowngradeOpen();

                trans.Commit();

                return(brId);
            }
        }
コード例 #18
0
ファイル: Tools.cs プロジェクト: ffzznjxk/AutoCADPlugin
        /// <summary>
        /// 车位排序
        /// </summary>
        /// <param name="isUpToDown">从上到下</param>
        public static void OrderCarBlock(bool isUpToDown = true)
        {
            Database db = HostApplicationServices.WorkingDatabase;

            using (var tr = db.TransactionManager.StartTransaction())
            {
                //选择车和索引
                var blocks = db.GetSelectionOfBlockRefs("\n选择车或索引", false,
                                                        carBlockName, indexBlockName);
                //删除原索引
                var indexs = blocks.Where(d => d.GetBlockName() == indexBlockName).ToList();
                if (indexs.Count > 0)
                {
                    foreach (var index in indexs)
                    {
                        index.UpgradeOpen();
                        index.Erase();
                    }
                }
                //选择的车
                var cars = blocks.Where(d => d.GetBlockName() == carBlockName).ToList();
                if (cars.Count != 0)
                {
                    //添加块定义
                    if (AddIndexBtr())
                    {
                        //从上到下
                        if (isUpToDown)
                        {
                            cars = cars.OrderBy(car => car.Position.X)
                                   .ThenByDescending(d => d.Position.Y).ToList();
                        }
                        //从下到上
                        else
                        {
                            cars = cars.OrderBy(car => car.Position.X)
                                   .ThenBy(d => d.Position.Y).ToList();
                        }

                        for (int i = 0; i < cars.Count; i++)
                        {
                            BlockReference car = cars[i];
                            Dictionary <string, string> atts = new Dictionary <string, string>
                            {
                                { "编号", $"{i + 1:D2}" }
                            };
                            //车位图形中点
                            var pt = new LineSegment3d(car.GeometricExtents.MinPoint,
                                                       car.GeometricExtents.MaxPoint).MidPoint;
                            var scale = new Scale3d(100);
                            //添加索引块
                            db.CurrentSpaceId.InsertBlockReference("0", indexBlockName, pt, scale, 0, atts);
                        }
                    }
                }
                else
                {
                    AcadApp.ShowAlertDialog("选中数量为0");
                }
                tr.Commit();
            }
        }
コード例 #19
0
        /// <summary>
        /// 在AutoCAD图形中插入块参照
        /// </summary>
        /// <param name="spaceId">块参照要加入的模型空间或图纸空间的Id</param>
        /// <param name="layer">块参照要加入的图层名</param>
        /// <param name="blockName">块参照所属的块名</param>
        /// <param name="position">插入点</param>
        /// <param name="scale">缩放比例</param>
        /// <param name="rotateAngle">旋转角度</param>
        /// <param name="attNameValues">属性的名称与取值</param>
        /// <returns>返回块参照的Id</returns>
        public static ObjectId InsertBlockReference(this ObjectId spaceId, string layer, string blockName, Point3d position, Scale3d scale, double rotateAngle)
        {
            DocumentLock docLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
            ObjectId     blockRefId;
            Database     db = spaceId.Database;
            BlockTable   bt = (BlockTable)db.BlockTableId.GetObject(OpenMode.ForRead);

            if (!bt.Has(blockName))
            {
                return(ObjectId.Null);
            }
            BlockTableRecord space = (BlockTableRecord)spaceId.GetObject(OpenMode.ForWrite);
            BlockReference   br    = new BlockReference(position, bt[blockName]);

            br.ScaleFactors = scale;
            br.Layer        = layer;
            br.Rotation     = rotateAngle;
            ObjectId         btrId  = bt[blockName];
            BlockTableRecord record = (BlockTableRecord)btrId.GetObject(OpenMode.ForRead);

            if (record.Annotative == AnnotativeStates.True)
            {
                ObjectContextCollection contextCollection = db.ObjectContextManager.GetContextCollection("ACDB_ANNOTATIONSCALES");
                ObjectContexts.AddContext(br, contextCollection.GetContext("1:1"));
            }
            blockRefId = space.AppendEntity(br);
            db.TransactionManager.AddNewlyCreatedDBObject(br, true);
            space.DowngradeOpen();
            docLock.Dispose();
            return(blockRefId);
        }
コード例 #20
0
 public override void WriteScale3d(Scale3d value)
 {
     Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
     ed.WriteMessage(MethodInfo.GetCurrentMethod().Name + " = ");
     ed.WriteMessage(value.ToString()+"\n");
 }
コード例 #21
0
ファイル: AcadEntity.cs プロジェクト: tevfikoguz/XCOM
        public static BlockReference CreateBlockReference(Database db, ObjectId blockId, Point3d insertionPoint, Scale3d scaleFactors, double rotation)
        {
            using (CurrentDB curr = new CurrentDB(db))
            {
                BlockReference blockRef = new BlockReference(insertionPoint, blockId);
                blockRef.SetDatabaseDefaults(db);

                blockRef.ScaleFactors = scaleFactors;
                blockRef.Rotation     = rotation;

                return(blockRef);
            }
        }