admin 发表于 2024-3-14 19:39:08

[每日一码] 打印AcDbLineTypeTableRecord线型定义引用的SHX文件名

static void ASDKwbTEST(void)
{
   AcDbDatabase* pDb = curDoc()->database();
assert(pDb);
//get line type table
AcDbLinetypeTable *pLTTable ;
acdbOpenObject(pLTTable,pDb->linetypeTableId(),AcDb::kForRead);

AcDbLinetypeTableRecord *pLTRecord = NULL ;

AcDbObjectId objLTId ;
//pLTTable->getAt(采用T("TRACKS"), objLTId) ;
pLTTable->getAt(采用T("ZIGZAG"), objLTId) ;

pLTTable->close();
Acad::ErrorStatus es = acdbOpenObject((AcDbObject *&)pLTRecord, objLTId, AcDb::kForRead) ;
if(es != Acad::eOk)
{
   acutPrintf(采用T("ZIGZAG linetype not loaded"));
      return;
}
         //iterate through the linetype
int dashes = pLTRecord->numDashes();
for(int c = 0; c < dashes; c++)
{
   int shpnum = pLTRecord->shapeNumberAt(c) ;
   if(shpnum != 0)
   {
   AcDbTextStyleTableRecord *pTSRecord = NULL ;
   AcDbObjectId objTSId = pLTRecord->shapeStyleAt(c);
   pLTRecord->close();

   acdbOpenObject((AcDbObject*&)pTSRecord,objTSId,AcDb::kForRead);
   assert(pTSRecord);

   const ACHAR *pName ;
   Acad::ErrorStatus es = pTSRecord->fileName(pName);
   pTSRecord->close();
   acutPrintf(采用T("\nName of shape file = %s"),pName);
   }
}
}

admin 发表于 2024-3-14 19:39:31

Here is a VB.NET example:<CommandMethod("getShpName")> 采用
    Public Sub GetShapeName()
      Dim LtypeNames As New ArrayList()
      Dim TextStyleNames As New ArrayList()
      Dim db As Database = HostApplicationServices.WorkingDatabase()
      Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
      Dim tm As Transaction = db.TransactionManager.StartTransaction()
      Try

            Dim lineTypTbl As LinetypeTable = tm.GetObject(db.LinetypeTableId, OpenMode.ForRead)
            Dim ltTblRec As LinetypeTableRecord
            Dim txtStyleTblRec As TextStyleTableRecord


            ltTblRec = tm.GetObject(lineTypTbl("ZigZag"), OpenMode.ForRead)


            'iterate through the linetype
            Dim intDashes As Integer = ltTblRec.NumDashes
            Dim i As Integer
            Dim iShpNum As Integer


            For i = 0 To intDashes - 1
                iShpNum = ltTblRec.ShapeNumberAt(i)
                If iShpNum <> 0 Then
                  Dim txtStylTblRecObjId As ObjectId = ltTblRec.ShapeStyleAt(i)
                  txtStyleTblRec = tm.GetObject(txtStylTblRecObjId, OpenMode.ForRead)
                  ed.WriteMessage("Name of" & txtStyleTblRec.FileName.ToString() & vbCrLf)
                End If
            Next


            tm.Commit()
      Catch ex As System.Exception
            ed.WriteMessage(ex.ToString())


      Finally
            tm.Dispose()
      End Try
    End Sub
页: [1]
查看完整版本: [每日一码] 打印AcDbLineTypeTableRecord线型定义引用的SHX文件名