Author Topic: Need opinions - thoughts on approach for inserting blocks into polylines  (Read 2137 times)

0 Members and 1 Guest are viewing this topic.

Proctor

  • Guest
Hello:
I'm fairly new to autoCad and the api for .net... and have been assigned a complex project which I am courageously taking a stab at.

I have a few ideas for how i might approach this - but you all have been so helpful to me since I've joined (which I am very greatful), and so I'm here - asking for your thoughts and ideas that could help me either with my ideas or a new approach.

Here's a short description of the project:
The customer provides an image. Sometimes these are already vectorized...but other times they will be raster. I'm focusing on the vector formats for this discussion. In a nutshell, I need to automate placing LEDs into polygons. The Leds are rectangular-shaped and need to be spaced at a given distance apart...and they must rotate so that they curve along with the curves of the poly. The majority of times, these images are letters.

Currently, we use custom line types and they are hand drawn into the polys. This spaces them perfectly, according to the product chosen. I've attached a screen shot of this.

I would like to create rectangular blocks that resemble the LEDs and insert them accordingly. I'm currently looking at a few approaches. The first involves working with offset - where as I would insert the blocks along the curves. It's not perfect..when I use offset manually from the command prompt, I get lines where I don't want them (see attached).

My other idea involves creating a block that resembles 2 perpendicular lines. I then use somthing similar to measure to insert them along the poly (see attached) - after, I connect the end points to create a new poly. This approach is similar to offset; but might give me more flexibility? I don't know...I'm just thinking out loud.

Thanks you for taking time to look at this .... any thoughts are already appreciated.

Proctor







David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4076
well, measure is how I would go about it.  That combined with offset as you suggessted.  I think it might be automated somewhat, but I think there is to much human interactivity to completely automate
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

djonio

  • Guest
Here is an example for putting some points on your polylines. I also include the database method (AddPointd) for adding the points to the db so you can visualize them.

        [CommandMethod("POPOLYLINE", CommandFlags.UsePickSet | CommandFlags.Redraw | CommandFlags.Modal)]
        public void pointsonpolyline()
        {
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            Database db = doc.Database;
            PromptIntegerResult pir = ed.GetInteger("Enter number of divisions: ");
            if (pir.Status != PromptStatus.OK && pir.Value > 0)
            {
                return;
            }
            double how_many_times = pir.Value;

            PromptEntityResult per = ed.GetEntity("Pick Polyline: ");
            if (per.Status == PromptStatus.OK)
            {
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {

                    Entity ent = (Entity)tr.GetObject(per.ObjectId, OpenMode.ForRead);
                    Polyline pline = ent as Polyline;
                    if (pline != null)
                    {
                        if (pline.Closed == true)
                        {
                            double len = pline.Length;
                            DBPoint xPointdStart = new DBPoint(pline.GetPoint3dAt(0));
                            AddPointd(xPointdStart, 15, "Start", "Total:" + len.ToString());
                           
                            double len_increment = len / how_many_times;
                            for (int x = 1; x <= how_many_times - 1; x++)
                            {
                                Point3d p3d = pline.GetPointAtDist(len_increment * x);
                                DBPoint xPointd = new DBPoint(p3d);
                                AddPointd(xPointd, 15, x.ToString(), (len_increment * x).ToString());
                            }

                        }
                    }

                    tr.Commit();
                }
            }
        }
        public static ObjectId AddPointd(DBPoint pdb, short color, string name, string description)
        {
            ObjectId result = ObjectId.Null;
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            DocumentLock docLock = doc.LockDocument();
            try
            {
                using (Transaction tm = doc.TransactionManager.StartTransaction())
                {

                    BlockTable bt = (BlockTable)tm.GetObject(db.BlockTableId, OpenMode.ForWrite, false);
                    BlockTableRecord btr = (BlockTableRecord)tm.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false);
                    pdb.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, color);
                    ObjectId o = btr.AppendEntity(pdb);
                    tm.AddNewlyCreatedDBObject(pdb, true);

                    Entity e = (Entity)tm.GetObject(o, OpenMode.ForWrite);
                    HyperLinkCollection hyperls = e.Hyperlinks;
                    HyperLink hyper = new HyperLink();
                    hyper.Name = name;
                    hyper.Description = description;
                    hyperls.Add(hyper);

                    result = pdb.ObjectId;
                    tm.Commit();
                }
            }
            catch (Autodesk.AutoCAD.Runtime.Exception) { }
            catch (System.Exception) { }
            finally
            {
                docLock.Dispose();
            }
            return result;
        }

Proctor

  • Guest
Thank you djonio. I converted to vb to see how this works and I see how it's like measure. If I use w/ my rectangular blocks...I suppose I will need to make them rotate as well.

Thanks again,
Proctor