乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 89|回复: 6

测量展点程序,开源啦~

[复制链接]

24

主题

42

帖子

3

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
138
发表于 2013-5-21 22:36:00 | 显示全部楼层 |阅读模式
程序VS2008写的For CAD2010
测量数据文件格式:
1,kz,22,22,35
2,p,25,25,86
3,f,58,756,96
依此类推
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. using Autodesk..ApplicationServices;
  9. using Autodesk.AutoCAD.DatabaseServices;
  10. using Autodesk.AutoCAD.EditorInput;
  11. using Autodesk.AutoCAD.Geometry;
  12. using Autodesk.AutoCAD.Interop;
  13. using Autodesk.AutoCAD.Interop.Common;
  14. using Autodesk.AutoCAD.Runtime;
  15.       [CommandMethod("PointOutNet")]
  16.         public void PointOutNet()
  17.         {           
  18.             //MessageBox.Show("");
  19.             List files=new List ();
  20.             System.Windows.Forms.OpenFileDialog openDialog = new System.Windows.Forms.OpenFileDialog();
  21.             openDialog.Multiselect = true;
  22.             openDialog.Filter = "数据文件|*.dat";
  23.             openDialog.Title = "选择数据文件(可多选)";
  24.             openDialog.RestoreDirectory = false;
  25.             if (openDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  26.             {
  27.                 foreach (string file in openDialog.FileNames)
  28.                 {
  29.                     files.Add(file);
  30.                 }
  31.             }
  32.             foreach (string file in files)
  33.             {
  34.                 PointOutNet(file);
  35.             }
  36.         }
  37.         public void PointOutNet(string FileName)
  38.         {
  39.             Document doc = Application.DocumentManager.MdiActiveDocument;
  40.             Database db = doc.Database;
  41.             Editor ed = doc.Editor;
  42.             string[] strArray;
  43.             List data = new List();
  44.             List dataNew = new List();
  45.             FileStream fStream = new FileStream(FileName, FileMode.Open);
  46.             StreamReader sReader = new StreamReader(fStream);
  47.             string dataRow = sReader.ReadLine();
  48.             while (dataRow != null)
  49.             {
  50.                 data.Add(dataRow);
  51.                 dataRow = sReader.ReadLine();
  52.             }
  53.            sReader.Close();
  54.             foreach (string pt in data)
  55.             {
  56.                 strArray = pt.Split(new char[] { ',' });
  57.                 if (strArray.Length >= 5)
  58.                 {
  59.                     dataNew.Add(strArray);
  60.                 }               
  61.             }
  62.             using (Transaction trans = db.TransactionManager.StartTransaction())
  63.             {
  64.                 BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
  65.                 BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
  66.                 foreach (string[] pt in dataNew)
  67.                 {                     
  68.                     double y = Convert.ToDouble(pt[2]);
  69.                     double x = Convert.ToDouble(pt[3]);
  70.                     double h = Convert.ToDouble(pt[4]);
  71.                     Point3d p1 = new Point3d(y, x, h);
  72.                     DBPoint newPoint = new DBPoint(p1);
  73.                     btr.AppendEntity(newPoint);
  74.                     trans.AddNewlyCreatedDBObject(newPoint, true);
  75.                 }
  76.                 trans.Commit();
  77.             }
  78.         }
回复

使用道具 举报

4

主题

86

帖子

7

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
102
发表于 2013-5-22 08:43:00 | 显示全部楼层
支持,这个实现起来倒不难,两个com引用没用到,去掉多好
回复

使用道具 举报

0

主题

7

帖子

1

银币

初来乍到

Rank: 1

铜币
7
发表于 2013-5-22 09:50:00 | 显示全部楼层
_Public Sub addRibbon() 'MessageBox.Show(""); Dim files As New List(Of String)() Dim openDialog As New System.Windows.Forms.OpenFileDialog() openDialog.Multiselect = True openDialog.Filter = "数据文件|*.dat" openDialog.Title = "选择数据文件(可多选)" openDialog.RestoreDirectory = False If openDialog.ShowDialog() = System.Windows.Forms.DialogResult.OK Then  For Each file As String In openDialog.FileNames   files.Add(file)  Next End If For Each file As String In files  PointOutNet(file) NextEnd SubPublic Sub PointOutNet(FileName As String) Dim doc As Document = Application.DocumentManager.MdiActiveDocument Dim db As Database = doc.Database Dim ed As Editor = doc.Editor Dim strArray As String() Dim data As New List(Of String)() Dim dataNew As New List(Of String())() Dim fStream As New FileStream(FileName, FileMode.Open) Dim sReader As New StreamReader(fStream) Dim dataRow As String = sReader.ReadLine() While dataRow IsNot Nothing  data.Add(dataRow)  dataRow = sReader.ReadLine() End While sReader.Close() For Each pt As String In data  strArray = pt.Split(New Char() {","C})  If strArray.Length >= 5 Then   dataNew.Add(strArray)  End If Next Using trans As Transaction = db.TransactionManager.StartTransaction()  Dim bt As BlockTable = DirectCast(trans.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)  Dim btr As BlockTableRecord = DirectCast(trans.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite), BlockTableRecord)  For Each pt As String() In dataNew   Dim y As Double = Convert.ToDouble(pt(2))   Dim x As Double = Convert.ToDouble(pt(3))   Dim h As Double = Convert.ToDouble(pt(4))   Dim p1 As New Point3d(y, x, h)   Dim newPoint As New DBPoint(p1)   btr.AppendEntity(newPoint)   trans.AddNewlyCreatedDBObject(newPoint, True)  Next  trans.Commit() End UsingEnd Sub
回复

使用道具 举报

0

主题

7

帖子

1

银币

初来乍到

Rank: 1

铜币
7
发表于 2013-5-22 09:51:00 | 显示全部楼层
VB版本,怎么这么乱?
  1. _Public Sub addRibbon() 'MessageBox.Show(""); Dim files As New List(Of String)() Dim openDialog As New System.Windows.Forms.OpenFileDialog() openDialog.Multiselect = True openDialog.Filter = "数据文件|*.dat" openDialog.Title = "选择数据文件(可多选)" openDialog.RestoreDirectory = False If openDialog.ShowDialog() = System.Windows.Forms.DialogResult.OK Then  For Each file As String In openDialog.FileNames   files.Add(file)  Next End If For Each file As String In files  PointOutNet(file) NextEnd SubPublic Sub PointOutNet(FileName As String) Dim doc As Document = Application.DocumentManager.MdiActiveDocument Dim db As Database = doc.Database Dim ed As Editor = doc.Editor Dim strArray As String() Dim data As New List(Of String)() Dim dataNew As New List(Of String())() Dim fStream As New FileStream(FileName, FileMode.Open) Dim sReader As New StreamReader(fStream) Dim dataRow As String = sReader.ReadLine() While dataRow IsNot Nothing  data.Add(dataRow)  dataRow = sReader.ReadLine() End While sReader.Close() For Each pt As String In data  strArray = pt.Split(New Char() {","C})  If strArray.Length >= 5 Then   dataNew.Add(strArray)  End If Next Using trans As Transaction = db.TransactionManager.StartTransaction()  Dim bt As BlockTable = DirectCast(trans.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)  Dim btr As BlockTableRecord = DirectCast(trans.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite), BlockTableRecord)  For Each pt As String() In dataNew   Dim y As Double = Convert.ToDouble(pt(2))   Dim x As Double = Convert.ToDouble(pt(3))   Dim h As Double = Convert.ToDouble(pt(4))   Dim p1 As New Point3d(y, x, h)   Dim newPoint As New DBPoint(p1)   btr.AppendEntity(newPoint)   trans.AddNewlyCreatedDBObject(newPoint, True)  Next  trans.Commit() End UsingEnd Sub
回复

使用道具 举报

0

主题

7

帖子

1

银币

初来乍到

Rank: 1

铜币
7
发表于 2013-5-22 09:54:00 | 显示全部楼层
能帮我删了吗,太乱了!
回复

使用道具 举报

0

主题

7

帖子

1

银币

初来乍到

Rank: 1

铜币
7
发表于 2013-5-22 10:17:00 | 显示全部楼层
好东西,谢谢楼主!
  1. Public Sub PointOutNet()
  2.         'MessageBox.Show("");
  3.         Dim files As New List(Of String)()
  4.         Dim openDialog As New System.Windows.Forms.OpenFileDialog()
  5.         openDialog.Multiselect = True
  6.         openDialog.Filter = "数据文件|*.dat"
  7.         openDialog.Title = "选择数据文件(可多选)"
  8.         openDialog.RestoreDirectory = False
  9.         If openDialog.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
  10.             For Each file As String In openDialog.FileNames
  11.                 files.Add(file)
  12.             Next
  13.         End If
  14.         For Each file As String In files
  15.             PointOutNet(file)
  16.         Next
  17.     End Sub
  18.     Public Sub PointOutNet(ByVal FileName As String)
  19.         Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
  20.         Dim db As Database = doc.Database
  21.         Dim ed As Editor = doc.Editor
  22.         Dim strArray As String()
  23.         Dim data As New List(Of String)()
  24.         Dim dataNew As New List(Of String())()
  25.         Dim fStream As New FileStream(FileName, FileMode.Open)
  26.         Dim sReader As New StreamReader(fStream)
  27.         Dim dataRow As String = sReader.ReadLine()
  28.         While dataRow IsNot Nothing
  29.             data.Add(dataRow)
  30.             dataRow = sReader.ReadLine()
  31.         End While
  32.         sReader.Close()
  33.         For Each pt As String In data
  34.             strArray = pt.Split(New Char() {","c})
  35.             If strArray.Length >= 5 Then
  36.                 dataNew.Add(strArray)
  37.             End If
  38.         Next
  39.         Using trans As Transaction = db.TransactionManager.StartTransaction()
  40.             Dim bt As BlockTable = DirectCast(trans.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)
  41.             Dim btr As BlockTableRecord = DirectCast(trans.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite), BlockTableRecord)
  42.             For Each pt As String() In dataNew
  43.                 Dim y As Double = Convert.ToDouble(pt(2))
  44.                 Dim x As Double = Convert.ToDouble(pt(3))
  45.                 Dim h As Double = Convert.ToDouble(pt(4))
  46.                 Dim p1 As New Point3d(y, x, h)
  47.                 Dim newPoint As New DBPoint(p1)
  48.                 btr.AppendEntity(newPoint)
  49.                 trans.AddNewlyCreatedDBObject(newPoint, True)
  50.             Next
  51.             trans.Commit()
  52.         End Using
  53.     End Sub
回复

使用道具 举报

20

主题

73

帖子

3

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
153
发表于 2013-5-24 22:17:00 | 显示全部楼层
支持开源,虽然功能比我以前写的简单些.贵在共享!
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-14 18:36 , Processed in 1.428078 second(s), 66 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表