king-hack 发表于 2009-5-22 19:03:00

(求救mccad)vb6可以调用ObjectDbx技术吗?

<p>求救</p><p></p><p>vb6可以调用ObjectDbx技术实现不打开图纸进行文字查找替换吗?</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 先谢了!</p>

king-hack 发表于 2009-5-22 21:00:00

<p>这是源代码,希望mccad及高手修改下!!!</p><p></p><p></p><p>Option Explicit</p><p>Dim objDBX As Object </p><p>Private Sub Form_Activate()<br/>If Left(Version, 2) = "15" Then<br/>&nbsp;&nbsp;&nbsp; Set objDBX = CreateObject("ObjectDBX.AxDbDocument.1")<br/>End If<br/>End Sub</p><p>Private Sub Command1_Click()<br/><br/>If ListView1.ListItems.Count = 0 Then<br/>&nbsp; MsgBox "请先选择图纸!"<br/>&nbsp;Exit Sub<br/>&nbsp;<br/>Else<br/>&nbsp;&nbsp;&nbsp; Dim adText As AcadText<br/>&nbsp;&nbsp;&nbsp; Dim adMText As AcadMText<br/>&nbsp;&nbsp;&nbsp; Dim adSS As AcadSelectionSet<br/>&nbsp;&nbsp;&nbsp; Dim fType(0 To 1) As Integer, fData(0 To 1)<br/>&nbsp;&nbsp;&nbsp; Dim i As Integer</p><p>&nbsp;&nbsp;&nbsp; If txtfind.Text = "" Or txtreplace.Text = "" Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox "输入所要替换的字符串内容!"<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Sub<br/>&nbsp;&nbsp;&nbsp; End If<br/><br/>&nbsp;&nbsp;&nbsp; Dim strFind As String<br/>&nbsp;&nbsp;&nbsp; Dim strReplace As String<br/>&nbsp;&nbsp;&nbsp; strFind = txtfind.Text<br/>&nbsp;&nbsp;&nbsp; strReplace = txtreplace.Text</p><p>&nbsp;&nbsp;&nbsp; ' 打开图形进行操作<br/>For i = 1 To Form1.ListView1.ListItems.Count + 1<br/>Call ReplaceTextInDwg(Form1.ListView1.ListItems(i).SubItems(1) &amp; "\" &amp; ListView1.ListItems.Item(i), strFind,strReplace)<br/>&nbsp;&nbsp;&nbsp; Next i<br/>End If<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;MsgBox "OK!&nbsp; ^_^"<br/>End Sub</p><p>' 对某个图形进行文字替换<br/>Private Sub ReplaceTextInDwg(ByVal strDwgName As String, ByVal strFind As String, _<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ByVal strReplace As String)<br/>&nbsp;&nbsp;&nbsp; ' 打开指定的图形<br/>objDBX.Open strDwgName</p><p>&nbsp;&nbsp;&nbsp; Dim ent As AcadEntity<br/>&nbsp;&nbsp;&nbsp; For Each ent In objDBX.ModelSpace<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If TypeOf ent Is AcadText Or TypeOf ent Is AcadMText Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; With ent<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If InStr(.TextString, strFind) Then .TextString = ReplaceStr(.TextString, strFind, strReplace, False)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End With<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp; Next ent<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; objDBX.SaveAs strDwgName<br/>End Sub</p><p>' 对字符串中指定的字符进行替换<br/>Public Function ReplaceStr(ByVal searchStr As String, ByVal oldStr As String, _<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ByVal newStr As String, ByVal firstOnly As Boolean) As String<br/>&nbsp;&nbsp;&nbsp; '对错误操作的处理<br/>&nbsp;&nbsp;&nbsp; If searchStr = "" Then Exit Function<br/>&nbsp;&nbsp;&nbsp; If oldStr = "" Then Exit Function</p><p>&nbsp;&nbsp;&nbsp; ReplaceStr = ""<br/>&nbsp;&nbsp;&nbsp; Dim i As Integer, oldStrLen As Integer, holdStr As String, StrLoc As Integer<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; '计算原来字符串的长度<br/>&nbsp;&nbsp;&nbsp; oldStrLen = Len(oldStr)<br/>&nbsp;&nbsp;&nbsp; StrLoc = InStr(searchStr, oldStr)<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; While StrLoc &gt; 0<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '获得图形中文字对象位于查找字符串之前的字符串<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; holdStr = holdStr &amp; Left(searchStr, StrLoc - 1) &amp; newStr<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '获得文字对象位于查找字符串之后的字符串<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; searchStr = Mid(searchStr, StrLoc + oldStrLen)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; StrLoc = InStr(searchStr, oldStr)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If firstOnly Then ReplaceStr = holdStr &amp; searchStr: Exit Function<br/>&nbsp;&nbsp;&nbsp; Wend<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ReplaceStr = holdStr &amp; searchStr<br/>End Function</p><p></p><p>' 列表框中是否存在指定名称的项目<br/>Private Function HasItem(ByVal strDwgName As String) As Boolean<br/>&nbsp;&nbsp;&nbsp; HasItem = False<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; Dim i As Integer<br/>&nbsp;&nbsp;&nbsp; For i = 1 To Form1.ListView1.ListItems.Count + 1<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If StrComp(Form1.ListView1.ListItems(i).SubItems(1) &amp; "\" &amp; ListView1.ListItems.Item(i), strDwgName, vbTextCompare) = 0 Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HasItem = True<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Function<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp; Next i<br/>End Function</p><p></p><p></p><p></p>

mccad 发表于 2009-5-22 21:09:00

<p>ObjectDbx是在AutoCAD打开的基础上才能实现。请注意,它可以实现不打开图形而对图形进行操作,但需要打开AutoCAD。</p><p>如果在VB中,则可以打开AutoCAD并让AutoCAD隐藏起来的情况下进行操作。但这样的话,会有长时间停顿的问题,因为需要在后台打开AutoCAD。</p>

king-hack 发表于 2009-5-22 21:15:00

<p>在VB中,可以实现不打开图形而对图形进行操作吗?</p>打开AutoCAD并让AutoCAD隐藏还是慢,可以像在ObjectDbx中那么快吗?

雪山飞狐_lzh 发表于 2009-5-22 21:30:00

Google 搜索 OpenDwg

king-hack 发表于 2009-5-23 06:23:00

lzh741206发表于2009-5-22 21:30:00static/image/common/back.gifGoogle 搜索 OpenDwg

<p>大哥,这个好像绝迹了,有谁能提供一下吗?不胜感激!</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="mailto:ywwxmm@yeah.net">ywwxmm@yeah.net</a></p>
页: [1]
查看完整版本: (求救mccad)vb6可以调用ObjectDbx技术吗?