计数块
你好我需要在多个关卡数块,我可以用5个关卡。
也许有人可以帮忙,有什么建议吗?
顺致敬意,
<Autodesk.AutoCAD.Runtime.CommandMethod("Bcount")>
Public Sub Blockcount()
Dim myExcel As Object = CreateObject("Excel.Application")
myExcel.Visible = True
Dim myWB As Object = myExcel.Workbooks.Add
Dim myDesktop As String = My.Computer.FileSystem.SpecialDirectories.Desktop
Dim curRow As Integer = 1
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
Using trx As Transaction = db.TransactionManager.StartTransaction()
Dim bt As BlockTable = trx.GetObject(db.BlockTableId, OpenMode.ForRead)
For Each btrId As ObjectId In bt
Dim btr As BlockTableRecord = trx.GetObject(btrId, OpenMode.ForRead)
Dim refIds As ObjectIdCollection = btr.GetBlockReferenceIds(False, False)
If btr.Name.Contains("Y") Then
If Not btr.IsLayout Then
myExcel.ActiveSheet.Cells(curRow, "F").value = refIds.Count.ToString
myExcel.ActiveSheet.Cells(curRow, "A").value = DateTime.Now.ToString
myExcel.ActiveSheet.Cells(curRow, "B").value = doc.Window.Text
myExcel.ActiveSheet.Cells(curRow, "C").value = "Price"
myExcel.ActiveSheet.Cells(curRow, "D").value = btr.Name
myExcel.ActiveSheet.Cells(curRow, "E").value = btr.Comments
curRow += 1
End If
End If
Next
db.Dispose()
End Using
myWB.SaveAs(IO.Path.Combine(myDesktop, "Furnitura.xlsx"))
myWB = Nothing
myExcel = Nothing
End Sub 你好,我想你的意思是“水平”层?关于上述代码,它不是VBA?似乎是其他语言,这是必须的?相反,我可以建议您使用VBA程序。 你好
我已经在块中的块中创建了块。。。并且需要计算所有同名的块。我可以计算图形中的对象或图形中的块引用,但只能计算一个级别。
例如,我添加了一个dwg。
我明白,你是说嵌套块。这是一个lsp程序,它在命令输入栏上显示不同的块名,我对lsp不是很在行,但我试过了,它成功了。
请参见https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/report-number-of-nested-blocks/m-p/6340079/highlight/true#M341484
我会尝试更多的VBA,但我从来没有过类似的问题。 它不起作用,只计算顶层块的总数量。我添加示例。xlsx。。我需要什么 抱歉,这是我的结果,我知道lsp例程不算,但你可以修改并适应你的使用。
((“YFE-0079689”“YFSK3.5-35”)(“Feet\u 50”“YFE-0044747”“YFE-0079689”“URB\u 15x13”))
这是嵌套块Feet_50的屏幕截图,并且是相同的,不仅是第一级,而且是嵌套的
该代码应该有效,
不幸的是,为了正确计数,您必须检查名称并进行计数,或者作为替代计数,计算将找到多少次相同的名称。
图纸上的结果应为:
YFE-0044747 6 YFE-0079689 6 YFSK3.5-35 18 URB_15x13 12
与参考图片完全相同,仅显示1个块(总计乘以6)。
当然,excel部分缺失了,但你应该知道如何修复它。
页:
[1]