+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Full Member
    Using
    AutoCAD 2010
    Join Date
    Aug 2009
    Posts
    47

    Default 2d array in vb .net

    Registered forum members do not see this ad.

    Hi
    i got a question how could i create a array that will contain start and end points of a lines

    tab(0)[pt1 pt2] first line
    tab(1)[pt1 pt2] second line

    should i use something like this it works but the points are all together so its not perfect

    Code:
    Dim Tab() As Point3d

  2. #2
    Super Member SEANT's Avatar
    Using
    AutoCAD 2012
    Join Date
    Aug 2005
    Location
    Rhode Island
    Posts
    1,968

    Default

    There are several methods to store the coordinates associated with points, and the best choice would probably depend on the downstream requirements of the data.

    Arrays are a valid option, and may even be the most efficient from a computer processing perspective. If the type and quantity of Points is unknown, arrays are a bit of a handful for the coder, however.

    The Autodesk.AutoCAD.Geometry.Point3dCollection is very easy to use - as points can be added and subtracted at will.

    With regard to collections (and their general ease of use), the System.Collections.Generic Namespace offers several other ways of storing points (or any data for that matter) and have the added benefit of making code more universal, i.e., not limited to just AutoCAD routines.

  3. #3
    Full Member
    Using
    AutoCAD 2010
    Join Date
    Aug 2009
    Posts
    47

    Default

    OK
    I'll try it thx

  4. #4
    Full Member
    Using
    AutoCAD 2010
    Join Date
    Aug 2009
    Posts
    47

    Default

    I think that is no need to create a new thread so i'll ask here have you got any idea why the ray in the function is not visible in the drawing if i use that code without function it works OK

    Code:
        <CommandMethod("src")> _
       Public Sub src()
            Dim lCmd As Editor = Application.DocumentManager.MdiActiveDocument.Editor
            Dim acBaza As Database = lCmd.Document.Database
            Dim trn As Transaction = acBaza.TransactionManager.StartTransaction
    
            Dim lnL1 As Line = New Line()
    
            Dim usrPtOp As PromptPointOptions = New PromptPointOptions("Wskarz srodek pomieszczenia :")
            Dim usrPt As PromptPointResult = lCmd.GetPoint(usrPtOp)
    
            Dim prevPt As Point3d = usrPt.Value
            Dim nextPt As Point3d = usrPt.Value
    
            If usrPt.Status = PromptStatus.OK Then
                Dim usrPtXmod As Point3d = New Point3d(usrPt.Value.X + 1, usrPt.Value.Y, usrPt.Value.Z)
                Dim promienSledzacy As Ray = New Ray()
                promienSledzacy.BasePoint = usrPt.Value
                promienSledzacy.SecondPoint = usrPtXmod
    
                'FILTRACJA LINII
                Dim typeValue() As TypedValue = {New TypedValue(0, "line")}
                Dim selFilter As SelectionFilter = New SelectionFilter(typeValue)
                Dim selResult As PromptSelectionResult = lCmd.SelectAll(selFilter)
                Dim ssLinie As SelectionSet = selResult.Value
                Dim tabID() As ObjectId = ssLinie.GetObjectIds
                Dim lnNajblizsza As Line = Nothing
                'TRANSAKCJA
                przecieciaPromienia(promienSledzacy, tabID, prevPt, nextPt, lnNajblizsza)
    
                'Sprawdzenie ktury punkt jest nizej
                Dim START As Point3d
                Dim FIN As Point3d
                If lnNajblizsza.StartPoint.Y > lnNajblizsza.EndPoint.Y Then
                    START = lnNajblizsza.EndPoint
                Else
                    START = lnNajblizsza.StartPoint
                End If
            End If
        End Sub
    
        Public Sub przecieciaPromienia(ByRef promienSledzacy As Ray, ByRef tabID() As ObjectId, ByRef prevPt As Point3d, ByRef nextPt As Point3d, ByRef lnNajblizsza As Line)
            Dim lCmd As Editor = Application.DocumentManager.MdiActiveDocument.Editor
            Dim acBaza As Database = lCmd.Document.Database
            Dim trn As Transaction = acBaza.TransactionManager.StartTransaction
            Try
                Dim btr As BlockTableRecord = trn.GetObject(acBaza.CurrentSpaceId, OpenMode.ForWrite)
                Dim objID As ObjectId
                Dim ra3d As Ray3d = New Ray3d(promienSledzacy.StartPoint, promienSledzacy.SecondPoint)
                Dim odl As Single = 0.0
                Dim odlTmp As Single = 0.0
                For Each objID In tabID
                    Dim ln As Line = CType(trn.GetObject(objID, OpenMode.ForRead), Line)
                    Dim ls As LineSegment3d = New LineSegment3d(ln.StartPoint, ln.EndPoint)
                    Dim ptArray() As Point3d = ls.IntersectWith(ra3d)
                    If ptArray Is Nothing Then Continue For
                    Dim ptkPrzeciecia As Point3dCollection = New Point3dCollection(ptArray)
                    'SZUKANIE PIERWSZEJ NAJBLIZSZEJ LINII   
                    '   odl=sqrt ((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)) 
    
                    odlTmp = Math.Sqrt((prevPt.X - ptkPrzeciecia.Item(0).X) * (prevPt.X - ptkPrzeciecia.Item(0).X) + (prevPt.Y - ptkPrzeciecia.Item(0).Y) * (prevPt.Y - ptkPrzeciecia.Item(0).Y))
    
                    If odl = 0.0 Then
                        odl = odlTmp
                        nextPt = ptkPrzeciecia.Item(0)
                        lnNajblizsza = ln
                    ElseIf odl >= odlTmp Then
                        nextPt = ptkPrzeciecia.Item(0)
                        lnNajblizsza = ln
                    End If
                Next
                lnNajblizsza.Highlight()
                promienSledzacy.SetDatabaseDefaults()
                btr.AppendEntity(promienSledzacy)
                trn.AddNewlyCreatedDBObject(promienSledzacy, True)
                trn.Commit()
            Catch ex As Exception
            Finally
                trn.Dispose()
            End Try
        End Sub

  5. #5
    Super Member SEANT's Avatar
    Using
    AutoCAD 2012
    Join Date
    Aug 2005
    Location
    Rhode Island
    Posts
    1,968

    Default

    I wouldn’t exactly say it is a definite but passing open database object references between sub/functions may not be the best practice. I modified the structure to illustrate an alternative. Note: Autodesk.AutoCAD.Geometry objects are not database residents

    I think the reason that the Ray was not showing was because the top level transaction had not been committed. Again, I modified the routine to illustrate that point.


    Code:
        <CommandMethod("src")> _
       Public Sub src()
            Dim lCmd As Editor = Application.DocumentManager.MdiActiveDocument.Editor
            Dim acBaza As Database = lCmd.Document.Database
            Using trn As Transaction = acBaza.TransactionManager.StartTransaction
    
                Dim lnL1 As Line = New Line()
    
                Dim usrPtOp As PromptPointOptions = New PromptPointOptions("Wskarz srodek pomieszczenia :")
                Dim usrPt As PromptPointResult = lCmd.GetPoint(usrPtOp)
    
                Dim prevPt As Point3d = usrPt.Value
                Dim nextPt As Point3d = usrPt.Value
    
                If usrPt.Status = PromptStatus.OK Then
                    Dim usrPtXmod As Point3d = New Point3d(usrPt.Value.X + 1, usrPt.Value.Y, usrPt.Value.Z)
                    Dim ls3d As LineSegment3d = New LineSegment3d(usrPt.Value, usrPtXmod)
    
    
                    'FILTRACJA LINII
                    Dim typeValue() As TypedValue = {New TypedValue(0, "line")}
                    Dim selFilter As SelectionFilter = New SelectionFilter(typeValue)
                    Dim selResult As PromptSelectionResult = lCmd.SelectAll(selFilter)
                    Dim ssLinie As SelectionSet = selResult.Value
                    Dim tabID() As ObjectId = ssLinie.GetObjectIds
    
                    Dim oid As ObjectId
                    'TRANSAKCJA
                    oid = przecieciaPromienia(ls3d, tabID, prevPt, nextPt)
                    Dim lnNajblizsza As Line = CType(trn.GetObject(oid, OpenMode.ForRead), Line)
                    'Sprawdzenie ktury punkt jest nizej
                    Dim START As Point3d
                    'Dim FIN As Point3d
                    If lnNajblizsza.StartPoint.Y > lnNajblizsza.EndPoint.Y Then
                        START = lnNajblizsza.EndPoint
                    Else
                        START = lnNajblizsza.StartPoint
                    End If
    
                End If
                trn.Commit()
            End Using
        End Sub
    
        Public Function przecieciaPromienia(ByRef ls3d As LineSegment3d, ByRef tabID() As ObjectId, ByRef prevPt As Point3d, ByRef nextPt As Point3d) As ObjectId
            Dim lCmd As Editor = Application.DocumentManager.MdiActiveDocument.Editor
            Dim acBaza As Database = Application.DocumentManager.MdiActiveDocument.Database
            Dim lnNajblizsza As Line = Nothing
            Using trn As Transaction = acBaza.TransactionManager.StartTransaction
    
                Try
                    Dim btr As BlockTableRecord = CType(trn.GetObject(acBaza.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)
                    Dim objID As ObjectId
                    Dim ra3d As Ray3d = New Ray3d(ls3d.StartPoint, ls3d.EndPoint)
    
                    Dim odl As Single = 0.0
                    Dim odlTmp As Single = 0.0
                    For Each objID In tabID
                        Dim ln As Line = CType(trn.GetObject(objID, OpenMode.ForRead), Line)
                        Dim ls As LineSegment3d = New LineSegment3d(ln.StartPoint, ln.EndPoint)
                        Dim ptArray() As Point3d = ls.IntersectWith(ra3d)
                        If ptArray Is Nothing Then Continue For
                        Dim ptkPrzeciecia As Point3dCollection = New Point3dCollection(ptArray)
                        'SZUKANIE PIERWSZEJ NAJBLIZSZEJ LINII   
                        '   odl=sqrt ((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)) 
    
                        odlTmp = Math.Sqrt((prevPt.X - ptkPrzeciecia.Item(0).X) * (prevPt.X - ptkPrzeciecia.Item(0).X) + (prevPt.Y - ptkPrzeciecia.Item(0).Y) * (prevPt.Y - ptkPrzeciecia.Item(0).Y))
    
                        If odl = 0.0 Then
                            odl = odlTmp
                            nextPt = ptkPrzeciecia.Item(0)
    
                        ElseIf odl >= odlTmp Then
                            nextPt = ptkPrzeciecia.Item(0)
    
                        End If
                        lnNajblizsza = ln
                    Next
                    lnNajblizsza.Highlight()
                    Dim promienSledzacy As Ray = New Ray()
                    promienSledzacy.BasePoint = ls3d.StartPoint
                    promienSledzacy.SecondPoint = ls3d.EndPoint
                    promienSledzacy.SetDatabaseDefaults()
                    btr.AppendEntity(promienSledzacy)
                    trn.AddNewlyCreatedDBObject(promienSledzacy, True)
                    trn.Commit()
                Catch ex As Exception
                End Try
                Return lnNajblizsza.ObjectId
            End Using
        End Function

  6. #6
    Full Member
    Using
    AutoCAD 2010
    Join Date
    Aug 2009
    Posts
    47

    Default

    Registered forum members do not see this ad.

    Thanks for the advice and the solution

Similar Threads

  1. Help turning 3d array into dxf
    By stdjpd21 in forum Autodesk Inventor
    Replies: 16
    Last Post: 21st Aug 2009, 07:39 pm
  2. need help with array
    By michaeloureiro in forum AutoCAD Beginners' Area
    Replies: 12
    Last Post: 10th Aug 2009, 04:06 pm
  3. eliptical array
    By michaeloureiro in forum AutoCAD Beginners' Area
    Replies: 5
    Last Post: 17th Dec 2008, 12:03 pm
  4. Array?
    By Barry in forum AutoCAD Beginners' Area
    Replies: 3
    Last Post: 25th Jun 2006, 07:42 pm
  5. customizing array?
    By Primus in forum AutoCAD Beginners' Area
    Replies: 5
    Last Post: 26th May 2006, 07:57 am

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts