乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 141|回复: 13

[编程交流] 获取块参照内的多行文字

[复制链接]

1

主题

11

帖子

10

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 22:03:56 | 显示全部楼层 |阅读模式
大家好;
 
我需要搜索块参考中的所有多行文字。
 
我为此付出了努力,但没有结果。
 
请帮忙,这对我很有必要。
 
提前谢谢。
回复

使用道具 举报

18

主题

434

帖子

422

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
94
发表于 2022-7-6 22:11:21 | 显示全部楼层
你好
你在DotNet论坛上发布了你的请求。。。我只能用Lisp解决方案来帮助您。
给你:
  1. (defun c:FindMT()
  2. (setq bl (tblnext "BLOCK" 1))
  3. (while bl
  4.    (setq name (cdr (assoc 2 bl)) mt nil)
  5.    (princ (strcat "\n\n == Block: " name " =="))
  6.    (setq ent  (tblobjname "BLOCK" name))
  7.    (while ent
  8.         (setq ent (entnext ent))
  9.          (if ent
  10.      (progn (setq el (entget ent))
  11.            (if (= "MTEXT" (cdr (assoc 0 el)))
  12.          (progn
  13.            (setq mt 1)
  14.            (princ (strcat "\n" (cdr (assoc 1 el))))
  15.            )
  16.          )
  17.        )
  18.      )
  19.      )
  20.    (if (not mt) (princ " >> no MTEXT"))
  21.    (setq bl (tblnext "BLOCK"))
  22.    )
  23. (princ)
  24. )
回复

使用道具 举报

44

主题

3166

帖子

2803

银币

中流砥柱

Rank: 25

铜币
557
发表于 2022-7-6 22:14:12 | 显示全部楼层
 
BlockReference只是其父块定义(也称为BlockTableRecord)的图形表示。
 
