请教一下,如何在后期绑定中创建面域呢?
在c#中 通过activex方式操作AutoCAD,代码如下:dynamic[] circleObj=new dynamic
double[] calpt = new double;
calpt = 0; calpt = 0; calpt = 0;
circleObj = AcadDoc.ModelSpace.AddCircle(cirPt, 10);
//生成面域
dynamic[] regionObject;
regionObject = (dynamic[])AcadDoc.ModelSpace.AddRegion(circleObj); //执行到这句出现: 对象数组无效 错误
dynamic profileRegionObject = (dynamic)(regionObject);
调试的时候发生如下错误: 对象数组无效
请问各位有什么好的解决办法?
本帖最后由 Real_King 于 2016-4-6 11:21 编辑
public virtual dynamic AddRegion(object ObjectList)返回值为dynamic
或者试试(object[])AcadDoc.ModelSpace.AddRegion() Real_King 发表于 2016-4-6 11:17 static/image/common/back.gif
public virtual dynamic AddRegion(object ObjectList)返回值为dynamic
或者试试(object[])AcadDoc.Mode ...
(object[])AcadDoc.ModelSpace.AddRegion() 这种方法也出现相同的错误.
public virtual dynamic AddRegion(object ObjectList) 这个如何用的? SurveyCAD 发表于 2016-4-6 12:28 static/image/common/back.gif
(object[])AcadDoc.ModelSpace.AddRegion() 这种方法也出现相同的错误.
public virtual dynamic AddRe ...
给你来个实例吧
Acad3DSolid damObjectCopy;
Acad3DPolyline[] polyline = new Acad3DPolyline;
AcadRegion regionObj;
try
{
damObjectCopy = (Acad3DSolid)damObject.Copy();
double[] regionCoords = new double, minPoint = new double, maxPoint = new
double;
object minPointObject, maxPointObject;
damObjectCopy.GetBoundingBox(out minPointObject, out maxPointObject);
minPoint = (double[])minPointObject;
maxPoint = (double[])maxPointObject;
regionCoords = minPoint; regionCoords = minPoint; regionCoords =
startHeight;
regionCoords = maxPoint; regionCoords = minPoint; regionCoords =
startHeight;
regionCoords = maxPoint; regionCoords = maxPoint; regionCoords =
startHeight;
regionCoords = minPoint; regionCoords = maxPoint; regionCoords =
startHeight;
polyline = AcadDoc.ModelSpace.Add3DPoly(regionCoords);
polyline.Closed = true;
object[] tempObject;
tempObject = (object[])AcadDoc.ModelSpace.AddRegion(polyline);
regionObj = (AcadRegion)(tempObject);
Acad3DSolid boolObjectB;
boolObjectB = AcadDoc.ModelSpace.AddExtrudedSolid(regionObj, endHeight - startHeight,
0.0);
damObjectCopy.Boolean(AcBooleanType.acIntersection, boolObjectB);
damObjectCopy.Layer = "划分后模型";
polyline.Delete();
regionObj.Delete();
}
catch
{
polyline.Delete();
erroInfoRichTextBox.Text += "在划分模型" + damObject.Layer.ToString()
+ "时:高程"+startHeight.ToString()+"至"+endHeight.ToString()+"出错!\n";
} Real_King 发表于 2016-4-6 14:34 static/image/common/back.gif
给你来个实例吧
Acad3DSolid damObjectCopy;
Acad3DPolyline[] polyline = new Acad3DPolyline;
你这个是在前期绑定中可以吧? 在后期绑定中是 没有AcadRegion ,Acad3DSolid 等等实体定义的. 本帖最后由 Real_King 于 2016-4-6 15:50 编辑
SurveyCAD 发表于 2016-4-6 14:38 static/image/common/back.gif
你这个是在前期绑定中可以吧? 在后期绑定中是 没有AcadRegion ,Acad3DSolid 等等实体定义的.
把你的circleObj在作为参数时强类型化一下试试,或者直接强类型化circleObj Real_King 发表于 2016-4-6 15:35 static/image/common/back.gif
把你的circleObj在作为参数时强类型化一下试试,或者直接强类型化circleObj
由于是后期绑定,没法强类型化啊! Real_King 发表于 2016-4-6 15:35 static/image/common/back.gif
把你的circleObj在作为参数时强类型化一下试试,或者直接强类型化circleObj
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 System.Runtime.InteropServices;
using System.Reflection;
using stdole;
namespace TlsCad.RunTime
{
public partial class Form1 : Form
{
public Form1()
{
//获取当前AutoCad实例
string pid = "AutoCad.Application";
dynamic app;
try
{
app = Marshal.GetActiveObject(pid);
}
catch
{
//如果没有就创建之
Type t = Type.GetTypeFromProgID(pid);
app = Activator.CreateInstance(t);
app.Visible = true;
}
//获取当前文档
dynamic doc = app.ActiveDocument;
double[] p1 = { 0, 0, 0 };
double[] p2 = { 0, 10, 0 };
double[] p3 = { 10, 10, 0 };
double[] p4 = { 10, 0, 0 };
//Com对象数组必须封装为IDispatch数组
//注意应引用stdole.dll
IDispatch[] ents =
{
doc.ModelSpace.AddLine(p1, p2),
doc.ModelSpace.AddLine(p2, p3),
doc.ModelSpace.AddLine(p3, p4),
doc.ModelSpace.AddLine(p4, p1)
};
//测试生成面域
dynamic r = doc.ModelSpace.AddRegion(ents);
double[] min, max;
r.GetBoundingBox(out min, out max);
app.ZoomWindow(min, max);
InitializeComponent();
}
}
}
这是 雪山飞狐_lzh 通过后期绑定生成面域的程序,但是我执行的时候,只是画了一个正方形,并没有成功创建一个面域,请问是什么原因呢? SurveyCAD 发表于 2016-4-7 09:59 static/image/common/back.gif
using System;
using System.Collections.Generic;
using System.ComponentModel;
经测试是可以的,你再检查下代码。 xiaodoo 发表于 2016-4-23 16:12 static/image/common/back.gif
经测试是可以的,你再检查下代码。
已经成功了,多谢
页:
[1]