Author Topic: Draw Multi-line without jig?  (Read 4584 times)

0 Members and 1 Guest are viewing this topic.

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Draw Multi-line without jig?
« Reply #15 on: October 26, 2010, 10:56:55 AM »
Using vectors,  the line is easy, so have a go at adding that
Code: [Select]
        [CommandMethod("MultiLine")]
        public void MultiLine()
        {
            Document doc = acadApp.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            Database db = HostApplicationServices.WorkingDatabase;
            Matrix3d ucs = ed.CurrentUserCoordinateSystem;
            CoordinateSystem3d Cs = ucs.CoordinateSystem3d;
            Plane pn = new Plane(Point3d.Origin, Cs.Zaxis);
            Vector3d normal = Cs.Zaxis;
            //First point
            PromptPointResult Pres = ed.GetPoint("\nPick the first point:");
            if (Pres.Status != PromptStatus.OK) return;
            Point3d U1 = Pres.Value;

            //Second point
            PromptPointOptions PPO = new PromptPointOptions
                ("\nPick the second point:");
            PPO.UseBasePoint = true;
            PPO.BasePoint = U1;
            Pres = ed.GetPoint(PPO);

            if (Pres.Status != PromptStatus.OK) return;

            Point3d U2 = Pres.Value;
            if (U1.Z != U2.Z) U2 = new Point3d(U2.X, U2.Y, U1.Z);

            //Add pline
            Polyline oPline = new Polyline(7);
            oPline.Normal = Cs.Zaxis;
            oPline.Elevation = -new Plane(Cs.Origin, Cs.Zaxis).Coefficients.D;
            if (U1.Z != 0) oPline.Elevation = oPline.Elevation + U1.Z;

            Point2d P1 = U1.TransformBy(ucs).Convert2d(pn);
            Point2d P2 = U2.TransformBy(ucs).Convert2d(pn);
            oPline.AddVertexAt(0, P1, 0, 0, 0);
            oPline.AddVertexAt(1, P2, 0, 0, 0);
            Vector2d v = (P2 - P1).GetNormal().RotateBy(Math.PI * 0.5);

            using (Transaction tr = doc.Database.TransactionManager.StartTransaction())
            {
                BlockTableRecord Cspace = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
                Cspace.AppendEntity(oPline);
                tr.AddNewlyCreatedDBObject(oPline, true);
                tr.Commit();
            }
            Double dOffset = 51;

            //Always on the bottom
            int iOffset = 1;
            if (P2.X < P1.X) iOffset = -1;

            v = v * iOffset * -dOffset;
            using (Transaction tr = doc.Database.TransactionManager.StartTransaction())
            {
                oPline = tr.GetObject(oPline.Id, OpenMode.ForWrite) as Polyline;
                oPline.AddVertexAt(2, P2.Add(v), 0, 0, 0);
                oPline.AddVertexAt(3, P1.Add(v), 0, 0, 0);
                oPline.Closed = true;
                tr.Commit();
            }


        } //End MultiLine

josano

  • Guest
Re: Draw Multi-line without jig?
« Reply #16 on: October 26, 2010, 02:28:31 PM »
Jeff, Bryco and friends,

Thank you all for your support.
I think now I can develop the part of beam.
Please excuse me for the work, but I'm still crawling in autocad.net, with everyone's help understand more about lines, polylines and offset.

Hugs,
Josano