我正在创建一个应用程序,它可以打开一个绘图,自动将标记添加到标题栏。一切都很好,直到它开始透过物体看。我得到“无法获取文档对象”,我还使用公共和互操作导入。这就是问题所在。它开始搜索对象,然后失败。我还想知道是否有办法限制搜索,因为我只关心块。
- For Each MyObj In MyDwgDoc.ModelSpace
- booMfgTag = False
- '** Find all Titleblocks
- If MyObj.ObjectName = "AcDbBlockReference" Then
- If MyObj.Name = "MSP-B-BORDER" Then
- XOffset = (12 + 47 / 64) - 1.875
- DScale = 1.0#
- booMfgTag = True
- ElseIf MyObj.Name = "MSP-D-BORDER" Then
- XOffset = (24 + 29 / 32) - 3.75
- DScale = 2.0#
- booMfgTag = True
- ElseIf MyObj.Name = "B-BORDER" Then
- XOffset = (12 + 47 / 64) - 1.875
- DScale = 1.0#
- booMfgTag = True
- ElseIf MyObj.Name = "D-BORDER" Then
- XOffset = (24 + 29 / 32) - 3.75
- DScale = 2.0#
- booMfgTag = True
- ElseIf MyObj.Name = "BLOCK1" Then
- XOffset = (24 + 29 / 32) - 3.75
- DScale = 2.0#
- booMfgTag = True
- End If
- If booMfgTag Then
- TBInsrtPt = MyObj.InsertionPoint
- '** Set-up and insert MfgTag
- InsertPnt(0) = TBInsrtPt(0) + XOffset * MyObj.XScaleFactor
- InsertPnt(1) = TBInsrtPt(1)
- InsertPnt(2) = TBInsrtPt(2)
- MTObj = MyDwgDoc.ModelSpace.InsertBlock(InsertPnt, strBlock, _
- MyObj.XScaleFactor * DScale, MyObj.YScaleFactor * DScale, MyObj.ZScaleFactor * DScale, 0.0#)
- '** Change the attributes of the new block
- RetVal = MTObj.GetAttributes
- If IsDBNull(DataGridView3.Rows(ridx).Cells(4).Value) Then
- DataGridView3.Rows(ridx).Cells(4).Value = " "
- End If
- If IsDBNull(DataGridView3.Rows(ridx).Cells(5).Value) Then
- DataGridView3.Rows(ridx).Cells(5).Value = " "
- End If
- If IsDBNull(DataGridView3.Rows(ridx).Cells(6).Value) Then
- DataGridView3.Rows(ridx).Cells(6).Value = " "
- End If
- If IsDBNull(DataGridView3.Rows(ridx).Cells(7).Value) Then
- DataGridView3.Rows(ridx).Cells(7).Value = " "
- End If
- For intI = LBound(RetVal) To UBound(RetVal)
- If RetVal(intI).TagString = "CSJOB" Then RetVal(intI).TextString = DataGridView3.Rows(ridx).Cells(3).Value
- If RetVal(intI).TagString = "LOCATION" Then RetVal(intI).TextString = DataGridView3.Rows(ridx).Cells(4).Value
- If RetVal(intI).TagString = "DESCRIPTION" Then RetVal(intI).TextString = DataGridView3.Rows(ridx).Cells(5).Value
- If RetVal(intI).TagString = "RESPONSIBLE1" Then RetVal(intI).TextString = DataGridView3.Rows(ridx).Cells(6).Value
- If RetVal(intI).TagString = "RESPONSIBLE2" Then RetVal(intI).TextString = DataGridView3.Rows(ridx).Cells(7).Value
- If RetVal(intI).TagString = "QTY" Then RetVal(intI).TextString = DataGridView3.Rows(ridx).Cells(1).Value
- Next intI
- booChange = True
- End If
- End If
- Next
|