Hello, I have a need to save coordinates points for a couple of objects, so I decided to use a structure object.
Here is my structure for an 8 sided polygon:
Structure OctoPolygon Public Shared pt1 As New Geometry.Point3d Public Shared pt2 As New Geometry.Point3d Public Shared pt3 As New Geometry.Point3d Public Shared pt4 As New Geometry.Point3d Public Shared pt5 As New Geometry.Point3d Public Shared pt6 As New Geometry.Point3d Public Shared pt7 As New Geometry.Point3d Public Shared pt8 As New Geometry.Point3d Public Sub setPoints(ByVal drawingStartPoint As Double, ByVal mcSize As Double, ByVal mcCenter2Cham As Double) Dim mcX1neg As Double, mcX2neg As Double, mcX1pos As Double, mcX2pos As Double Dim mcY1neg As Double, mcY2neg As Double, mcY1pos As Double, mcY2pos As Double Dim mcChamLength As Double ' Set the moldcap chamfer value mcChamLength = ((mcSize / 2) - mcCenter2Cham) ' Set the new corners based on length and chamfer of the polygon mcX1neg = drawingStartPoint - (mcSize / 2) mcX2neg = drawingStartPoint - ((mcSize / 2) - mcChamLength) mcX1pos = drawingStartPoint + (mcSize / 2) mcX2pos = drawingStartPoint + ((mcSize / 2) - mcChamLength) mcY1neg = ((mcSize / 2) * -1) mcY2neg = (((mcSize / 2) - mcChamLength) * -1) mcY1pos = (mcSize / 2) mcY2pos = ((mcSize / 2) - mcChamLength) pt1 = New Geometry.Point3d(mcX1neg, mcY2neg, 0) pt2 = New Geometry.Point3d(mcX2neg, mcY1neg, 0) pt3 = New Geometry.Point3d(mcX2pos, mcY1neg, 0) pt4 = New Geometry.Point3d(mcX1pos, mcY2neg, 0) pt5 = New Geometry.Point3d(mcX1pos, mcY2pos, 0) pt6 = New Geometry.Point3d(mcX2pos, mcY1pos, 0) pt7 = New Geometry.Point3d(mcX2neg, mcY1pos, 0) pt8 = New Geometry.Point3d(mcX1neg, mcY2pos, 0) End Sub End Structure
Then I want to send that object to a sub that will draw the octagonal polyline:
' Create octagonal moldcap shapes Public Sub addPolyOctagon(ByVal polyStruct As OctoPolygon) Dim podPolyOctagonTransMan As DatabaseServices.TransactionManager Dim podPolyOctagonTrans As DatabaseServices.Transaction Dim podDWG As ApplicationServices.Document Dim podBT As DatabaseServices.BlockTable Dim podBTR As DatabaseServices.BlockTableRecord ' Get the active document and begin a Transaction podDWG = ApplicationServices.Application.DocumentManager.Md
iActiveDocument podPolyOctagonTransMan = podDWG.TransactionManager podPolyOctagonTrans = podPolyOctagonTransMan.StartTransaction ' Open the BlockTable for Read podBT = podDWG.Database.BlockTableId.GetObject(DatabaseSer vices.OpenMode.ForRead) podBTR = podBT(DatabaseServices.BlockTableRecord.ModelSpace ).GetObject(DatabaseServices.OpenMode.ForWrite) ' Draw the polyline Dim polyCorners As New Autodesk.AutoCAD.Geometry.Point3dCollection polyCorners.Add(New Geometry.Point3d(polyStruct.pt1)) polyCorners.Add(New Geometry.Point3d(polyStruct.pt2)) polyCorners.Add(New Geometry.Point3d(polyStruct.pt3)) polyCorners.Add(New Geometry.Point3d(polyStruct.pt4)) polyCorners.Add(New Geometry.Point3d(polyStruct.pt5)) polyCorners.Add(New Geometry.Point3d(polyStruct.pt6)) polyCorners.Add(New Geometry.Point3d(polyStruct.pt7)) polyCorners.Add(New Geometry.Point3d(polyStruct.pt8)) Dim mcPLine As New DatabaseServices.Polyline2d(DatabaseServices.Poly2 dType.SimplePoly, _ polyCorners, 0, True, 0, 0, Nothing) podBTR.AppendEntity(mcPLine) podPolyOctagonTrans.AddNewlyCreatedDBObject(mcPLin e, True) ' Commit the Transaction podPolyOctagonTrans.Commit() podPolyOctagonTrans.Dispose() podPolyOctagonTransMan.Dispose() End Sub
It's having a real problem with the lines:
It says "Access of shared member, constant member, enum member, or nested type through an instance; qualifying expression wil not be evaluated"
Can someone please explain the to me, and tell me how I can get the sub to see the points defined in the structure?
Remove "Shared" from the structure's public member declaration.
I do not know the exact reason(s) why you want to expose the 8 Point3d member as "Shared". At least, according to the code you showed here and to what you described for your need, they should not be "Shared" members, assuming before the sub addPolyOctagon() is called, you have instantiated the structure and called its method setPoints() and then passed it to the addPolyOctagon().
Hi Norman, thank you for replying. I guess I used "Shared" ot of ignorance. I saw structure code somewhere and copied its format.
Ok, so now I removed the "Shared" from the structure:
Structure OctoPolygon Public pt1 As Geometry.Point3d Public pt2 As Geometry.Point3d
But the lines like:
now have this issue:
"Value of type 'Autodesk.AutoCAD.Geometry.Point3d' cannot be converted to '1-dimensional array of Double'.
I thought it just needed a point and those are 3d points.
Using a struct in the case you show, to store only multiple instances of a single type, is really inappropriate.
You can use an array of Point3d or a Point3d collection, and reference the elements via their index, which is what your structure members (pt1-pt7) are.
If per chance, you have other types of data that you want to also include, you can use a struct for something like that, but the Point3d members should still not be there, because the struct can contain an array of Point3d or Point3dCollection as well.
Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register
Start with some of our most frequented solutions to get help installing your software.