C#net应用程序与au交互
嘿我一直在开发一个应用程序,要求用户提供将插入autocad块的信息。
到目前为止,我已经成功地打开了autocad,提取了坐标,并用我需要的属性创建了一个块。
但问题是我需要使用一个自定义块(在dwg文件中),我不知道如何将其添加到数据库,添加我需要的属性,并将其放置在图形上。下面是一些代码,试图更好地解释。
public void insert()
{
object p;
app = OpenApp();
app.Visible = true;
AcadBlock block = null;
p = app.ActiveDocument.Utility.GetPoint(System.Type.Missing, "Base point:");
block = app.ActiveDocument.Blocks.Add(p, "TEST");
block.AddAttribute(1.0, AcAttributeMode.acAttributeModeNormal, "TEST", p, "test tag", "test value");
block.AddAttribute(1.0, AcAttributeMode.acAttributeModeNormal, "1", p, "1", "1r");
block.AddAttribute(1.0, AcAttributeMode.acAttributeModeNormal, "2", p, "2", "2");
block.AddAttribute(1.0, AcAttributeMode.acAttributeModeNormal, "3", p, "3", "3");
app.ActiveDocument.Database.ModelSpace.AddMInsertBlock(p, "TEST", 1.0, 1.0,1.0, 0.0, 1, 1, 1, 1, System.Type.Missing);
我两周前才开始为autocad开发,如果有人能帮忙的话。
提前感谢 我几乎已经弄明白了。
现在缺少的部分是如何转换(强制转换)系统。对象[]到Autodesk。Autocad。互操作。科罗姆。属性[]。
在下面的代码中,我在图形上插入块,然后尝试更改其属性,然后更新块。但是
bl.GetAttributes(); 返回一个对象[],而不是一个属性[]。
bl = app.ActiveDocument.ModelSpace.InsertBlock(p, "CARIMBO-DTE", 1.0, 1.0, 1.0, 1.0, System.Type.Missing);
AcadAttribute[] att;
object[] atr;
att = bl.GetAttributes();
//AcadAttribute[] atr;
//atr = att;
//att = (Autodesk.AutoCAD.Interop.Common.AcadAttribute[])atr ;
for (int i = 0; i < att.Length; i++)
{
if (att.TagString == "IDEDIFICIO")
{
att.TextString = "TESTE";
}
//if ((Autodesk.AutoCAD.Interop.Common.AcadAttribute[])att.TagString == "IDEDIFICIO")
//{
// (Autodesk.AutoCAD.Interop.Common.AcadAttribute[])att.TextString = "TESTE";
//}
}
bl.Update();
我就快到了,有人想知道吗? 我已经弄明白了。
反正是thx!
很抱歉之前没有看到这个。。。您可以发布您的解决方案,以便其他有相同问题的人可以获得帮助。 你好没关系。
在c语言中,我在转换系统时遇到了麻烦__ComObject to AcadAttribute尝试了几件事,但都没有成功。
所以我不得不走另一条路。
我在Autocad中创建了一个宏,从文件中读取,然后将块放置在图形上,并用属性填充。现在在c语言中,我只需要调用runMacro命令。
app = openApp();
app.Visible = true;
app.RunMacro("readInfo");
这不是一个很好的选择,因为你必须为你想要放置的每个块创建一个文件,然后删除它,但现在它必须工作。
这是密码
Sub insert(ByVal id As String, ByVal res As String)
Dim BlockRefObj As AcadBlockReference
Set BlockRefObj = ThisDrawing.ModelSpace.InsertBlock(ThisDrawing.Utility.GetPoint(, "Pick location:"), "BLOCK NAME", 1#, 1#, 1#, 0)
Dim Attributes
Dim i As Integer
i = 0
Attributes = BlockRefObj.GetAttributes
For i = LBound(Attributes) To UBound(Attributes)
If Attributes(i).TagString = "ID" Then
Attributes(i).TextString = id
End If
If Attributes(i).TagString = "RES" Then
Attributes(i).TextString = res
End If
Next i
BlockRefObj.Update
Set BlockRefObj = Nothing
End Sub
Sub readInfo()
Const ForReading = 1, ForWriting = 2, ForAppending = 8, TristateFalse = 0
Dim fs, f
Dim id As String
Dim res As String
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile("c:\1.tmp", ForReading, TristateFalse)
Do While f.AtEndOfStream <> True
id = f.ReadLine
res = f.ReadLine
Loop
Call insert(id, res)
f.Close
End Sub
如果有人知道如何只用c语言实现这一点,我将非常感激。 这些链接可能很有用:
http://forums.autodesk.com/t5/NET/c-block-insert/td-p/1744533/page/2
http://forums.autodesk.com/t5/NET/Discussion-Group-ClassLibrary-please-read/td-p/3005908 谢谢。
我一直有麻烦,这些dll
acdmgd
admgd公司
我猜他们是用在第一个拳头环节。
我不知道他们为什么在运行时抛出异常:S 你使用的参考文献是否正确。。。?
ObjectARX SDK包括AcDbMgd。dll和AcMgd。dll(等等)。 我想是的。但我会试试的。谢谢
页:
[1]