明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
12
返回列表 发新帖

[运行时] .C#4.0 实现晚绑定来调用Com库

[复制链接]
发表于 2016-6-6 12:58 | 显示全部楼层
if (pars<i>.IsOut)
                        lst.Add(args<i>);
提示如下错误:

错误        CS0307        变量“pars”不能与类型参数一起使用       

错误        CS0118        “i”是 变量,但此处被当做 类型 来使用

错误        CS0307        变量“ref object[]”不能与类型参数一起使用

错误        CS0118        “i”是 变量,但此处被当做 类型 来使用

请问是什么原因?
发表于 2016-9-19 13:06 | 显示全部楼层
不错,C#在com方面的介绍比起VB太少了
发表于 2016-10-16 18:52 | 显示全部楼层
雪山飞狐_lzh 发表于 2015-4-5 14:53
变体参数的反射

Utiility类中大量的函数使用了变体。。。

能否帮忙将这个单个CAD版本的应用程序修改为适合多个CAD版本的应用程序,如2010,2013等版本,本人愿意支付一定的费用,联系QQ:1067426844。程序码如下:
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using Microsoft.VisualBasic;
  10. using Autodesk.AutoCAD.Interop;
  11. using Autodesk.AutoCAD.Interop.Common;

  12. namespace CAD二次开发
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         public static Autodesk.AutoCAD.Interop.AcadApplication AcadApp;
  17.         public static Autodesk.AutoCAD.Interop.AcadDocument AcadDoc;
  18.         public Form1()
  19.         {
  20.             InitializeComponent();
  21.         }
  22.         public static void 启动CAD()
  23.         {
  24.             try
  25.             {
  26.                 AcadApp = (AcadApplication)System.Runtime.InteropServices.Marshal.GetActiveObject("AutoCAD.Application");
  27.                 AcadDoc = AcadApp.ActiveDocument;
  28.             }
  29.             catch
  30.             {
  31.                 AcadApp = new AcadApplication();
  32.                 AcadDoc = AcadApp.ActiveDocument;
  33.             }
  34.             AcadApp.Application.Visible = true;
  35.             Microsoft.VisualBasic.Interaction.AppActivate(AcadApp.Caption);
  36.         }

  37.         private void button1_Click(object sender, EventArgs e)
  38.         {
  39.             启动CAD();

  40.             double Ks =0;
  41.             double Ke = 2000;
  42.             double Dmax = 150;
  43.             double Dmin = -150;

  44.             string VerCAD = (AcadApp.Version.ToString()).Substring(0, 2);//获取AutoCAD版本号,从左边截取2位字符
  45.             AcadAcCmColor color1 = (AcadAcCmColor)AcadDoc.Application.GetInterfaceObject("AutoCAD.AcCmColor." + VerCAD);//新建一AcadAcCmColor对象,该对象用来给图形对象的颜色属性赋值
  46.             AcadLayer acLayer;
  47.             AcadText TextObj;

  48.             acLayer = AcadDoc.Layers.Add("中心线");
  49.             acLayer.color = AcColor.acYellow;
  50.             acLayer.Lineweight = ACAD_LWEIGHT.acLnWt025;

  51.             acLayer = AcadDoc.Layers.Add("文字标注");
  52.             acLayer.color = AcColor.acGreen;

  53.             acLayer = AcadDoc.Layers.Add("主网格");
  54.             color1.SetRGB(66, 112, 138);
  55.             acLayer.TrueColor = color1;
  56.             acLayer.Lineweight = ACAD_LWEIGHT.acLnWt015;

  57.             acLayer = AcadDoc.Layers.Add("副网格");
  58.             color1.SetRGB(95, 58, 69);
  59.             acLayer.TrueColor = color1;
  60.             acLayer.Lineweight = ACAD_LWEIGHT.acLnWt005;

  61.             double[] lineStartPoint = new Double[3];
  62.             double[] lineEndPoint = new Double[3];
  63.             double[] TextPoint = new Double[3];

  64.             //水平网格线
  65.             for (int i = Convert.ToInt32(Math.Ceiling(Dmin / 10)) * 10; i <= Math.Floor(Dmax / 10) * 10; i = i + 10)
  66.             {
  67.                 lineStartPoint[0] = Ks ; lineStartPoint[1] = i;
  68.                 lineEndPoint[0] = Ke ; lineEndPoint[1] = i;

  69.                 if (i % 50 == 0)
  70.                 {
  71.                     if (i == 0)
  72.                     {
  73.                         AcadDoc.ModelSpace.AddLine(lineStartPoint, lineEndPoint).Layer = "中心线";
  74.                     }
  75.                     else
  76.                     {
  77.                         AcadDoc.ModelSpace.AddLine(lineStartPoint, lineEndPoint).Layer = "主网格";
  78.                     }
  79.                 }
  80.                 else
  81.                 {
  82.                     AcadDoc.ModelSpace.AddLine(lineStartPoint, lineEndPoint).Layer = "副网格";
  83.                 }
  84.             }

  85.             //竖向网格线
  86.             for (int i = Convert.ToInt32(Math.Ceiling(Ks / 10)) * 10; i <= Math.Floor(Ke / 10) * 10; i = i + 10)
  87.             {
  88.                 lineStartPoint[0] = i ; lineStartPoint[1] = Math.Ceiling(Dmin / 10) * 10;
  89.                 lineEndPoint[0] = i ; lineEndPoint[1] = Math.Floor(Dmax / 10) * 10;

  90.                 if (i % 50 == 0)
  91.                 {
  92.                     AcadDoc.ModelSpace.AddLine(lineStartPoint, lineEndPoint).Layer = "主网格";
  93.                     if (i % 100 == 0)
  94.                     {
  95.                         //标注里程
  96.                         TextPoint[0] = i ; TextPoint[1] = Math.Ceiling(Dmin / 10) * 10 - 10;
  97.                         string strText;
  98.                         if (i % 1000 == 0)
  99.                         {
  100.                             strText = "K" + (i / 1000).ToString();
  101.                         }
  102.                         else
  103.                         {
  104.                             strText = ((i / 100) % 10).ToString();
  105.                         }
  106.                         TextObj = AcadDoc.ModelSpace.AddText(strText, TextPoint, 7.5);
  107.                         TextObj.Alignment = AcAlignment.acAlignmentMiddleCenter;//文本对齐方式
  108.                         TextObj.TextAlignmentPoint = TextPoint;
  109.                         TextObj.Layer = "文字标注";

  110.                         //标注拨量
  111.                         if (i % 1000 == 0)
  112.                         {
  113.                             for (int j = Convert.ToInt32(Math.Ceiling(Dmin / 50)) * 50; j <= Math.Floor(Dmax / 50) * 50; j = j + 50)
  114.                             {
  115.                                 TextPoint[0] = i  - 5; TextPoint[1] = j;
  116.                                 TextObj = AcadDoc.ModelSpace.AddText(j.ToString(), TextPoint, 7.5);
  117.                                 TextObj.Alignment = AcAlignment.acAlignmentMiddleRight;//文本对齐方式
  118.                                 TextObj.TextAlignmentPoint = TextPoint;                //文本对齐点
  119.                                 TextObj.Layer = "文字标注";
  120.                             }
  121.                         }
  122.                     }
  123.                 }

  124.             }

  125.             AcadDoc.ActiveLayer = AcadDoc.Layers.Add("0");//恢复0图层
  126.             AcadDoc.SendCommand("_z\ne\n");
  127.             AcadDoc.SendCommand("_regenall\n");//全部重生成模型

  128.             Microsoft.VisualBasic.Interaction.AppActivate(AcadApp.Caption);

  129.         }
  130.     }
  131. }
发表于 2017-7-28 09:01 | 显示全部楼层
mark
发表于 2018-5-1 09:17 | 显示全部楼层
飞狐大侠,你好。从你的帖子中学到了很多,非常感谢。
有一个问题请教 一下:使用C# COM,怎么调用sendcommand命令,实现两条直线trim的功能?(在sendcommand命令中,可以使用handent,但是无法使用list()),或者不用调用sendcommand,有无其它命令。
非常期待能获得你的指点。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-3-29 04:24 , Processed in 0.138638 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表