eID ="ObjectDBX.AxDbDocument.17";
AutoCAD.AcadApplication AcadApp = Connector.Application;
dbx.AxDbDocument dbxDoc;
dbxDoc=(dbx.AxDbDocument)AcadApp.GetInterfaceObject(programeID);
try
{
if (System.IO.File.Exists (FileName)==false) throw new Exception ("文件不存在。");
dbxDoc.Open(FileName,PassWord);
}// end of try
catch (Exception e)
{
System.Windows.Forms.MessageBox.Show(e.Message );
dbxDoc=null;
}
return dbxDoc;
}//end of function GetThisDrawing
///
/// 根据当前文档和块名取得当前块的引用
///
public dbx.AcadBlockReference GetBlockReference(dbx.AxDbDocument thisDrawing,string blkName)
{
dbx.AcadBlockReference blkRef=null;
bool found = false;
try
{
foreach (dbx.AcadEntity entity in thisDrawing.ModelSpace )
{
if (entity.EntityName=="AcDbBlockReference")
{
blkRef=(dbx.AcadBlockReference)entity;
//System.Windows.Forms.MessageBox.Show(blkRef.Name);
if (blkRef.Name.ToLower() ==blkName.ToLower() )
{
found = true;
break;
}
}//end of entity.EntityName=="AcDbBlockReference"
}// end of foreach thisDrawing.ModelSpace
}//end of try
catch (Exception e)
{
System.Windows.Forms.MessageBox.Show ("图形中有未知的错误,格式不正确或图形数据库需要修愎。系统错误提示:" + e.Message ,"信息",System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
thisDrawing=null;
}//end of catch
if (!found) blkRef = null;
return blkRef;
}//end of function GetBlockReference
///
/// 根据给定的块引用(dbx.AcadBlockReference)和属性名返回属性值
///
public object GetValueByAttributeName(dbx.AcadBlockReference blkRef,string AttributeName)
{
object Atts=(object)blkRef.GetAttributes();
object attValue=null;
for (int i=0;i
{
dbx.AcadAttributeReference attRef;
attRef=(dbx.AcadAttributeReference)Atts[i];
if (attRef.TagString==AttributeName)
{
attValue= attRef.TextString ;
break;
}
}//end of for i
return attValue;
}// end of function
#endregion
}//end of cla