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

vb.net autocad point object

2 REPLIES 2
Reply
Message 1 of 3
kcimos
1398 Views, 2 Replies

vb.net autocad point object

I want to obtain the X & Y values of 950 or so autocad point objects.

 

my code fails at the  "AutoCadPoint = TryCast(TransMan.GetObject(Id, OpenMode.ForRead, True), AcadPoint)" - AutoCadPoint isn't getting set to anything cuasing a crash when I try to get the corrdinates from it

 

FYI: ACF.SsGetAcadPointObjects creates an array of objectIDs called ACF.ssResult

 

Public Class BlocksAtPoints

    <CommandMethod("BBPTREE")> _
    Public Sub InsertTreeBlockAtPoint()

        Dim ocName As String
        Dim AutoCadPoint As AcadPoint

        Dim BlockPath As String

        BlockPath = "C:\AAA-Stuff"                                                     

        Dim idArray As ObjectId()
        Dim TransMan As Autodesk.AutoCAD.DatabaseServices.TransactionManager

        If ACF.SsGetAcadPointObjects("Select Points to have Dyanamic Tree Block inserted at:") = True Then


            Dim strBlockName As String = "DYN TREE.dwg"

            idArray = ACF.ssResult.GetObjectIds()

            TransMan = ACF.Db.TransactionManager          'start a transaction

            Using Tx As Transaction = ACF.Db.TransactionManager.StartTransaction

                For Each Id In idArray

                    ocName = Id.ObjectClass.Name

                    If ocName = "AcDbPoint" Then                'get its coords


                        AutoCadPoint = TryCast(TransMan.GetObject(Id, OpenMode.ForRead, True), AcadPoint)

                        MsgBox(AutoCadPoint.Handle.ToString)

                        Dim InsPt As New Point3d(AutoCadPoint.Coordinates(0), AutoCadPoint.Coordinates(1), 0)

                        If ACF.InsertBlock(strBlockName, InsPt, 1, 1, 1, 0, BlockPath) = False Then

                            MsgBox("error!!! block: " & strBlockName & " is not in the dwg, please insert it")
                            Exit Sub

                        End If

                    End If

                Next Id

            End Using

        Else

        End If

    End Sub

End Class

  can anyonw tell me how to tap into the autocad point object?

2 REPLIES 2
Message 2 of 3
hgasty1001
in reply to: kcimos

Hi,

 

The correct type for a point entity is DBPoint, please see the docs on this object, it has a property "position" that returns a Point3D, so you don't need to iterate an index to obtain the coordinates. I have no idea what an AcadPoint is (a com object?). Also could be a problem with the transaction,  usually you should start the transaction *before* obtaining object Ids, and if the ACF.SsGetAcadPointObjects it is returning the objectids of only dbpoints, you only need to call GetObject from those objectids to obtain a DBPoint (SomeDBPointObjectId.GetObject).

A workflow for this task could be as follow:

 

1.-Set you parameters (path, block names, etc)

2.-Start a Transaction

3.-Get the dbpoints objectIds

4.-Iterate the ObjectId collection to obtain each DBPoint, and Insert the block at each DBPoint.Position

5.-Commit the transaction

 

Gaston Nunez

 

 

 

 

Message 3 of 3
kcimos
in reply to: hgasty1001

thanks DBPOINT is what I was looking for.

goodle searching the problem only lead to discussions/info about getting selection points from the user.

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