PDA

View Full Version : How to export(X,Y,Z) of a point to a text file? or read them in vb.net ?



vnsharifi
21st Jan 2011, 04:13 am
Hello there. I found below lisp in internet. What is does is , It will find the bounding box of selected object and it put those data in minpoint and maxpoint variable and show them in command prompt.
with this format ( x1 y1 z1 , x2 y2 z2)
I believe , right term is " Buffer ".

Now my question is , how can I can read X,Y
coordinates of those point in vb net.

Or at least write them in a file.
I nice example would be helpful because I am not a pro.
Thanks for all help.

;;=============================
(defun C:minmax()
(setq BarEname (cdr (car (entget (car (entsel "\nselect your object "))))))
(ucs-bbox BarEname)
)

;; can be used with vla-transformby to
;; transform objects from the UCS to the WCS
(defun UCS2WCSMatrix ()
(vlax-tmatrix
(append
(mapcar '(lambda (vector origin) (append (trans vector 1 0 t) (list origin)) )
(list '(1 0 0) '(0 1 0) '(0 0 1))
(trans '(0 0 0) 0 1) )
(list '(0 0 0 1))
)
)
)
;; transform objects from the WCS to the UCS
(defun WCS2UCSMatrix ()
(vlax-tmatrix
(append
(mapcar '(lambda (vector origin)(append (trans vector 0 1 t) (list origin)))
(list '(1 0 0) '(0 1 0) '(0 0 1))
(trans '(0 0 0) 1 0)
)
(list '(0 0 0 1))
)
)
)
;; Returns the UCS coordinates of the object bounding box about UCS
;; Argument
;; obj : a graphical object (ename or vla-object)
;; Return
;; a list of left lower point and right upper point UCS coordinates
(defun ucs-bbox (obj / minpoint maxpoint)
(vl-load-com)
(and (= (type obj) 'ENAME)
(setq obj (vlax-ename->vla-object obj))
)
(vla-TransformBy obj (UCS2WCSMatrix))
(vla-getboundingbox obj 'minpoint 'maxpoint)
(vla-TransformBy obj (WCS2UCSMatrix))
(list (vlax-safearray->list minpoint)
(vlax-safearray->list maxpoint)
)
)

fixo
21st Jan 2011, 10:59 am
Here you go


'
' Created by SharpDevelop.
' User: Олег
' Date: 21.01.2011
' Time: 11:46
'
' To change this template use Tools | Options | Coding | Edit Standard Headers.
'
Imports System
Imports System.Text
Imports System.Data
Imports System.IO
Imports System.Globalization
Imports System.Collections
Imports System.Runtime.InteropServices
Imports System.Reflection
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.ApplicationServices

<Assembly: CommandClass(GetType(TextCommands.ImportPoints))>
Namespace TextCommands
Public Class ImportPoints
<CommandMethod("CSV")> _
Public Shared Sub ImbortBounds()
Dim fname As String="C:\usedFiles\bbox.csv"

Dim oldcult As CultureInfo= Threading.Thread.CurrentThread.CurrentCulture
Threading.Thread.CurrentThread.CurrentCulture= New CultureInfo("EN-us")

Dim db As Database=HostApplicationServices.WorkingDatabase
Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.D ocumentManager.MdiActiveDocument
Dim ed As Editor=doc.Editor
Dim mtx As Matrix3d= ed.CurrentUserCoordinateSystem
Dim pts As List(Of String)= New List(Of String)


Dim psr As PromptSelectionResult =ed.GetSelection()

If psr.Status <> PromptStatus.OK Then
ed.WriteMessage("{0}Selection Returned: {0}" ,vbCr,psr.Status)
Return
End If

Dim sset As SelectionSet = psr.Value

ed.WriteMessage("{0}Selection Returned: {0}" ,vbCr,sset.Count)
If sset.Count=0 Then
ed.WriteMessage("{0}Nothing Selected, exit...",vbcr)
return
End If
pts.Add(String.Format("{0}{6}{1}{6}{2}{6}{3}{6}{4}{6}{5}{7}", _
"Min X","Min Y","Min Z","Max X","Max Y","Max Z",vbtab,vbclf))
Using tr As Transaction=db.TransactionManager.StartTransaction ()

Try
For Each ent As SelectedObject In sset
Dim id As ObjectId = ent.ObjectId
Dim obj As Entity = TryCast(tr.GetObject(id, OpenMode.ForRead), Entity)
If (Not ent Is Nothing) Then


Dim ex3d As Extents3d=obj.GeometricExtents
Dim pd As Point3d=ex3d.MinPoint.TransformBy(mtx)
Dim pu As Point3d=ex3d.MaxPoint.TransformBy(mtx)


Dim strtmp As String= _
String.Format("{0:f3}{6}{1:f3}{6}{2:f3}{6}{3:f3}{6}{4:f3}{6}{5:f3 }{7}", _
pd.X,pd.Y,pd.Z,pu.X,pu.Y,pu.Z,vbtab,vbclf)

pts.Add(strtmp)

End if

Next
If pts.Count>1 Then

Try

Using sw As New StreamWriter(fname)

For Each coords As String In pts

sw.WriteLine(coords)
Next
sw.Close()
End Using

Catch ex As IOException
ed.WriteMessage("{0}Error while processing the file.",vbCr)

Catch ex As System.Exception
ed.WriteMessage("{0}Error reading in file data.",vbCr)

End Try

End If

Catch ex As System.Exception
ed.WriteMessage("{0}{1}",vbCr,ex.ToString)
Finally
Threading.Thread.CurrentThread.CurrentCulture=oldc ult
End Try

End using
End Sub

End Class
End Namespace


~'J'~