回望南山
记忆痕迹可以鲜明, 回望往事如数家珍——
posts - 177,  comments - 54,  trackbacks - 0
;;;功能:多义线添加顶点
;;;用法:(Add_Vertex <多义线ename>  <点pt> <凸度bulge>)
;;;如果点pt在多义线上,则添加该点作为多义线的一个顶点,并保持该点处的曲率不变;
;;;如果点pt不在多义线上,则添加该点作为多义线的最后一个顶点,并使新加子段的凸度为bulge。

(defun Add_Vertex (ename pt bulge / obj n dm d1 d2 pcen v plist)
  (setq obj (vlax-ename->vla-object ename))
  (if (vlax-curve-getParamAtPoint obj pt)
    (progn
  (setq n (fix (vlax-curve-getParamAtPoint obj pt)))
  (setq dm (vlax-curve-getDistAtPoint obj pt))
  (setq d1 (vlax-curve-getDistAtParam obj n))
  (setq d2 (vlax-curve-getDistAtParam obj (1+ n)))
  (setq v (vlax-curve-getsecondderiv obj n))
  (if (zerop (vla-getbulge obj n))
    (vla-AddVertex obj (1+ n) (ax:2DPoint pt))
    (progn 
 

      (if (> (vla-getbulge obj n) 0)
    (setq pcen (mapcar '+ (vlax-safearray->list (vlax-variant-value (vla-get-Coordinate obj n))) v))
    (setq pcen (mapcar '- (vlax-safearray->list (vlax-variant-value (vla-get-Coordinate obj n))) v))
      )
      (setq ang2m
        (* 0.25
           (- (angle pcen (vlax-safearray->list (vlax-variant-value(vla-get-Coordinate obj (1+ n)))))
          (angle pcen pt)
           )
        )
        angm1
        (* 0.25
           (- (angle pcen pt)
          (angle pcen (vlax-safearray->list (vlax-variant-value(vla-get-Coordinate obj n))))
           )
        )
      )
      (vla-AddVertex obj (1+ n) (ax:2DPoint pt))
      (vla-SetBulge obj n (/ (sin angm1) (cos angm1)))
      (vla-SetBulge obj (1+ n) (/ (sin ang2m) (cos ang2m)))
    )
  )
  )
  (progn
    (setq plist    (vlax-safearray->list
          (vlax-variant-value
            (vla-get-coordinates obj)
          )
        )
    )
    (vla-AddVertex obj (/ (length plist) 2) (ax:2DPoint pt))
    (vla-SetBulge obj (1- (/ (length plist) 2)) bulge)
    )
  )
  (vla-update obj)
  (princ)
)  

(defun ax:2DPoint (pt)
  (vlax-make-variant
    (vlax-safearray-fill
      (vlax-make-safearray vlax-vbdouble '(0 . 1))
      (list (car pt) (cadr pt))
    )
  )
)

 方法2: 
;;;--------------------------------------------------------
;;;函数: c:adv
;;;--------------------------------------------------------
;;;来源:            作者: caddog
;;;编制时间:2007.3
;;;功能:     添加多段线的顶点
;;;语法:    
;;;参数     
;;;返回值:  
;;;备注  :   学习VBA看到ADDVERTEX,试着写了一个看看,没考虑弧
;;;--------------------------------------------------------
(DEFUN C:ad (/ 2dp ename n obj p pp ss1 ss2 t1 var2dp StartWidth
       endWidth)
  (SETQ SS1 (ENTSEL "\n请选择一条多段线:"))
  (SETQ ENAME (CAR SS1))
  (SETQ OBJ (VLAX-ENAME->VLA-OBJECT ENAME))
  ;;如果是多段线则处理
  (IF (WCMATCH (VLA-GET-OBJECTNAME obj) "LWPOLYLINE,AcDbPolyline") ;_ 结束wcmatch
    (PROGN
      ;;显示多段线的夹点,便于用户查看 
      (SETQ ss2 (SSADD ENAME))
      (SSSETFIRST NIL ss2)
      ;;提示用户选择插入点
      (SETQ P (GETPOINT "\n请选择插入点:"))
      ;;当点P有值时循环
      (WHILE p
 ;;确定用户所指定的插入点的位置,是在哪个顶点之后
 (SETQ PP (VLAX-CURVE-GETCLOSESTPOINTTO OBJ (TRANS P 1 0)))
 (SETQ N (+ (FIX (VLAX-CURVE-GETPARAMATPOINT OBJ PP)) 1))
 ;;取插入点外原来的起始宽度和终止宽度
 ;;试着用PEDIT命令添加顶点,观察加入点后宽度的变化可知
 ;;新加入顶点的起始/终止宽度均为原来的的终止宽度
 (VLA-GETWIDTH obj (- n 1) 'StartWidth 'endWidth)
 ;;创建安全数组,并将点取的坐标赋给它.注意ADDVERTEX方法只接受二维点
 (SETQ 2DP (VLAX-MAKE-SAFEARRAY VLAX-VBDOUBLE '(0 . 1)))
 (VLAX-SAFEARRAY-FILL 2DP (LIST (CAR P) (CADR P)))
 ;;转换安全数组为变体
 (SETQ VAR2DP (VLAX-MAKE-VARIANT 2DP))
 ;;调用ACTIVEX方法添加顶点
 (VLA-ADDVERTEX OBJ N VAR2DP)
 ;;调整宽度
 (VLA-SETWIDTH obj n endWidth endWidth)

 (SETQ P (GETPOINT "\n请选择插入点:"))
      ) ;_end while
      (PRINC)
      (SSSETFIRST NIL) ;_取消夹取的状态
    ) ;_end progn
    (PROGN
      (PRINC "\n您选择的不是多段线!")
      (PRINC)
    ) ;_end else progn
  ) ;_end if
  (princ)
) ;_end defun

posted on 2008-05-02 14:24 深藏记忆 阅读(992) 评论(5)  编辑  收藏 所属分类: 转载Vlisp

FeedBack:
# re: 多义线添加顶点.lsp
2008-05-02 18:09 | 晚儿
看不懂 是vb嘛?
椰汁的味道 跟 椰树牌椰汁 味道 差的很多  回复  更多评论
  
# re: 多义线添加顶点.lsp
2012-04-28 03:06 | vlisp123
要导出EXCEL,需要一个DataTable数据表才行,把DataTable dt;//定义一个数据表类型这句代码放到最外层,即class下面。使之成为一个全局变量。
然后InOutExcel.SaveAsExcel(dt);调用

load加载方法里:
//读取用户列表加载到下拉框
string sql = "select * from UserAdmin";//SQL查询语句
DataTable dT = DbHelper.Fill(sql);//返回一个DataTable数据表
for (int i = 0; i < dT.Rows.Count; i++)//循环每一行
{
string str = dT.Rows[i]["UserName"].ToString();//读取UserName字段
this.comboBox1.Items.Add(str);//放进comboBox1中
}



-------------------------------------------------------------
相应的用下拉框comboBox1来接收用户名
//获取输入信息
//string UserName = this.txtName.Text;//读取用户名
string UserName = this.comboBox1.Text;
string PassWord = this.txtPWS.Text;//读取密码


  回复  更多评论
  
# re: 多义线添加顶点.lsp
2012-04-28 03:08 | vlisp123
InOutExcel.cs.txt
using System;
using System.Collections.Generic;
//using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Data.OleDb;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Configuration;
using DotNet.DbUtilities;
using DotNet.Utilities;  回复  更多评论
  
# re: 多义线添加顶点.lsp
2012-04-28 03:09 | vlisp123
namespace VS
{
public class InOutExcel
{
//把当前查询结果导出Excel
/// <summary>
/// 导出到Excel
/// </summary>
/// <param name="dtExcel">数据源</param>
public static void SaveAsExcel(System.Data.DataTable dtExcel)
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "导出Excel (*.xls)|*.xls";
saveFileDialog.FilterIndex = 0;
saveFileDialog.RestoreDirectory = true;
saveFileDialog.CreatePrompt = true;
saveFileDialog.Title = "导出文件保存路径";
saveFileDialog.ShowDialog();
string strName = saveFileDialog.FileName;
if (strName.Length != 0)
{
//导出到execl
System.Reflection.Missing miss = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Excel.ApplicationClass excel = new Microsoft.Office.Interop.Excel.ApplicationClass();
try
{
excel.Application.Workbooks.Add(true);
excel.Visible = false;//若是true,则在导出的时候会显示EXcel界面。
if (excel == null)
{
MessageBox.Show("EXCEL无法启动!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
Microsoft.Office.Interop.Excel.Workbooks books = (Microsoft.Office.Interop.Excel.Workbooks)excel.Workbooks;
Microsoft.Office.Interop.Excel.Workbook book = (Microsoft.Office.Interop.Excel.Workbook)(books.Add(miss));
Microsoft.Office.Interop.Excel.Worksheet sheet = (Microsoft.Office.Interop.Excel.Worksheet)book.ActiveSheet;
sheet.Name = "test";

int m = 0, n = 0;
//生成列名称 这里i是从1开始的 因为我第0列是个隐藏列ID 没必要写进去
for (int i = 0; i < dtExcel.Columns.Count; i++)
{
excel.Cells[1, i + 1] = dtExcel.Columns[i].Caption.ToString();
}

//填充数据
for (int i = 0; i < dtExcel.Rows.Count; i++)
{
//j也是从1开始 原因如上 每个人需求不一样
for (int j = 0; j < dtExcel.Columns.Count; j++)
{
if (dtExcel.Rows[i][j].ToString().GetType() == typeof(string))
{
excel.Cells[i + 2, j + 1] = "'" + dtExcel.Rows[i][j].ToString().Trim();
}
else
{
excel.Cells[i + 2, j + 1] = dtExcel.Rows[i][j].ToString().Trim();
}
}
}

sheet.SaveAs(strName, miss, miss, miss, miss, miss, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, miss, miss, miss);
book.Close(false, miss, miss);
books.Close();
excel.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(sheet);
System.Runtime.InteropServices.Marshal.ReleaseComObject(book);
System.Runtime.InteropServices.Marshal.ReleaseComObject(books);
System.Runtime.InteropServices.Marshal.ReleaseComObject(excel);

GC.Collect();
MessageBox.Show("数据已经成功导出!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
//toolStripProgressBar1.Value = 0;
System.Diagnostics.Process.Start(strName);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "错误提示");
}
finally
{
//excel.Quit();
KillSpecialExcel(excel);

}
}
}
  回复  更多评论
  
# re: 多义线添加顶点.lsp
2012-04-28 03:11 | vlisp123
#region Kill Special Excel Process
[DllImport("User32.dll", CharSet = CharSet.Auto)]
static extern int GetWindowThreadProcessId(IntPtr hWnd, out int lpdwProcessId);

//推荐这个方法,找了很久,不容易啊
private static void KillSpecialExcel(Microsoft.Office.Interop.Excel.Application m_objExcel)
{
try
{
if (m_objExcel != null)
{
int lpdwProcessId;
GetWindowThreadProcessId(new IntPtr(m_objExcel.Hwnd), out lpdwProcessId);
System.Diagnostics.Process.GetProcessById(lpdwProcessId).Kill();
}
}
catch (Exception ex)
{
Console.WriteLine("Delete Excel Process Error:" + ex.Message);
}
}
#endregion


}
}




this.状态栏.Text="你好!"+User.UserName+"("+User.Role +")";  回复  更多评论
  

飘过是缘,相识最真

订阅到抓虾
google reader
gougou


点击这里给我发消息


<2008年5月>
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567

常用链接

留言簿(5)

随笔分类

随笔档案

文章分类

文章档案

相册

收藏夹

八面来息

天天充电

同行者

积分与排名

  • 积分 - 59540
  • 排名 - 62

最新评论

阅读排行榜

评论排行榜