TheSwamp

Code Red => .NET => Topic started by: ahlzl on February 23, 2009, 08:12:47 AM

Title: Create an associative hatch using C#
Post by: ahlzl on February 23, 2009, 08:12:47 AM
You can create an associative hatch with the help of ARX:  http://www.theswamp.org/index.php?topic=24025.msg290732#msg290732
But without ARX,how to create an associative hatch using C#?
The following post gives you the answer:
http://www.objectarx.net/bbs/viewthread.php?tid=2883&extra=page%3D1
Title: Re: Create an associative hatch using C#
Post by: Bryco on February 24, 2009, 05:16:20 PM
It must be a  trick question but
Code: [Select]
public Hatch HatchPline(ObjectId id)
        {
            Database db=HostApplicationServices.WorkingDatabase;
            Hatch h = new Hatch();
            ObjectIdCollection hs = new ObjectIdCollection();
            hs.Add(id);
            using(Transaction tr=db.TransactionManager.StartTransaction())
            {
                Polyline p=tr.GetObject(id,OpenMode.ForRead) as Polyline;
                h.SetDatabaseDefaults();
                h.Elevation=p.Elevation;
                h.Normal = p.Normal;
                h.PatternScale = 1;
                h.SetHatchPattern(HatchPatternType.PreDefined,"ANSI31");       
            }
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTableRecord Cspace = tr.GetObject
                    (db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
                Cspace.AppendEntity(h);               
                tr.AddNewlyCreatedDBObject(h, true);
                h.Associative = true;
                h.AppendLoop(HatchLoopTypes.External, hs);
                tr.Commit();             
            }
            return h;
         
        }

This makes associative hatch
Title: Re: Create an associative hatch using C#
Post by: kdub_nz on February 24, 2009, 06:46:53 PM

I thought I'd posted one as well, but couldn't find it, so may have been dreaming    :|