获取块参照内的多行文字
大家好;我需要搜索块参考中的所有多行文字。
我为此付出了努力,但没有结果。
请帮忙,这对我很有必要。
提前谢谢。 你好
你在DotNet论坛上发布了你的请求。。。我只能用Lisp解决方案来帮助您。
给你:
(defun c:FindMT()
(setq bl (tblnext "BLOCK" 1))
(while bl
(setq name (cdr (assoc 2 bl)) mt nil)
(princ (strcat "\n\n == Block: " name " =="))
(setq ent(tblobjname "BLOCK" name))
(while ent
(setq ent (entnext ent))
(if ent
(progn (setq el (entget ent))
(if (= "MTEXT" (cdr (assoc 0 el)))
(progn
(setq mt 1)
(princ (strcat "\n" (cdr (assoc 1 el))))
)
)
)
)
)
(if (not mt) (princ " >> no MTEXT"))
(setq bl (tblnext "BLOCK"))
)
(princ)
)
BlockReference只是其父块定义(也称为BlockTableRecord)的图形表示。
这应该让你开始(C#):
//
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using acApp = Autodesk.AutoCAD.ApplicationServices.Application;
namespace FOO
{
public class Commands
{
private static DocumentCollection acDocs = acApp.DocumentManager;
public void FOO()
{
Document doc = acDocs.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
SelectionFilter sf = new SelectionFilter(
new TypedValue { new TypedValue(0, "INSERT") });
PromptSelectionOptions pso = new PromptSelectionOptions();
pso.MessageForAdding = "Select block references:";
PromptSelectionResult psr = ed.GetSelection(pso, sf);
if (psr.Status != PromptStatus.OK)
{
ed.WriteMessage("\n** Nothing selected ** \n");
return;
}
dynamic acDoc = doc.GetAcadDocument();
acDoc.StartUndoMark();
using (Transaction tr = db.TransactionManager.StartOpenCloseTransaction())
{
ObjectIdCollection ids = new ObjectIdCollection();
foreach (ObjectId id in psr.Value.GetObjectIds())
{
BlockReference br = (BlockReference)tr.GetObject(id, OpenMode.ForRead);
ObjectId btrId = br.BlockTableRecord;
if (!ids.Contains(btrId))
{
ids.Add(btrId);
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(btrId, OpenMode.ForWrite);
foreach (ObjectId bid in btr)
{
MText mtext = tr.GetObject(bid, OpenMode.ForRead) as MText;
if (mtext != null)
{
mtext.UpgradeOpen();
mtext.ColorIndex = 1;
mtext.DowngradeOpen();
}
}
}
}
tr.Commit();
}
ed.Regen();
acDoc.EndUndoMark();
}
}
}
嗨fuccaro
非常感谢您的帮助,我对lisp一无所知,所以我尝试将您的代码转换为。net代码,但我没有找到任何转换器这样做。
太谢谢你了。 嗨,黑匣子
谢谢你的帮助。
我会尝试你的代码并反馈。
谢谢 无需转换。查看此旧链接:
http://www.cadtutor.net/forum/showthread.php?1390-如何在此存档中使用LISP例程
只需遵循CADTutor在该帖子第一篇文章中的说明。祝你好运 嗨,黑匣子
我测试了你的代码,效果很好。
它发现(多行文字)是(BlockReference)的(组件)之一还是否。
但是我需要搜索块引用中的多行文字
换句话说,在我的例子中,块引用是(容器)或(区域)或(区域),多行文字在其中。
请帮忙。
非常感谢。 听起来您正试图在模型空间中找到一个多行文字实体,该实体的几何延伸(或可能只是插入点)位于块引用的几何延伸内。
发布包含与您尝试处理的一般场景相同的示例图形文件可能会有所帮助。 谢谢你,fuccaro,我会这样做的。 嗨SEANT
谢谢你的帮助
我正在编写两段不同的代码
第一个是找到多边形内的点,它工作正常,我试图转换代码以达到我的需要,但我直到现在都失败了
<CommandMethod("TEST")> _
Public Sub Test()
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
Dim peo As New PromptEntityOptions(vbLf & "Select a polyline: ")
peo.SetRejectMessage("Only a polyline !")
peo.AddAllowedClass(GetType(Polyline), True)
Dim per As PromptEntityResult = ed.GetEntity(peo)
If per.Status <> PromptStatus.OK Then
Return
End If
Using tr As Transaction = db.TransactionManager.StartOpenCloseTransaction()
Dim pline As Polyline = DirectCast(tr.GetObject(per.ObjectId, OpenMode.ForRead), Polyline)
If Not pline.Closed Then
ed.WriteMessage(vbLf & "Polyline must be closed.")
Return
End If
Dim curves As New DBObjectCollection()
curves.Add(pline)
Try
Using regions As DBObjectCollection = Region.CreateFromCurves(curves)
Using region__1 As Region = DirectCast(regions(0), Region)
Dim ppo As New PromptPointOptions(vbLf & "Pick a point <quit>: ")
ppo.AllowNone = True
While True
Dim ppr As PromptPointResult = ed.GetPoint(ppo)
If ppr.Status <> PromptStatus.OK Then
Exit While
End If
Application.ShowAlertDialog(GetPointContainment(region__1, ppr.Value).ToString())
End While
End Using
End Using
Catch exn As System.Exception
ed.WriteMessage(vbLf & "Error: " & exn.Message)
End Try
End Using
End Sub
Private Function GetPointContainment(region As Region, point As Point3d) As PointContainment
Dim result As PointContainment = PointContainment.Outside
Using brep As New Brep(region)
If brep IsNot Nothing Then
Using ent As BrepEntity = brep.GetPointContainment(point, result)
If TypeOf ent Is Autodesk.AutoCAD.BoundaryRepresentation.Face Then
result = PointContainment.Inside
End If
End Using
End If
End Using
Return result
End Function
页:
[1]
2