Code Red > .NET

Pick points to 2dpoints.

(1/5) > >>

Bryco:
I'm having a bit of trouble figuring out planes.
I'm picking 3d points and I want to make them 2d for polyline coords.
I presume the plane needed is the
Plane pn = new Plane(db.Ucsorg, db.Ucsxdir.CrossProduct(db.Ucsydir));
as I want to add the pline in the current ucs.
Any combo of Point2d P = Res1.Value.Convert2d(pn); or
Point2d P = Res1.Value.TransformBy(ucs).Convert2d(pn); fails with a curly Ucs
In vba one translates the points to the plines ocs using the normal.
Is it the same in c#?
(I've tried Kean Walmsley's poly jig and that doesn't work either.)
some mess around code

--- Code: --- [CommandMethod("Dp")]
        public void PlineDraw2()
        {
           
            Document doc = acadApp.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;
            Polyline oPline = new Polyline(3);
            ObjectId id = ObjectId.Null;


            Plane pn = new Plane(db.Ucsorg, db.Ucsxdir.CrossProduct(db.Ucsydir));
            //Plane pn = new Plane(db.Ucsorg, new Vector3d(0,0,1));
            Transaction tr = null;
            Matrix3d ucs = ed.CurrentUserCoordinateSystem;
            Vector3d Norm = new Vector3d(0, 0, 1).TransformBy(ucs);
            oPline.Normal = Norm;
            //oPline.Elevation = db.Ucsorg.Z;
            //oPline.Elevation = -pn.Coefficients.D;
            //ed.WriteMessage("\nelev={0}", -pn.Coefficients.D);
            //Point3d O = db.Ucsorg;
            //ed.WriteMessage("\nucsOrigin={0},{1},{2}", O.X, O.Y,O.Z);
         
            PromptPointResult Res1 = ed.GetPoint("\nSpecify start point:");
            if (Res1.Status != PromptStatus.OK) return;
            ed.WriteMessage("\nP={0},{1},{2}", Res1.Value.X, Res1.Value.Y, Res1.Value.Z);
           // Point2d P = Res1.Value.Convert2d(pn);
            Point2d  P = new Point2d(Res1.Value.X, Res1.Value.Y);
            ed.WriteMessage("\nP={0},{1}", P.X, P.Y);


             //P = Res1.Value.TransformBy(ucs).Convert2d(pn);
            //Point2d P = Res1.Value.Convert2d(pn);
            ed.WriteMessage("\nP={0},{1}", P.X, P.Y);

            oPline.AddVertexAt(0, P, 0, 0, 0);
             
   

            Point3d BasePt = Res1.Value;//.TransformBy(ucs);

            PromptPointOptions PPO = new PromptPointOptions("\nSpecify next point or [Arc]:", "Arc");
            PPO.UseBasePoint = true;
            PPO.UseDashedLine = true;
            PPO.AllowNone = true;
            PPO.BasePoint = BasePt;
            PromptPointResult Res2 = ed.GetPoint(PPO);
            if (Res2.Status != PromptStatus.OK) return;




            //P = Res2.Value.TransformBy(ucs).Convert2d(pn);
            //ed.WriteMessage("\nP={0},{1}", P.X, P.Y);
             //P = Res2.Value.Convert2d(pn);
             P = new Point2d(Res2.Value.X, Res2.Value.Y);
            oPline.AddVertexAt(1, P, 0, 0, 0);


            try    //add verticies
            {
                using (tr = db.TransactionManager.StartTransaction())
                {
                    BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                    btr.AppendEntity(oPline);
                    tr.AddNewlyCreatedDBObject(oPline, true);
                    tr.Commit();
                    id = oPline.ObjectId;
                }
            }
            catch (System.Exception ex)
            {
                ed.WriteMessage("\nError: " + ex.Message);
                tr.Abort();
            }
            finally
            {
                if (tr != null) tr.Dispose();
            }


        }
--- End code ---


T.Willey:
The problem might be with your AddVertexAt method calls.  Example

--- Code: ---            oPline.AddVertexAt(0, P, 0, 0, 0);

--- End code ---
I think it should be

--- Code: ---            oPline.AddVertexAt(0, P, 0.0, 0.0, 0.0);

--- End code ---
Since it wants 'double's in those locations.

--- Quote ---public void AddVertexAt(int index, Point2d pt, double bulge, double startWidth, double endWidth);

--- End quote ---

Only thing I can see, without running the code.

Bryco:
No it runs fine and works fine in world ucs or any world ucs that has been rotated about the z

T.Willey:
Here is what worked for me (plus some stuff I tried).

Edit:  Now it is not working.  Back to the drawing board.

--- Code: --- [CommandMethod("MyTestPline")]
public void MyTestPline() {
Document Doc = AcadApp.DocumentManager.MdiActiveDocument;
Database Db = Doc.Database;
Editor Ed = Doc.Editor;
PromptPointResult ppr01 = Ed.GetPoint("\nSelect first point: ");
PromptPointOptions ppo02 = new PromptPointOptions("\nSelect second point: ");
ppo02.UseBasePoint = true;
ppo02.BasePoint = ppr01.Value;
PromptPointResult ppr02 = Ed.GetPoint(ppo02);
PromptPointOptions ppo03 = new PromptPointOptions("\nSelect last point: ");
ppo03.UseBasePoint = true;
ppo03.BasePoint = ppr02.Value;
PromptPointResult ppr03 = Ed.GetPoint(ppo03);
Ed.WriteMessage("\n1 = {0}\n2 = {1}\n3 = {2}", ppr01.Value, ppr02.Value, ppr03.Value);
Vector3d vec = new Vector3d(0,0,1).TransformBy(Ed.CurrentUserCoordinateSystem);
Plane plane = new Plane(Db.Ucsorg,vec);
Ed.WriteMessage("\n{0}", vec);
//Point2d p01 = ppr01.Value.Convert2d(plane);
//Point2d p02 = ppr02.Value.Convert2d(plane);
//Point2d p03 = ppr03.Value.Convert2d(plane);
//Point3d p01 = ppr01.Value.TransformBy(Ed.CurrentUserCoordinateSystem);
//Point3d p02 = ppr02.Value.TransformBy(Ed.CurrentUserCoordinateSystem);
//Point3d p03 = ppr03.Value.TransformBy(Ed.CurrentUserCoordinateSystem);
//Ed.WriteMessage("\n1 = {0}\n2 = {1}\n3 = {2}", p01, p02, p03);
Polyline Pline = new Polyline(3);
//Pline.AddVertexAt(0, new Point2d(p01.X, p01.Y), 0.0, 0.0, 0.0);
//Pline.AddVertexAt(0, new Point2d(p02.X, p02.Y), 0.0, 0.0, 0.0);
//Pline.AddVertexAt(0, new Point2d(p03.X, p03.Y), 0.0, 0.0, 0.0);
//Pline.AddVertexAt(0, p01, 0.0, 0.0, 0.0);
//Pline.AddVertexAt(0, p02, 0.0, 0.0, 0.0);
//Pline.AddVertexAt(0, p03, 0.0, 0.0, 0.0);
Pline.AddVertexAt(0, new Point2d(ppr01.Value.X, ppr01.Value.Y), 0.0, 0.0, 0.0);
Pline.AddVertexAt(0, new Point2d(ppr02.Value.X, ppr02.Value.Y), 0.0, 0.0, 0.0);
Pline.AddVertexAt(0, new Point2d(ppr03.Value.X, ppr03.Value.Y), 0.0, 0.0, 0.0);
Pline.Normal = vec;
using (Transaction Trans = Db.TransactionManager.StartTransaction()) {
BlockTableRecord btr = (BlockTableRecord)Trans.GetObject(Db.CurrentSpaceId, OpenMode.ForWrite);
btr.AppendEntity(Pline);
Trans.AddNewlyCreatedDBObject(Pline, true);
Trans.Commit();
}

}

--- End code ---

Bryco:
Thanks for trying Tim.
It seems like the easiest thing (I still hope it is) but there are so many variables.
I have everything working on the polyline jig but this (The 3d part), and I thought this would be the easiest.
Although for some reason the jig gives points in world just to totally confuse you.
Perhaps using a plane is a mistake.
Theoretically if you were to pick 4 points and the returns are in Ucs then using those numbers (say the z is 0)
to input as coordinates, make the pline and transform the whole pline with the ucsmatrix you would get the correct result (It sounds good I don't know.)
That transformation is a bit like , use the 2d points to make the pline, then set the normal and the elevation (if the ucs origin was 0,0,0 this may be the same)
The normal should be the ucs crossproduct, the elevation is probably the vector distance from the ucs origin to 0,0,0.
I think if you use ppr01.Value.Convert2d(plane); you are effectively getting the res value, converting it to world, converting that back to the same plane as the ucs.

I'll work some more on it tonight, as I said in vba I make an ocs but I haven't seen that used in C# so far.

Navigation

[0] Message Index

[#] Next page

Go to full version