Author Topic: GetPointAtDist troubles  (Read 8565 times)

0 Members and 1 Guest are viewing this topic.

surveyor_randy

  • Guest
GetPointAtDist troubles
« on: September 16, 2008, 09:41:21 AM »
I am trying to use the GetPointAtDist function and am having no luck.  I've researched this on the Autodesk NGs and here at the swamp and haven't found anything that can help.  There is mention of using the 'curves' class.  I can't find any documentation on this.  I keep getting an "eInvalidInput" error on the red line.  I've read that the object needs to be added to the database first, I tried that and still got the error.  This line is a temporary calculation line and I don't want to keep it.  Any help would be appreciated!  FYI, I am using AutoCad 2008 and Civil 3D SP2.

Code: [Select]
Public Sub TEST()

            Dim oStPnt As Point3d = ed.GetPoint("Select starting point: ").Value
            Dim oEndPnt As Point3d = ed.GetPoint("Select ending point: ").Value
            Dim tmpLine As Line = New Line(oStPnt, oEndPnt)
            [color=red]Dim PointAtDist As Point3d = tmpLine.GetPointAtDist(10)[/color]

End Sub

Glenn R

  • Guest
Re: GetPointAtDist troubles
« Reply #1 on: September 16, 2008, 10:07:34 AM »
I think you may need to do more study and learn more of not only the .NET API, but the AutoCAD one as well. The 'Curves' class that you mention, is in fact the base class of a lot of AutoCAD entities, with the humble Line being one of them.

If you look up Autodesk.AutoCAD.DatabaseServices.Line in the ARX documentation, you will see it wraps the native ARX AcDbLine class. If you were to look at that, you will see it inherits from AcDbCurve, which in turn is wrapped in AutoCAD's .NET API as Curve I believe.

Therefore, Line inherits from Curve and get's it's methods/properties, with GetPointAtDist being one of them.

Observe:
Code: [Select]
using System;

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;

using acadApp = Autodesk.AutoCAD.ApplicationServices.Application;

namespace ClassLibrary1
{
public class Class1
{
public Class1() { }

[CommandMethod("SurveyRand")]
public static void SurveyRandCommand()
{
      using (Line tempLine = new Line(new Point3d(0, 0, 0), new Point3d(100, 100, 10)))
      {
        Point3d closestPoint = tempLine.GetPointAtDist(10);

        Document doc = acadApp.DocumentManager.MdiActiveDocument;
        Editor ed = doc.Editor;

        ed.WriteMessage("{0}Closest point at distance of 10: {1}", Environment.NewLine, closestPoint);
      }

}
}
}

Glenn R

  • Guest
Re: GetPointAtDist troubles
« Reply #2 on: September 16, 2008, 10:09:40 AM »
Also, without knowing more, your error may be due to the distance, which is being passed as an argument, is actually greater than line itself.

surveyor_randy

  • Guest
Re: GetPointAtDist troubles
« Reply #3 on: September 16, 2008, 10:26:04 AM »
...your error may be due to the distance, which is being passed as an argument, is actually greater than line itself.

Thank you for the prompt reply Glenn, that WAS the issue.  Maybe I had the wrong idea about the GetPointAtDist function.  I didn't know that the distance had to be shorter then the line itself.  I thought it would project the line the specified distance and give you a Point3D in retun.  If you don't mind, how would I return a point3d that is X distance from the endpoint of a line that is projected.

Spike Wilbury

  • Guest
Re: GetPointAtDist troubles
« Reply #4 on: September 16, 2008, 10:44:56 AM »
If you have the ARX SDK, read about the AcGe Classes.  :-)

surveyor_randy

  • Guest
Re: GetPointAtDist troubles
« Reply #5 on: September 16, 2008, 10:58:02 AM »
If you have the ARX SDK, read about the AcGe Classes.  :-)

I don't have it.  I am going to go DL it from Autodesk.

To answer my own question: I just grabbed the angle of the line and then used the PolarPoint function from the Interop.AcadUtilityClass to calculate the extended points.  I am not taking into consideration any UCS rotation or anything like that.  I will need to study up on other methods of doing this but for now, this serves my purpose.

Glenn R

  • Guest
Re: GetPointAtDist troubles
« Reply #6 on: September 16, 2008, 11:17:42 AM »
I agree with Luis and if you don't have it then you should get it and start studying both it and .NET.

Here's one way:
Code: [Select]
using System;

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;

using acadApp = Autodesk.AutoCAD.ApplicationServices.Application;

namespace ClassLibrary1
{
  public class Class1
  {
    public Class1() { }

    [CommandMethod("SurveyRand")]
    public static void SurveyRandCommand()
    {
      Document doc = acadApp.DocumentManager.MdiActiveDocument;
      Editor ed = doc.Editor;

      Line3d pLine = new Line3d(new Point3d(0, 0, 0), new Point3d(10, 10, 0));
      double param = pLine.GetParameterAtLength(0.0, 15, true, 0.0);
      Point3d newPoint = pLine.EvaluatePoint(param);

      ed.WriteMessage("{0}Point at distance of 15: {1}", Environment.NewLine, newPoint);
    }
  }
}

Edit: Fixed crap formatting.

surveyor_randy

  • Guest
Re: GetPointAtDist troubles
« Reply #7 on: September 16, 2008, 11:25:35 AM »
You guys are great!  Thanks again for the help.  :-)

sinc

  • Guest
