.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Passing Coordinate Values to Polyline Function

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
mgorecki
1762 Views, 6 Replies

Passing Coordinate Values to Polyline Function

Hello,

Getting out of my comfort zone of LiSP and trying to move to VB .NET, so I appreciate all of your help in advance.  I have a function that will add polyline vertices to the polyline entity, but the values are "hard coded".  I was wondering how I would be able to pass variable values for polyline points to a polyline function so that it could use them instead.

In the Sub, I have something like this currently (polyCorner is the function):

polyCorner(New Geometry.Point3d(-5, -5, 0), New Geometry.Point3d(5, -5, 0), New Geometry.Point3d(5, 5, 0), New Geometry.Point3d(-5, 5, 0))

 

The numbers are hard coded.  I would like to know the format for this line if the variables were already calculated and passed to this line.

 

In the function, I have:

Public Function polyCorner(ByVal CnrPt1 As Geometry.Point3d, ByVal CnrPt2 As Geometry.Point3d, _
    ByVal CnrPt3 As Geometry.Point3d, ByVal CnrPt4 As Geometry.Point3d) As DatabaseServices.ObjectId
        :
        :
        :
        'Draw the polyline
        Dim myPoints As New Geometry.Point3dCollection
        myPoints.Add(New Geometry.Point3d(CnrPt1))
        myPoints.Add(New Geometry.Point3d(CnrPt2))
        myPoints.Add(New Geometry.Point3d(CnrPt3))
        myPoints.Add(New Geometry.Point3d(CnrPt4))
        Dim myPLine As New DatabaseServices.Polyline2d( _
            DatabaseServices.Poly2dType.SimplePoly, myPoints, 0, True, 0, 0, Nothing)
        myBTR.AppendEntity(myPLine)
        myTrans.AddNewlyCreatedDBObject(myPLine, True)

 

The variables CnrPt1 - CnrPt4 are passed to the function, but this format doesn't work.  Can someone give me an idea as to how to write this to use variables?

 

Thanks,

Mark

6 REPLIES 6
Message 2 of 7
chiefbraincloud
in reply to: mgorecki

First thing, when adding the points to the Point3DCollection, you already have a Point3d Object, so you don't create a new one, you just pass it, like this:

myPoints.Add(CnrPt1)

 

Second, and I could be wrong about this, I haven't messed with my create2DPoly function in a long time, but I don't think the Polyline2D constructor is going to like the null collection for the bulges. Instead of passing Nothing, I think you are going to have to create a proper DoubleCollection that contains the same number of elements as your point3d collection. Something like this:

 

Dim dbls(myPoints.Count - 1) As Double  'this will automatically initialize each element of the array to 0

Dim myPLine As New DatabaseServices.Polyline2d( DatabaseServices.Poly2dType.SimplePoly, _

myPoints, 0, True, 0, 0, New DoubleCollection(dbls))

 

It is also imperative that you look up Try/Catch blocks in the VB (or Visual Studio) help files.  Using them appropriately will prevent AutoCAD crashes, and will save you loads of time in the debug process.  The exception data provided often contains at least a hint as to what the problem may be.  (Granted, sometimes the messages can be a little vague, but it should at least help you narrow down the potential problems)

Dave O.                                                                  Sig-Logos32.png
Message 3 of 7
mgorecki
in reply to: chiefbraincloud

hello,

Thank you very much.  I hope you don't mind me asking another question.  When using AutoLiSP, there were help files that contained all of the AutoLiSP commands and what they do (entget, distof, etc...), is there something like that for VB.Net for AutoCAD?  I look at the command that you provided:

Dim myPLine As New DatabaseServices.Polyline2d( DatabaseServices.Poly2dType.SimplePoly, _

myPoints, 0, True, 0, 0, New DoubleCollection(dbls))

I was wondering where you would learn about the modifiers (mypoints, 0, True, 0, 0....).  For this and other commands, I would like to know what's needed and what they actually are (like True meaning that the polyline is closed).  Do you know of a source for this kind of info?

Thanks again,

Mark

Message 4 of 7
chiefbraincloud
in reply to: mgorecki

The first place I look for signatures and overloads is in the Visual Studio Object Browser.  I also have the ObectARX help integrated, so if I press F1 with the cursor on an autocad object I get a help page (if there is a help page for the object).  You should download the ObjectARX SDK.  Not only are the developer help files in it, there are also some .NET code examples.

 

And, though I haven't used it much at all, and I have seen lots of complaints on this discussion group about it, the AutoCAD .NET Developers Guide is located here:

http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer's%20Guide/index.html

Dave O.                                                                  Sig-Logos32.png
Message 5 of 7
mgorecki
in reply to: mgorecki

Thanks a bunch.  I'll check those out.

 

Mark

Message 6 of 7
kob4lt
in reply to: chiefbraincloud

Can you help me. I am getting eInvalidInput error for this code

 

 

Polyline2d cestica = new Polyline2d(Poly2dType.SimplePoly, points, 0, true, 0, 0, new DoubleCollection(points.Count - 1));

 

Thanks

 

Message 7 of 7
chiefbraincloud
in reply to: kob4lt

Making the assumption that 'points' is a valid Point3dCollection, the problem is your DoubleCollection for the bulges.

 

In my example above, I declared a Double array of size (points.count - 1) because that automatically initializes each element of the array (for value types).  Meaning that if you stepped through the code, immediately following the execution of this line; Dim dbls(myPoints.Count - 1) As Double, the value of dbls(0) all the way to dbls(points.count - 1) would be equal to 0.

 

Then I created my DoubleCollection from the Double array, which both sizes the collection, and copies each element of the array into the collection.

 

What your code does with New DoubleCollection(points.count - 1) is creates a DoubleCollection that is sized but empty(incorrectly sized though, I'll cover that in a minute), but if you declared a variable and tested it, like Dim DblCol as New DoubleCollection(points.count - 1), immediately following the execution of that line of code, DblCol.Count would equal points.count - 1, but DblCol.Item(0) (and all of the other Items) would equal Nothing, not 0.

 

About the size of the array or collection:

When you declare an array of particular size (like dbls(points.count - 1)) the argument passed in VB is the zero based UpperBound of the array, whereas in C# the argument is the actual size or number of elements.  In both cases (VB and C#)  the declaration of the DoubleCollection with the Capacity argument is the actual size, so you need to use points.Count, not points.Count - 1.

 

In the end, what you need to pass is a DoubleCollection where DblCol.Count is equal to points.Count, and each item in DblCol has a numeric value (zero for no arc).  then your InvalidInput error will go away.

Dave O.                                                                  Sig-Logos32.png

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost