Ejemplo n.º 1
0
        private void WriteGroup(Group group, string ownerHandle)
        {
            this.chunk.Write(0, group.CodeName);
            this.chunk.Write(5, group.Handle);
            this.chunk.Write(330, ownerHandle);

            this.chunk.Write(100, SubclassMarker.Group);

            this.chunk.Write(300, this.EncodeNonAsciiCharacters(group.Description));
            this.chunk.Write(70, group.IsUnnamed ? (short) 1 : (short) 0);
            this.chunk.Write(71, group.IsSelectable ? (short) 1 : (short) 0);

            foreach (EntityObject entity in group.Entities)
            {
                this.chunk.Write(340, entity.Handle);
            }
        }
Ejemplo n.º 2
0
        private Group ReadGroup()
        {
            string handle = null;
            string description = null;
            string name = null;
            bool isUnnamed = true;
            bool isSelectable = true;
            List<string> entities = new List<string>();
            this.chunk.Next();
            while (this.chunk.Code != 0)
            {
                switch (this.chunk.Code)
                {
                    case 5:
                        handle = this.chunk.ReadHex();
                        this.chunk.Next();
                        break;
                    case 330:
                        string handleOwner = this.chunk.ReadHex();
                        DictionaryObject dict = this.dictionaries[handleOwner];
                        if (handle == null)
                            throw new NullReferenceException("Null handle in Group dictionary.");
                        name = dict.Entries[handle];
                        this.chunk.Next();
                        break;
                    case 300:
                        description = this.DecodeEncodedNonAsciiCharacters(this.chunk.ReadString());
                        this.chunk.Next();
                        break;
                    case 70:
                        isUnnamed = this.chunk.ReadShort() != 0;
                        this.chunk.Next();
                        break;
                    case 71:
                        isSelectable = this.chunk.ReadShort() != 0;
                        this.chunk.Next();
                        break;
                    case 340:
                        string entity = this.chunk.ReadHex();
                        entities.Add(entity);
                        this.chunk.Next();
                        break;
                    default:
                        this.chunk.Next();
                        break;
                }
            }

            // we need to keep track of the group names generated
            if (isUnnamed)
                this.CheckGroupName(name);

            Group group = new Group(name, false)
            {
                Handle = handle,
                Description = description,
                IsUnnamed = isUnnamed,
                IsSelectable = isSelectable
            };

            // the group entities will be processed later
            this.groupEntities.Add(group, entities);

            return group;
        }
Ejemplo n.º 3
0
        private static void WriteGroup()
        {
            Line line1 = new Line(new Vector2(0, 0), new Vector2(100, 100));
            Line line2 = new Line(new Vector2(100, 0), new Vector2(200, 100));
            Line line3 = new Line(new Vector2(200, 0), new Vector2(300, 100));

            // named group
            Group group1 = new Group("MyGroup", new EntityObject[] {line1, line2});

            //unnamed group
            Group group2 = new Group(new EntityObject[] {line1, line3});

            DxfDocument dxf = new DxfDocument();
            // the AddGroup method will also add the entities contained in a group to the document.
            dxf.Groups.Add(group1);
            dxf.Groups.Add(group2);

            List<DxfObject> list = dxf.Groups.GetReferences(group1);
            dxf.Save("group.dxf");

            dxf = DxfDocument.Load("group.dxf");

            group1 = dxf.Groups[group1.Name];
            group2 = dxf.Groups[group2.Name];
            dxf.Groups.Remove(group1);
            dxf.Groups.Remove(group2);
            dxf.Save("group copy.dxf");


        }
Ejemplo n.º 4
0
        public static void ModifyingGroups()
        {
            Line line1 = new Line(new Vector2(0, 0), new Vector2(100, 100));
            line1.Color = AciColor.Red;
            Line line2 = new Line(new Vector2(100, 0), new Vector2(200, 100));
            line2.Color = AciColor.Yellow;
            Line line3 = new Line(new Vector2(200, 0), new Vector2(300, 100));
            line3.Color = AciColor.Magenta;

            DxfDocument doc = new DxfDocument();

            Block blk = new Block("MyBlock");
            blk.Entities.Add(line1);
            Insert ins = new Insert(blk);
            doc.AddEntity(ins);

            doc.AddEntity(line2);

            Layout layout = new Layout("Layout1");
            doc.Layouts.Add(layout);
            doc.ActiveLayout = layout.Name;
            doc.AddEntity(line3);
            
            // group
            Group group = new Group("MyGroup");
            doc.Groups.Add(group);

            // the Add method will also add the entities contained in a group to the document (in the active layout).
            doc.Groups.Add(group);

            // when the group belongs to a document, all entities must belong to the same document.
            // even if it does not sound very useful, a group can contain entities that belongs to different layouts and even blocks.
            group.Entities.Add(line1);
            group.Entities.Add(line2);
            group.Entities.Add(line3);

            Line line4 = new Line(new Vector2(300, 0), new Vector2(400, 100));
            line4.Color = AciColor.Blue;
            // if a new entity, that does not belong to any document, is added to the group, it will be added to the group document active layout.
            doc.ActiveLayout = Layout.ModelSpaceName;
            group.Entities.Add(line4);

            Line line5 = new Line(new Vector2(400, 0), new Vector2(500, 100));
            line5.Color = AciColor.Green;
            DxfDocument doc2 = new DxfDocument();
            doc2.AddEntity(line5);

            // this is illegal, line5 belongs to another document.
            //group.Entities.Add(line5);
            // you need to clone the entity before adding it to the group. This is also the common practice to copy entities between documents.
            group.Entities.Add((EntityObject) line5.Clone());

            // remember removing a group only deletes it from the collection not the entities
            //doc.Groups.Remove(group);
            doc.Save("group.dxf");

            doc = DxfDocument.Load("group.dxf");
        }
Ejemplo n.º 5
0
        private static void MakingGroups()
        {
            Line line1 = new Line(Vector2.Zero, Vector2.UnitX);
            Line line2 = new Line(Vector2.Zero, Vector2.UnitY);
            Group group = new Group();
            group.Entities.Add(line1);
            group.Entities.Add(line2);

            DxfDocument dxf = new DxfDocument();
            // when we add a group to the document all the entities contained in the group will be automatically added to the document
            dxf.Groups.Add(group);

            // adding the group entities to the document is not necessary, but doing so should not cause any harm
            // the AddEntity method will return false in those cases, since those entities are already in the document
            dxf.AddEntity(line1);
            dxf.AddEntity(line2);

            dxf.Save("group.dxf");

            DxfDocument load = DxfDocument.Load("group.dxf");

            Console.WriteLine("Press a key to finish...");
            Console.ReadKey();
        }