Exemple #1
0
        private ObjectId GetOrCreatePartOutline(Part part)
        {
            var outlinePartId = ObjectId.Null;

            using (var t = _acad.StartTransaction())
            {
                var blkTbl = t.GetObject(_acad.Database.BlockTableId, OpenMode.ForWrite) as BlockTable;
                if (blkTbl.Has(part.OutlineReferenceName))
                {
                    return(blkTbl[part.OutlineReferenceName]);
                }

                var border = (part.UsageType == UsageType.Head)? 0 : _properties.Algorythim.Options.OutlineDistance - 0.01F;
                using (var record = new BlockTableRecord {
                    Name = part.OutlineReferenceName, Units = UnitsValue.Centimeters, Explodable = true
                })
                {
                    record.Origin = part.PivotPoint;
                    outlinePartId = blkTbl.Add(record);
                    t.AddNewlyCreatedDBObject(record, true);

                    using (var poly = EntityGenerator.CreateSquare(part.Dimensions, border))
                    {
                        record.AppendEntity(poly);
                        t.AddNewlyCreatedDBObject(poly, true);
                    }

                    using (var poly = EntityGenerator.CreateSquare(part.Dimensions))
                    {
                        record.AppendEntity(poly);
                        t.AddNewlyCreatedDBObject(poly, true);
                    }

                    foreach (var line in EntityGenerator.CreateCrossLines(part.Dimensions, border))
                    {
                        record.AppendEntity(line);
                        t.AddNewlyCreatedDBObject(line, true);
                        line.Dispose();
                    }
                }

                t.Commit();
            }

            return(outlinePartId);
        }
Exemple #2
0
        public ObjectId GetOrCreatePart(Part part)
        {
            var partObjectId = ObjectId.Null;

            using (var t = _acad.StartTransaction())
            {
                var blkTbl = t.GetObject(_acad.Database.BlockTableId, OpenMode.ForWrite) as BlockTable;

                if (!blkTbl.Has(part.ReferenceName))
                {
                    if (blkTbl.Has(part.GenericReferenceName))
                    {
                        return(blkTbl[part.GenericReferenceName]);
                    }

                    using (var record = new BlockTableRecord())
                    {
                        record.Name       = part.GenericReferenceName;
                        record.Units      = UnitsValue.Centimeters;
                        record.Origin     = part.PivotPoint;
                        record.Explodable = true;
                        partObjectId      = blkTbl.Add(record);
                        t.AddNewlyCreatedDBObject(record, true);

                        using (var poly = EntityGenerator.CreateSquare(part.Dimensions, 0))
                        {
                            poly.Color = part.UsageType.ToColor();

                            record.AppendEntity(poly);
                            t.AddNewlyCreatedDBObject(poly, true);
                        }
                    }
                }
                else
                {
                    return(blkTbl[part.ReferenceName]);
                }

                t.Commit();
            }

            return(partObjectId);
        }