42272846 发表于 2006-3-15 14:04:00

关于VBA对块进行缩放的问题,请达人们指点一下

<P>刚学CAD编程,希望实现以下功能:</P>
<P>构造选择集,从屏幕选择区域种筛选出块来放入选择集,遍历选择集,对选择集里面的块根据块名进行缩放,(每一个块名缩放比例固定),</P>
<P>希望达人们指点一下,谢谢了.</P>

xinghesnak 发表于 2006-3-16 08:15:00

<P>Sub main()<BR>Dim sel As AcadSelectionSet<BR>On Error Resume Next<BR>Set sel = ThisDrawing.SelectionSets.Item("Temp")<BR>If Err Then<BR>&nbsp;&nbsp;&nbsp; On Error GoTo 0<BR>&nbsp;&nbsp;&nbsp; Set sel = ThisDrawing.SelectionSets.Add("Temp")<BR>End If<BR>Dim filterType(0) As Integer, filterData(0) As Variant<BR>filterType(0) = 100: filterData(0) = "AcDbBlockReference"<BR>sel.SelectOnScreen filterType, filterData</P>
<P>Dim BlockRef As AcadBlockReference<BR>Dim BasePoint<BR>Dim ScaleFactory As Double<BR>ScaleFactory = 0.8<BR>For i = 0 To sel.Count - 1<BR>&nbsp;&nbsp;&nbsp; Set BlockRef = sel.Item(i)<BR>&nbsp;&nbsp;&nbsp; If BlockRef.Name = "asdfa" Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BasePoint = BlockRef.InsertionPoint<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BlockRef.ScaleEntity BasePoint, ScaleFactory<BR>&nbsp;&nbsp;&nbsp; End If<BR>Next<BR>End Sub</P>

42272846 发表于 2006-3-16 21:45:00

<P>谢谢了,通过你帮助,我写了如下过程,</P>
<P>Private Sub CommandButton1_Click()</P>
<P>On Error Resume Next<BR>&nbsp;&nbsp;&nbsp; Dim BlkRef As AcadBlockReference<BR>&nbsp;&nbsp;&nbsp; Dim BlkName As String<BR>&nbsp;&nbsp;&nbsp; ' 创建空白选择集<BR>&nbsp;&nbsp;&nbsp; Dim SS As AcadSelectionSet<BR>&nbsp;&nbsp;&nbsp; Set SS = CreatSSet<BR>&nbsp;&nbsp;&nbsp; Form_SuoFang.Hide<BR>&nbsp;&nbsp;&nbsp; ' 设置过滤条件,将所有同名的块过滤出来<BR>&nbsp;&nbsp;&nbsp; Dim FilterType As Variant<BR>&nbsp;&nbsp;&nbsp; Dim FilterData As Variant<BR>&nbsp;&nbsp;&nbsp; Dim FType(1) As Integer<BR>&nbsp;&nbsp;&nbsp; Dim FData(1) As Variant<BR>&nbsp;&nbsp;&nbsp; FType(0) = 0<BR>&nbsp;&nbsp;&nbsp; FData(0) = "insert" '图元名<BR>&nbsp;&nbsp;&nbsp; FType(1) = 66<BR>&nbsp;&nbsp;&nbsp; FData(1) = 0&nbsp; '不带属性<BR>&nbsp;&nbsp;&nbsp; FilterType = FType<BR>&nbsp;&nbsp;&nbsp; FilterData = FData<BR>&nbsp;&nbsp;&nbsp; SS.SelectOnScreen FilterType, FilterData<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Dim i As Integer<BR>&nbsp;&nbsp;&nbsp; Dim j As Integer<BR>&nbsp;&nbsp;&nbsp; Dim Blk As AcadBlock<BR>&nbsp;&nbsp;&nbsp; If SS.Count = 0 Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox "该区域内该块总数为零,请重新选择区域", vbExclamation, "错误"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Sub<BR>&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' 遍历选择集中的块<BR>&nbsp;&nbsp;&nbsp; For i = 0 To SS.Count - 1<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set BlkRef = SS(i)<BR>&nbsp;&nbsp;&nbsp; BlkName = BlkRef.Name<BR>&nbsp;&nbsp;&nbsp; If CheckBox2.Value = True Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SQLSTR = "select * from 放大倍率表 where 块名='" &amp; BlkName &amp; "'"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set ADORSTemp = Nothing<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ADORSTemp.Open SQLSTR, ADOConnection, adOpenKeyset, adLockOptimistic<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If ADORSTemp.RecordCount &gt; 0 Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BLX = ADORSTemp.Fields("倍率X").Value<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BLY = ADORSTemp.Fields("倍率Y").Value<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BLZ = ADORSTemp.Fields("倍率Z").Value<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BLX = 1<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BLY = 1<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BLZ = 1<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If BlkName = ComboBox1.Text Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BLX = TextBox1.Text<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BLY = TextBox2.Text<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BLZ = TextBox3.Text<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BLX = 1<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BLY = 1<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BLZ = 1<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp; BlkRef.XScaleFactor = BLX<BR>&nbsp;&nbsp;&nbsp; BlkRef.YScaleFactor = BLY<BR>&nbsp;&nbsp;&nbsp; BlkRef.ZScaleFactor = BLZ&nbsp;</P>
<P>&nbsp;&nbsp; Next<BR>&nbsp;&nbsp;&nbsp; MsgBox "放大成功!!!", vbExclamation, "提示"<BR>End Sub</P>
页: [1]
查看完整版本: 关于VBA对块进行缩放的问题,请达人们指点一下