明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
12
返回列表 发新帖
楼主: yuangw1234

圖塊會增加

  [复制链接]
发表于 2006-4-12 01:21:00 | 显示全部楼层

Sub tt()
On Error Resume Next
Dim obj As AcadEntity, pnt
Dim d As Integer
Do
ThisDrawing.Utility.GetEntity obj, pnt
Loop While (obj.ObjectName <> "AcDbCircle" And obj.ObjectName <> "AcDbBlockReference")

If Err Then
Err.Clear
Else

d = ThisDrawing.Utility.GetInteger("输入直径:")
If obj.ObjectName = "AcDbCircle" Then
AddNut d, , obj.Center
Else
AddNut d, obj
End If
End If
End Sub

Sub AddNut(dia As Integer, Optional blkref As AcadBlockReference, Optional insertpnt)
Dim blk As AcadBlock
Dim pnt(2) As Double
If blkref Is Nothing Then
    Set blk = ThisDrawing.Blocks.Add(pnt, "*N")
    Set blkref = ThisDrawing.ModelSpace.InsertBlock(insertpnt, blk.Name, 1, 1, 1, 0)
Else
    Set blk = ThisDrawing.Blocks(blkref.Name)
End If

For Each i In blk
    i.Delete
Next i

'这里向块里加入实体
blk.AddText "M" & dia, pnt, 5#

blkref.Update
End Sub

