|
问题:
I need to find a compiled shape file (shx) used by an AcDbLinetypeTableRecord class. How can I determine what shape a linetype uses?
解决方案:
If a line type uses a shx file it will reference an AcDbTextStyleTableRecord. Here is an example that prints the names of the shx file used by the ZIGZAG linetype in acad.lin.
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);
}
}
}
下面是.net实现代码:
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 |
|