Author Topic: Create hatch without making boundary entities  (Read 2914 times)

0 Members and 1 Guest are viewing this topic.

jmaeding

  • Bull Frog
  • Posts: 304
  • I'm just here for the Shelties.
Create hatch without making boundary entities
« on: October 07, 2009, 02:40:47 PM »
I've seen detailed examples of hatch creation where boundary is existing or drawn new.
What if i know the points from a text file or something, and only want the hatch.
Must I draw the ents and erase after?  or can i just make a temp pline object to get objectid, then never add to database but use in appendloop?
thx
James Maeding

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Create hatch without making boundary entities
« Reply #1 on: October 08, 2009, 08:29:39 AM »
You have to add the pline to get an objectid, but you only need one pline to do all your hatches
Code: [Select]
     [CommandMethod("hatchtest")]
        public static void hatchtest()
        {
            Document doc=acadApp.DocumentManager.MdiActiveDocument;
            Editor ed=doc.Editor;
            Database db=doc.Database;
            ObjectIdCollection hatchIds=new ObjectIdCollection();
            double[]p={2,1,3,3,4,5,5,1,4,2,3,1};
            double[] p2 = { 12, 11, 13, 13, 14, 15, 15, 11, 14, 12, 13, 11 };
            List<double[]>ds=new List<double[]> {p,p2};             
            Polyline pline=new Polyline();
            pline.SetDatabaseDefaults();
            pline.AddVertexAt(0, new Point2d(0, 0), 0, 0, 0);
            Hatch hatch = new Hatch();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTableRecord space = tr.GetObject
                    (db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
                space.AppendEntity(pline);
                tr.AddNewlyCreatedDBObject(pline, true);
                for (int k = 0; k < ds.Count;k++)
                { 
                    for (int i = pline.NumberOfVertices - 1; i > 0; i--)
                        pline.RemoveVertexAt(i);
                    pline.SetPointAt(0, new Point2d(ds[k][0], ds[k][1]));
                    for (int i = 1; i < ds[k].Length / 2; i++)
                    {
                        int j = i * 2;
                        pline.AddVertexAt(i, new Point2d(ds[k][j], ds[k][j + 1]), 0, 0, 0);
                    }
                    pline.Closed = true;
                    hatchIds.Clear();
                    hatch = new Hatch();
                    hatch.SetDatabaseDefaults();
                    hatch.SetHatchPattern(HatchPatternType.PreDefined, "Ansi32");
                    hatchIds.Add(pline.ObjectId);
                    space.AppendEntity(hatch);
                    tr.AddNewlyCreatedDBObject(hatch, true);
                    hatch.Associative = false;
                    hatch.AppendLoop(HatchLoopTypes.External, hatchIds);                   
                }

                tr.Commit();
            }

        } // end hatchtest

jmaeding

  • Bull Frog
  • Posts: 304
  • I'm just here for the Shelties.
Re: Create hatch without making boundary entities
« Reply #2 on: October 08, 2009, 11:26:36 AM »
ok, thx for smaple code too.
I guess the normal hatch command does require entities to make a hatch, but I have a routine in L**P that does it with just points, thought maybe I was missing some approach with .net.

James Maeding

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Create hatch without making boundary entities
« Reply #3 on: October 08, 2009, 02:09:52 PM »
Probably uses -hatch which doesnt need a bounary

mjfarrell

  • Seagull
  • Posts: 14444
  • Every Student their own Lesson
Re: Create hatch without making boundary entities
« Reply #4 on: October 09, 2009, 08:54:04 AM »
ok, thx for smaple code too.
I guess the normal hatch command does require entities to make a hatch, but I have a routine in L**P that does it with just points, thought maybe I was missing some approach with .net.



Shouldn't you be busy writing your Civil 3D piping program?   ;-)
Be your Best


Michael Farrell
http://primeservicesglobal.com/

jmaeding

  • Bull Frog
  • Posts: 304
  • I'm just here for the Shelties.
Re: Create hatch without making boundary entities
« Reply #5 on: October 09, 2009, 03:38:59 PM »
oh, I am actually in the middle of writing my own piping/civil design prog.
I am essentially making Civil BIM objects that are fully shareable and directly labelable.
None of this "only label the corridor surface" stuff of C3D.
Its actually been far easier than I expected.  Once I got the hang of snippets, and created standard sets of using statements to keep my aliases organized, most of my functions take only a couple debug runs to shake out.
It will not be relient on any autocad api calls to calculate things.  You could have it do things in some other cad program as they are invented.
I have adapter classes that get data and draw things in acad.  I even have ones to get/set data in LDT/C3D alignments and surfaces.  My prog can be used as an editing mechanism for any prog whose objects have an API.
Its native data is xml files that can exist in any set of folders, and you can set grouping and filtering on what objects you want to see in the treeview dialog.
I've got it all planned out, just need to walk the plan now.
James Maeding

mjfarrell

  • Seagull
  • Posts: 14444
  • Every Student their own Lesson
Re: Create hatch without making boundary entities
« Reply #6 on: October 09, 2009, 08:13:33 PM »
whenever you want earnest user evaluation of that applet let me know....
Be your Best


Michael Farrell
http://primeservicesglobal.com/

jmaeding

  • Bull Frog
  • Posts: 304
  • I'm just here for the Shelties.
Re: Create hatch without making boundary entities
« Reply #7 on: October 12, 2009, 03:35:35 PM »
will do, I want to make it open source for as much as possible.  I need all the code refinement I can get.
It might be that the labeling part is just our companies, but I bet you guys could whip out labeling tools that would trump ours eventually.
Labeling is one of the things that there are many solutions for, whereas a pipeline design object is easier to agree upon.
I think this will lead to multiple labeling packages depending on what options one wants for callouts.
Once the underlying engine is set up, and open source, the sky is the limit.
I do need to figure out an open source surface library.  The ones I know of do not have .net compatibility yet.


James Maeding