发表于 2006-4-12 11:43:00 | 显示全部楼层
理解你的意思,你还需要对原来已经插入的图块进行处理。
  1. Public Sub tt1()        '以下是变为各种螺丝调用程式
  2. Dim R  As Double
  3. On Error Resume Next
  4. Dim Sr As String
  5. Dim Zm As String
  6. Dim Shuz As Integer
  7. Dim Yj As Double
  8. Sr = InputBox("请输入人要变的东东", "变变", "")
  9. Zm = Left(Sr, 1)
  10. Shuz = Mid(Sr, 2)
  11. Select Case Zm
  12.      Case "m"
  13.      Select Case Shuz
  14.          Case 5
  15.              Yj = 4.3
  16.          Case 6
  17.              Yj = 5.2
  18.          Case 8
  19.              Yj = 6.8
  20.          Case 10
  21.              Yj = 8.6
  22.          Case 12
  23.              Yj = 10.5
  24.          Case 14
  25.              Yj = 12.5
  26.      End Select
  27.       Call Gy1(Shuz, Yj)
  28.      Case "u"  '以下是正面沉头的调用公式
  29.       'Call u(shuz)
  30.      Case Else
  31.      'Call gy(Val(sr))   '这是变为圆的调用程式
  32. End Select
  33. End Sub
  34. Public Sub Gy1(Ls As Integer, Yj As Double)
  35. On Error Resume Next
  36. Dim SSetObj1 As AcadSelectionSet      '以下是画螺丝的共用程式
  37. Dim I1 As Integer
  38. Dim SelObj1 As AcadObject
  39. Dim blockObj As AcadBlock
  40. Dim InsertPoint(0 To 2) As Double
  41. Dim i As Integer
  42. Dim BlockRefObj As AcadBlockReference
  43. Dim Pt1 As Variant
  44. Dim typeArray, dataArray
  45. Const PI = 3.141592654
  46.     BuildFilter typeArray, dataArray, -4, "<or", 0, "circle,arc", -4, "<and", 0, "insert", 2, "luosi*", -4, "and>", -4, "or>"
  47.     Set SSetObj1 = PickFirstSSet("please select object:", typeArray, dataArray)
  48.    
  49.      InsertPoint(0) = InsertPoint(1) = InsertPoint(2) = 0
  50.      
  51.      Set blockObj = ThisDrawing.Blocks("luosi" & Ls)
  52.      If Err Then
  53.          Err.Clear
  54.          Set blockObj = ThisDrawing.Blocks.Add(InsertPoint, "luosi" & Ls)
  55.          blockObj.AddArc InsertPoint, Ls / 2, PI, PI / 2
  56.          blockObj.AddCircle InsertPoint, Yj / 2
  57.      End If
  58.    
  59.      For I1 = 0 To SSetObj1.Count - 1
  60.          Set SelObj1 = SSetObj1.Item(I1)
  61.          Select Case SelObj1.ObjectName
  62.             Case "AcDbCircle", "AcDbCrc"
  63.              Pt1 = SelObj1.Center
  64.              Set BlockRefObj = ThisDrawing.ModelSpace.InsertBlock(Pt1, "luosi" & Ls, 1#, 1#, 1#, 0)
  65.             Case "AcDbBlockReference"
  66.             Pt1 = SelObj1.InsertionPoint
  67.              Set BlockRefObj = ThisDrawing.ModelSpace.InsertBlock(Pt1, "luosi" & Ls, 1#, 1#, 1#, 0)
  68.         End Select
  69.         SelObj1.Delete
  70.      
  71.        Next
  72. End Sub
  73. Public Sub BuildFilter(typeArray, dataArray, ParamArray gCodes())
  74.     Dim fType() As Integer, fData()
  75.     Dim index As Long, i As Long
  76.    
  77.     index = LBound(gCodes) - 1
  78.         
  79.     For i = LBound(gCodes) To UBound(gCodes) Step 2
  80.         index = index + 1
  81.         ReDim Preserve fType(0 To index)
  82.         ReDim Preserve fData(0 To index)
  83.         fType(index) = CInt(gCodes(i))
  84.         fData(index) = gCodes(i + 1)
  85.     Next
  86.     typeArray = fType: dataArray = fData
  87. End Sub
  88. Function PickFirstSSet(Optional txtTip As String = "", Optional typeArray = -1, Optional dataArray = -1) As AcadSelectionSet
  89.     On Error Resume Next
  90.     ThisDrawing.SelectionSets("PICKFIRST").Delete
  91.     Set PickFirstSSet = ThisDrawing.PickfirstSelectionSet
  92.     If PickFirstSSet.Count = 0 Then
  93.         If txtTip <> "" Then ThisDrawing.Utility.Prompt txtTip
  94.         If IsArray(typeArray) Then
  95.             PickFirstSSet.SelectOnScreen typeArray, dataArray
  96.         Else
  97.             PickFirstSSet.SelectOnScreen
  98.         End If
  99.     Else
  100.         If IsArray(typeArray) Then PickFirstSSet.Select acSelectionSetPrevious, , , typeArray, dataArray
  101.     End If
  102. End Function

 楼主| 发表于 2006-4-12 22:04:00 | 显示全部楼层

管理员,这次确实是好了,没想到要这么长的程式,太感谢你了!

在这里我真正感到了一个真正管理员的作风及为人,以前进的那个论坛太差了

最后我还是得说声谢谢管理员及版主,同时也感谢各位朋友,不过这个问题我

一直不解的是为什么只有管理员和版主在回复,可能是各位朋友觉得我这个问题

太简单了还是怎么回事?

 楼主| 发表于 2006-4-13 10:34:00 | 显示全部楼层

管理员你好,你那个虽然可以解决我的问题,不过我有点不懂,我一直想问管理员一个问题,就是为什么我的程式有这样一个处理 :就是假如我当前图中有名为"luosi"的块存在,然后就去删除(或炸开),删除后再做一个以"luosi"为名的块为什么会做不起来呢?我现在想到的一点就是:假如当前图中有这样一个名为"luosi"的块存在,我只要把这个块中所含有的东西的一些性质改一下,如m8变成m10,我只要把以前块中的那个圆的半径改成m10的半径,弧也做同样的处理,这种方法应该可行,目前我想请教管理员就是怎么样可以提出块中所拥有的东西,如一个圆,我得到这个圆我再去变这个圆的半径就容易了,希望管理员或版主和各位可以支持,因为这个问题确实困扰我一段时间,多谢大家

 

发表于 2006-4-13 11:41:00 | 显示全部楼层
1.插入后的图块,如果要删除,就得先删除图面上的块,才能删除块定义。
2.块定义中的对象可以修改的,直接修改就行。就跟修改图面上的对象一样(不同的是不能用选择集)
3.根据你程序只需要这点功能,程序可以简化:
  1. Public Sub tt1()        '以下是变为各种螺丝调用程式
  2.     On Error Resume Next
  3.     Dim Sr As String
  4.     Dim Zm As String
  5.     Dim Shuz As Integer
  6.     Sr = InputBox("请输入人要变的东东", "变变", "")
  7.     Zm = Left(Sr, 1)
  8.     Shuz = Mid(Sr, 2)
  9.     Select Case Zm
  10.          Case "m"
  11.           Call Gy1(Shuz)
  12.          Case "u"  '以下是正面沉头的调用公式
  13.           'Call u(shuz)
  14.          Case Else
  15.          'Call gy(Val(sr))   '这是变为圆的调用程式
  16.     End Select
  17. End Sub
  18. Public Sub Gy1(Ls As Integer)
  19.     On Error Resume Next
  20.     Dim SSetObj1 As AcadSelectionSet      '以下是画螺丝的共用程式
  21.     Dim SelObj1 As AcadEntity
  22.     Dim blockObj As AcadBlock
  23.     Dim InsertPoint(0 To 2) As Double
  24.     Dim i As Integer
  25.     Dim Pt1 As Variant
  26.      
  27.     Const PI = 3.141592654
  28.     ThisDrawing.SelectionSets("ss").Delete
  29.     Err.Clear
  30.     Set SSetObj1 = ThisDrawing.SelectionSets.Add("ss")
  31.     ThisDrawing.Utility.Prompt "please select object:"
  32.     SSetObj1.SelectOnScreen
  33.    
  34.     Set blockObj = ThisDrawing.Blocks("luosi" & Ls)
  35.     If Err Then
  36.         Err.Clear
  37.         Set blockObj = ThisDrawing.Blocks.Add(InsertPoint, "luosi" & Ls)
  38.         Dim YJ(14) As Double
  39.         YJ(5) = 4.3: YJ(6) = 5.2: YJ(8) = 6.8: YJ(10) = 8.6: YJ(12) = 10.5: YJ(14) = 12.5
  40.         blockObj.AddArc InsertPoint, Ls / 2, PI, PI / 2
  41.         blockObj.AddCircle InsertPoint, YJ(Ls) / 2
  42.     End If
  43.    
  44.     For i = 0 To SSetObj1.Count - 1
  45.         Set SelObj1 = SSetObj1.Item(i)
  46.         Select Case SelObj1.ObjectName
  47.             Case "AcDbCircle", "AcDbCrc"
  48.                 ThisDrawing.ModelSpace.InsertBlock SelObj1.Center, "luosi" & Ls, 1#, 1#, 1#, 0
  49.                 SelObj1.Delete
  50.             Case "AcDbBlockReference"
  51.                 SelObj1.Name = "luosi" & Ls
  52.                 SelObj1.Update
  53.         End Select
  54.     Next
  55. End Sub

 楼主| 发表于 2006-4-13 14:36:00 | 显示全部楼层

确实是精华,这么简捷的几名话就搞定了,真的很偑服,我这次看明白了

虽然我昨晚也搞定了,但我的程式冗长,以下就是我的程式,就是多了一个

假如有100个相同点则以其中一个点为中心变化,还有一个就是不能变的东西作了一个处理,我现在这里编了一些一次性标注整个图面中的圆和块的坐标,还有一些

就是较復杂pwline线的入块画法(冲模中用的),当然还有一些其它的拉圾程式,我的这些程式都好象太长,真想管理员简化一下,不过这次已经够打扰你们了,就先不再打扰了,我的这些程式还是先将就用著,在这里非常感谢你们

Public Sub gy1(ls As Double)
Dim ssetobj1 As AcadSelectionSet      '以下是画螺丝的共用程式
Dim icount1 As Integer
Dim selobj1 As AcadObject
Dim I As Integer
Dim i1 As Integer
Dim i2 As Integer
Dim shuzi As Integer
icount1 = ThisDrawing.SelectionSets.Count
While (icount1 > 0)
    If ThisDrawing.SelectionSets.Item(icount1 - 1).Name = "yuan" Then
    ThisDrawing.SelectionSets.Item(icount1 - 1).Delete
    End If
    icount1 = icount1 - 1
Wend
    Set ssetobj1 = ThisDrawing.SelectionSets.Add("yuan")
    ThisDrawing.Utility.Prompt "please select object"
    ssetobj1.SelectOnScreen
    Const pi = 3.141592654
    I = ThisDrawing.Blocks.Count
While (I > 0)
    If ThisDrawing.Blocks.Item(I - 1).Name = "luosi" Then
    For i2 = 0 To ThisDrawing.Blocks.Item(I - 1).Count - 1
    ThisDrawing.Blocks.Item(I - 1).Item(i2).Radius = yj / 2
    Next
    ThisDrawing.Regen acAllViewports
   
    End If
    I = I - 1
Wend
    insertpoint(0) = 0
    insertpoint(1) = 0
    insertpoint(2) = 0
    Set blockobj = ThisDrawing.Blocks.Add(insertpoint, "luosi")
        Dim ptn(0 To 2) As Variant
        ptn(0) = Null
        ptn(1) = Null
        ptn(2) = Null
    For i1 = 0 To ssetobj1.Count - 1
        Set selobj1 = ssetobj1.Item(i1)
    If selobj1.ObjectName = "AcDbCircle" Or selobj1.ObjectName = "AcDbCrc" Then
        pt1 = selobj1.Center
        ElseIf selobj1.ObjectName = "AcDbBlockReference" Then
        pt1 = selobj1.InsertionPoint
        Else
        shuzi = MsgBox("选择了不可以变的东西", "1")
        If shuzi = 2 Then
        End
        End If
    End If
        If pt1(0) = ptn(0) And pt1(1) = ptn(1) And pt1(2) = ptn(2) Then
        Else
        ptn(0) = pt1(0)
        ptn(1) = pt1(1)
        ptn(2) = pt1(2)
        Set arc1 = blockobj.AddArc(insertpoint, ls / 2, pi, pi / 2)
        arc1.Linetype = "CONTINUOUS"
        Set circ1 = blockobj.AddCircle(insertpoint, yj / 2)
        circ1.Linetype = "CONTINUOUS"
        Set blockrefobj = ThisDrawing.ModelSpace.InsertBlock(pt1, "luosi", 1#, 1#, 1#, 0)
        End If
        selobj1.Delete
   
    Next
       

End Sub

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

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-27 05:33 , Processed in 0.148834 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表