- 积分
- 254
- 明经币
- 个
- 注册时间
- 2016-10-15
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2016-10-16 18:52:10
|
显示全部楼层
能否帮忙将这个单个CAD版本的应用程序修改为适合多个CAD版本的应用程序,如2010,2013等版本,本人愿意支付一定的费用,联系QQ:1067426844。程序码如下:- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using Microsoft.VisualBasic;
- using Autodesk.AutoCAD.Interop;
- using Autodesk.AutoCAD.Interop.Common;
- namespace CAD二次开发
- {
- public partial class Form1 : Form
- {
- public static Autodesk.AutoCAD.Interop.AcadApplication AcadApp;
- public static Autodesk.AutoCAD.Interop.AcadDocument AcadDoc;
- public Form1()
- {
- InitializeComponent();
- }
- public static void 启动CAD()
- {
- try
- {
- AcadApp = (AcadApplication)System.Runtime.InteropServices.Marshal.GetActiveObject("AutoCAD.Application");
- AcadDoc = AcadApp.ActiveDocument;
- }
- catch
- {
- AcadApp = new AcadApplication();
- AcadDoc = AcadApp.ActiveDocument;
- }
- AcadApp.Application.Visible = true;
- Microsoft.VisualBasic.Interaction.AppActivate(AcadApp.Caption);
- }
- private void button1_Click(object sender, EventArgs e)
- {
- 启动CAD();
- double Ks =0;
- double Ke = 2000;
- double Dmax = 150;
- double Dmin = -150;
- string VerCAD = (AcadApp.Version.ToString()).Substring(0, 2);//获取AutoCAD版本号,从左边截取2位字符
- AcadAcCmColor color1 = (AcadAcCmColor)AcadDoc.Application.GetInterfaceObject("AutoCAD.AcCmColor." + VerCAD);//新建一AcadAcCmColor对象,该对象用来给图形对象的颜色属性赋值
- AcadLayer acLayer;
- AcadText TextObj;
- acLayer = AcadDoc.Layers.Add("中心线");
- acLayer.color = AcColor.acYellow;
- acLayer.Lineweight = ACAD_LWEIGHT.acLnWt025;
- acLayer = AcadDoc.Layers.Add("文字标注");
- acLayer.color = AcColor.acGreen;
- acLayer = AcadDoc.Layers.Add("主网格");
- color1.SetRGB(66, 112, 138);
- acLayer.TrueColor = color1;
- acLayer.Lineweight = ACAD_LWEIGHT.acLnWt015;
- acLayer = AcadDoc.Layers.Add("副网格");
- color1.SetRGB(95, 58, 69);
- acLayer.TrueColor = color1;
- acLayer.Lineweight = ACAD_LWEIGHT.acLnWt005;
- double[] lineStartPoint = new Double[3];
- double[] lineEndPoint = new Double[3];
- double[] TextPoint = new Double[3];
- //水平网格线
- for (int i = Convert.ToInt32(Math.Ceiling(Dmin / 10)) * 10; i <= Math.Floor(Dmax / 10) * 10; i = i + 10)
- {
- lineStartPoint[0] = Ks ; lineStartPoint[1] = i;
- lineEndPoint[0] = Ke ; lineEndPoint[1] = i;
- if (i % 50 == 0)
- {
- if (i == 0)
- {
- AcadDoc.ModelSpace.AddLine(lineStartPoint, lineEndPoint).Layer = "中心线";
- }
- else
- {
- AcadDoc.ModelSpace.AddLine(lineStartPoint, lineEndPoint).Layer = "主网格";
- }
- }
- else
- {
- AcadDoc.ModelSpace.AddLine(lineStartPoint, lineEndPoint).Layer = "副网格";
- }
- }
- //竖向网格线
- for (int i = Convert.ToInt32(Math.Ceiling(Ks / 10)) * 10; i <= Math.Floor(Ke / 10) * 10; i = i + 10)
- {
- lineStartPoint[0] = i ; lineStartPoint[1] = Math.Ceiling(Dmin / 10) * 10;
- lineEndPoint[0] = i ; lineEndPoint[1] = Math.Floor(Dmax / 10) * 10;
- if (i % 50 == 0)
- {
- AcadDoc.ModelSpace.AddLine(lineStartPoint, lineEndPoint).Layer = "主网格";
- if (i % 100 == 0)
- {
- //标注里程
- TextPoint[0] = i ; TextPoint[1] = Math.Ceiling(Dmin / 10) * 10 - 10;
- string strText;
- if (i % 1000 == 0)
- {
- strText = "K" + (i / 1000).ToString();
- }
- else
- {
- strText = ((i / 100) % 10).ToString();
- }
- TextObj = AcadDoc.ModelSpace.AddText(strText, TextPoint, 7.5);
- TextObj.Alignment = AcAlignment.acAlignmentMiddleCenter;//文本对齐方式
- TextObj.TextAlignmentPoint = TextPoint;
- TextObj.Layer = "文字标注";
- //标注拨量
- if (i % 1000 == 0)
- {
- for (int j = Convert.ToInt32(Math.Ceiling(Dmin / 50)) * 50; j <= Math.Floor(Dmax / 50) * 50; j = j + 50)
- {
- TextPoint[0] = i - 5; TextPoint[1] = j;
- TextObj = AcadDoc.ModelSpace.AddText(j.ToString(), TextPoint, 7.5);
- TextObj.Alignment = AcAlignment.acAlignmentMiddleRight;//文本对齐方式
- TextObj.TextAlignmentPoint = TextPoint; //文本对齐点
- TextObj.Layer = "文字标注";
- }
- }
- }
- }
- }
- AcadDoc.ActiveLayer = AcadDoc.Layers.Add("0");//恢复0图层
- AcadDoc.SendCommand("_z\ne\n");
- AcadDoc.SendCommand("_regenall\n");//全部重生成模型
- Microsoft.VisualBasic.Interaction.AppActivate(AcadApp.Caption);
- }
- }
- }
|
|