Re: GetPointAtDist troubles
« Reply #8 on: September 16, 2008, 02:08:49 PM »
There's also a lot of example manipulations of Curves in the Sincpac-C3D code.  Take a look at the CurveUtil class in the AcadUtilities subproject, in particular.

surveyor_randy

  • Guest
Re: GetPointAtDist troubles
« Reply #9 on: September 17, 2008, 08:01:01 AM »
There's also a lot of example manipulations of Curves in the Sincpac-C3D code.  Take a look at the CurveUtil class in the AcadUtilities subproject, in particular.

I'm looking at it now, thanks for making it available.

One other quick question to all.... "How can you consider the stuff that Autocad puts out (ex:object ARX documentation) to be documentation?"  Other then having a little sample code, it tells you pretty much the same thing that the object browser in Visual Studio does.  I would think that the documentation would break each class down and briefly explain what each function does.  Isn't that what documentation is supposed to do?  Other then just looking through sample code (like I've been doing), is there anything I am missing that might tell you, for example, what a 'parm' is or how to work with vector manipulations or Matrices?"  end rant.

Glenn R

  • Guest
Re: GetPointAtDist troubles
« Reply #10 on: September 17, 2008, 08:11:46 AM »
There's also a lot of example manipulations of Curves in the Sincpac-C3D code.  Take a look at the CurveUtil class in the AcadUtilities subproject, in particular.

I'm looking at it now, thanks for making it available.

One other quick question to all.... "How can you consider the stuff that Autocad puts out (ex:object ARX documentation) to be documentation?"  Other then having a little sample code, it tells you pretty much the same thing that the object browser in Visual Studio does.  I would think that the documentation would break each class down and briefly explain what each function does.  Isn't that what documentation is supposed to do?  Other then just looking through sample code (like I've been doing), is there anything I am missing that might tell you, for example, what a 'parm' is or how to work with vector manipulations or Matrices?"  end rant.

Yes there is - the ARX documentation. See my initial reply. You will have to read the ARX native definitions to ultimately figure a lot of things out.

Spike Wilbury

  • Guest
Re: GetPointAtDist troubles
« Reply #11 on: September 17, 2008, 09:46:51 AM »
One other quick question to all.... "How can you consider the stuff that Autocad puts out (ex:object ARX documentation) to be documentation?"  Other then having a little sample code, it tells you pretty much the same thing that the object browser in Visual Studio does.  I would think that the documentation would break each class down and briefly explain what each function does.  Isn't that what documentation is supposed to do?  Other then just looking through sample code (like I've been doing), is there anything I am missing that might tell you, for example, what a 'parm' is or how to work with vector manipulations or Matrices?"  end rant.

:)

The ObjectARX SDK assumes you have a good level of knowledge of C++ background (at least 2 years in my opinion - remember it is just an addition to), you have to figure out a lot of things (as mentioned by Glenn) and also helps if you know linear algebra, math and geometry just to start  :evil:   :-P.

Good luck!

surveyor_randy

  • Guest
Re: GetPointAtDist troubles
« Reply #12 on: September 17, 2008, 10:22:28 AM »
I don't have any C++ experience.  A little C#, a lot of Pascal, VB, VB.NET and Assembly.  I understand how vector manipulation and matrices work in mathematics.  Dot products, yay!!  I just don't know how they work in AutoCad.  I would imagine that you can define a line with a vector, however, I didn't see anywhere when defining a vector to define the magnitude of the vector.  I think I am just going to look at as much sample code as I can.  I did find the breakdown in the ARX documentation and it is helpful.  Thanks again for all the replys.  :-)
« Last Edit: September 17, 2008, 10:25:57 AM by surveyor_randy »

Spike Wilbury

  • Guest
Re: GetPointAtDist troubles
« Reply #13 on: September 17, 2008, 10:31:38 AM »
I don't have any C++ experience.  A little C#, a lot of Pascal, VB, VB.NET and Assembly.  I understand how vector manipulation and matrices work in mathematics.  Dot products, yay!!  I just don't know how they work in AutoCad.  I would imagine that you can define a line with a vector, however, I didn't see anywhere when defining a vector to define the magnitude of the vector.  I think I am just going to look at as much sample code as I can.  I did find the breakdown in the ARX documentation and it is helpful.  Thanks again for all the replys.  :-)

Open the arxref.chm | under search type: Using the Line and Plane Classes | at least it will provide a little intro - better than nothing

Also, search for this: "Using Basic Geometry Types"

HTH.
« Last Edit: September 17, 2008, 10:38:25 AM by Luis »

sinc

  • Guest
Re: GetPointAtDist troubles
« Reply #14 on: September 17, 2008, 01:43:24 PM »
For what it's worth, I agree with you about the Docs.  They are weak, and leave out a lot of info that should be there.  I've sent Autodesk a number of notes about things that are missing from the docs, and they do seem to be taking that feedback and making them better, but they still have a very long way to go.

It actually helps if you send them feedback every time you notice one of those things.  I get the impression that there are a number of people working on the documentation, and most of them aren't really sure what they need to do.  They seem to like it when someone lets them know what's missing, so they have some direction.  They seem to have plenty of time to work on the docs, they just don't necessarily have a lot of experience with APIs, and it just really doesn't seem to occur to them that we need to know things like what are the possible exceptions this method might throw, and so forth.

Spike Wilbury

  • Guest
Re: GetPointAtDist troubles
« Reply #15 on: September 17, 2008, 06:05:00 PM »
maybe, could be a good idea to write a short sample of usage for each of the functions... maybe.....