这应该让你开始(C#):
 
  1. //
  2. using Autodesk.AutoCAD.ApplicationServices;
  3. using Autodesk.AutoCAD.DatabaseServices;
  4. using Autodesk.AutoCAD.EditorInput;
  5. using Autodesk.AutoCAD.Runtime;
  6. using acApp = Autodesk.AutoCAD.ApplicationServices.Application;
  7. [assembly: CommandClass(typeof(FOO.Commands))]
  8. namespace FOO
  9. {
  10.    public class Commands
  11.    {
  12.        private static DocumentCollection acDocs = acApp.DocumentManager;
  13.        [CommandMethod("FOO")]
  14.        public void FOO()
  15.        {
  16.            Document doc = acDocs.MdiActiveDocument;
  17.            Database db = doc.Database;
  18.            Editor ed = doc.Editor;
  19.            SelectionFilter sf = new SelectionFilter(
  20.                    new TypedValue[1] { new TypedValue(0, "INSERT") });
  21.            PromptSelectionOptions pso = new PromptSelectionOptions();
  22.            pso.MessageForAdding = "Select block references:";
  23.            PromptSelectionResult psr = ed.GetSelection(pso, sf);
  24.            if (psr.Status != PromptStatus.OK)
  25.            {
  26.                ed.WriteMessage("\n** Nothing selected ** \n");
  27.                return;
  28.            }
  29.            dynamic acDoc = doc.GetAcadDocument();
  30.            acDoc.StartUndoMark();
  31.            using (Transaction tr = db.TransactionManager.StartOpenCloseTransaction())
  32.            {
  33.                ObjectIdCollection ids = new ObjectIdCollection();
  34.                foreach (ObjectId id in psr.Value.GetObjectIds())
  35.                {
  36.                    BlockReference br = (BlockReference)tr.GetObject(id, OpenMode.ForRead);
  37.                    ObjectId btrId = br.BlockTableRecord;
  38.                    if (!ids.Contains(btrId))
  39.                    {
  40.                        ids.Add(btrId);
  41.                        BlockTableRecord btr = (BlockTableRecord)tr.GetObject(btrId, OpenMode.ForWrite);
  42.                        foreach (ObjectId bid in btr)
  43.                        {
  44.                            MText mtext = tr.GetObject(bid, OpenMode.ForRead) as MText;
  45.                            if (mtext != null)
  46.                            {
  47.                                mtext.UpgradeOpen();
  48.                                mtext.ColorIndex = 1;
  49.                                mtext.DowngradeOpen();
  50.                            }
  51.                        }
  52.                    }
  53.                }
  54.                tr.Commit();
  55.            }
  56.            ed.Regen();
  57.            acDoc.EndUndoMark();
  58.        }
  59.    }
  60. }
回复

使用道具 举报

1

主题

11

帖子

10

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 22:19:46 | 显示全部楼层
嗨fuccaro
 
非常感谢您的帮助,我对lisp一无所知,所以我尝试将您的代码转换为。net代码,但我没有找到任何转换器这样做。
 
太谢谢你了。
回复

使用道具 举报

1

主题

11

帖子

10

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 22:25:00 | 显示全部楼层
嗨,黑匣子
 
谢谢你的帮助。
我会尝试你的代码并反馈。
 
谢谢
回复

使用道具 举报

18

主题

434

帖子

422

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
94
发表于 2022-7-6 22:29:24 | 显示全部楼层
无需转换。查看此旧链接:
http://www.cadtutor.net/forum/showthread.php?1390-如何在此存档中使用LISP例程
只需遵循CADTutor在该帖子第一篇文章中的说明。祝你好运
回复

使用道具 举报

1

主题

11

帖子

10

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 22:34:32 | 显示全部楼层
嗨,黑匣子
 
我测试了你的代码,效果很好。
它发现(多行文字)是(BlockReference)的(组件)之一还是否。
 
但是我需要搜索块引用中的多行文字
换句话说,在我的例子中,块引用是(容器)或(区域)或(区域),多行文字在其中。
 
请帮忙。
 
非常感谢。
回复

使用道具 举报

10

主题

973

帖子

909

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
118
发表于 2022-7-6 22:39:51 | 显示全部楼层
听起来您正试图在模型空间中找到一个多行文字实体,该实体的几何延伸(或可能只是插入点)位于块引用的几何延伸内。
 
发布包含与您尝试处理的一般场景相同的示例图形文件可能会有所帮助。
回复

使用道具 举报

1

主题

11

帖子

10

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 22:44:46 | 显示全部楼层
谢谢你,fuccaro,我会这样做的。
回复

使用道具 举报

1

主题

11

帖子

10

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 22:46:22 | 显示全部楼层
嗨SEANT
谢谢你的帮助
我正在编写两段不同的代码
 
第一个是找到多边形内的点,它工作正常,我试图转换代码以达到我的需要,但我直到现在都失败了
 
  1. <CommandMethod("TEST")> _
  2. Public Sub Test()
  3.    Dim doc As Document = Application.DocumentManager.MdiActiveDocument
  4.    Dim db As Database = doc.Database
  5.    Dim ed As Editor = doc.Editor
  6.    Dim peo As New PromptEntityOptions(vbLf & "Select a polyline: ")
  7.    peo.SetRejectMessage("Only a polyline !")
  8.    peo.AddAllowedClass(GetType(Polyline), True)
  9.    Dim per As PromptEntityResult = ed.GetEntity(peo)
  10.    If per.Status <> PromptStatus.OK Then
  11.        Return
  12.    End If
  13.    Using tr As Transaction = db.TransactionManager.StartOpenCloseTransaction()
  14.        Dim pline As Polyline = DirectCast(tr.GetObject(per.ObjectId, OpenMode.ForRead), Polyline)
  15.        If Not pline.Closed Then
  16.            ed.WriteMessage(vbLf & "Polyline must be closed.")
  17.            Return
  18.        End If
  19.        Dim curves As New DBObjectCollection()
  20.        curves.Add(pline)
  21.        Try
  22.            Using regions As DBObjectCollection = Region.CreateFromCurves(curves)
  23.                Using region__1 As Region = DirectCast(regions(0), Region)
  24.                    Dim ppo As New PromptPointOptions(vbLf & "Pick a point <quit>: ")
  25.                    ppo.AllowNone = True
  26.                    While True
  27.                        Dim ppr As PromptPointResult = ed.GetPoint(ppo)
  28.                        If ppr.Status <> PromptStatus.OK Then
  29.                            Exit While
  30.                        End If
  31.                        Application.ShowAlertDialog(GetPointContainment(region__1, ppr.Value).ToString())
  32.                    End While
  33.                End Using
  34.            End Using
  35.        Catch exn As System.Exception
  36.            ed.WriteMessage(vbLf & "Error: " & exn.Message)
  37.        End Try
  38.    End Using
  39. End Sub
  40. Private Function GetPointContainment(region As Region, point As Point3d) As PointContainment
  41.    Dim result As PointContainment = PointContainment.Outside
  42.    Using brep As New Brep(region)
  43.        If brep IsNot Nothing Then
  44.            Using ent As BrepEntity = brep.GetPointContainment(point, result)
  45.                If TypeOf ent Is Autodesk.AutoCAD.BoundaryRepresentation.Face Then
  46.                    result = PointContainment.Inside
  47.                End If
  48.            End Using
  49.        End If
  50.    End Using
  51.    Return result
  52. End Function
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-4 08:32 , Processed in 0.970653 second(s), 72 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表