Author Topic: User Input - Getpoint Method - rubber band line  (Read 3482 times)

0 Members and 1 Guest are viewing this topic.

Oak3s

  • Guest
User Input - Getpoint Method - rubber band line
« on: September 02, 2011, 02:46:20 PM »
I am trying to rewrite the C# code for the GetPoint Method found in AutoCAD .NET Developers Guide/Prompt for User Input.

I rewriting it in hopes of better understanding it...which I think it working :) But I am stuck on the rubber portion. I can pick the two points and draw the line...but once I pick the first point I want the rubber band line...not getting it.

Code: [Select]
[CommandMethod("UserPoint")]
        public static void UserPoint()
        {
            Document acDoc = Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;
            PromptPointOptions usrPointOpts = new PromptPointOptions("Enter the start point of the line: ");    //prompt for point
            PromptPointResult usrPointRes = acDoc.Editor.GetPoint(usrPointOpts);                                //get user point
            Point3d usrStart = usrPointRes.Value;                                                               //store user value

            PromptPointOptions usrEndPointOpts = new PromptPointOptions("\nEnter the end point of the line: ");   //prompt for point

           [color=red] //set a rubber band line **************NOT WORKING********************[/color]
            usrPointOpts.UseBasePoint = true;
            usrPointOpts.BasePoint = usrStart;

            PromptPointResult usrEndPointRes = acDoc.Editor.GetPoint(usrEndPointOpts);                          //get user point
            Point3d usrEnd = usrEndPointRes.Value;                                                              //store user value

            //start a transaction
            using (Transaction acTrans = acCurDb.TransactionManager.StartOpenCloseTransaction())
            {
                BlockTable acBlkTbl;
                BlockTableRecord acBlkTblRec;
                //open model space for write
                acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;
                acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite)
                                                                                    as BlockTableRecord;
                //define the new line
                Line usrLine = new Line(usrStart, usrEnd);
                usrLine.SetDatabaseDefaults();

                //add new line to the drawing
                acBlkTblRec.AppendEntity(usrLine);
                acTrans.AddNewlyCreatedDBObject(usrLine, true);

                //commit the changes and dispose of the transaction
                acTrans.Commit();
            }
        }

(side question, how do I add color to a portion of code?)

As usual, any help is appreciated.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: User Input - Getpoint Method - rubber band line
« Reply #1 on: September 02, 2011, 03:47:12 PM »
You are using the wrong PromptOption...
Code: [Select]
            usrPointOpts.UseBasePoint = true;
            usrPointOpts.BasePoint = usrStart; <<<<<

            PromptPointResult usrEndPointRes = acDoc.Editor.GetPoint(usrEndPointOpts);    <<<<<<<
[/code

Jeff H

  • Needs a day job
  • Posts: 6150
Re: User Input - Getpoint Method - rubber band line
« Reply #2 on: September 02, 2011, 03:48:30 PM »
PromptPointOptions inherits from PromptCornerOptions,
which has a UseDashedLine property

Oak3s

  • Guest
Re: User Input - Getpoint Method - rubber band line
« Reply #3 on: September 02, 2011, 04:22:31 PM »
Jeff_M
Is this what it should be?
Code: [Select]
            //set a rubber band line
            usrEndPointOpts.UseBasePoint = true;
            usrEndPointOpts.BasePoint = usrStart;

            PromptPointResult usrEndPointRes = acDoc.Editor.GetPoint(usrEndPointOpts);

Thats what seems to be working as intended...

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: User Input - Getpoint Method - rubber band line
« Reply #4 on: September 02, 2011, 04:39:42 PM »
That's correct.

Oak3s

  • Guest
Re: User Input - Getpoint Method - rubber band line
« Reply #5 on: September 02, 2011, 04:46:48 PM »
Thank you.