关于VBA对块进行缩放的问题,请达人们指点一下
<P>刚学CAD编程,希望实现以下功能:</P><P>构造选择集,从屏幕选择区域种筛选出块来放入选择集,遍历选择集,对选择集里面的块根据块名进行缩放,(每一个块名缩放比例固定),</P>
<P>希望达人们指点一下,谢谢了.</P> <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> On Error GoTo 0<BR> 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> Set BlockRef = sel.Item(i)<BR> If BlockRef.Name = "asdfa" Then<BR> BasePoint = BlockRef.InsertionPoint<BR> BlockRef.ScaleEntity BasePoint, ScaleFactory<BR> End If<BR>Next<BR>End Sub</P> <P>谢谢了,通过你帮助,我写了如下过程,</P>
<P>Private Sub CommandButton1_Click()</P>
<P>On Error Resume Next<BR> Dim BlkRef As AcadBlockReference<BR> Dim BlkName As String<BR> ' 创建空白选择集<BR> Dim SS As AcadSelectionSet<BR> Set SS = CreatSSet<BR> Form_SuoFang.Hide<BR> ' 设置过滤条件,将所有同名的块过滤出来<BR> Dim FilterType As Variant<BR> Dim FilterData As Variant<BR> Dim FType(1) As Integer<BR> Dim FData(1) As Variant<BR> FType(0) = 0<BR> FData(0) = "insert" '图元名<BR> FType(1) = 66<BR> FData(1) = 0 '不带属性<BR> FilterType = FType<BR> FilterData = FData<BR> SS.SelectOnScreen FilterType, FilterData<BR> <BR> Dim i As Integer<BR> Dim j As Integer<BR> Dim Blk As AcadBlock<BR> If SS.Count = 0 Then<BR> MsgBox "该区域内该块总数为零,请重新选择区域", vbExclamation, "错误"<BR> Exit Sub<BR> End If<BR> ' 遍历选择集中的块<BR> For i = 0 To SS.Count - 1<BR> Set BlkRef = SS(i)<BR> BlkName = BlkRef.Name<BR> If CheckBox2.Value = True Then<BR> SQLSTR = "select * from 放大倍率表 where 块名='" & BlkName & "'"<BR> Set ADORSTemp = Nothing<BR> ADORSTemp.Open SQLSTR, ADOConnection, adOpenKeyset, adLockOptimistic<BR> If ADORSTemp.RecordCount > 0 Then<BR> BLX = ADORSTemp.Fields("倍率X").Value<BR> BLY = ADORSTemp.Fields("倍率Y").Value<BR> BLZ = ADORSTemp.Fields("倍率Z").Value<BR> Else<BR> BLX = 1<BR> BLY = 1<BR> BLZ = 1<BR> End If<BR> Else<BR> If BlkName = ComboBox1.Text Then<BR> BLX = TextBox1.Text<BR> BLY = TextBox2.Text<BR> BLZ = TextBox3.Text<BR> Else<BR> BLX = 1<BR> BLY = 1<BR> BLZ = 1<BR> End If<BR> End If<BR> BlkRef.XScaleFactor = BLX<BR> BlkRef.YScaleFactor = BLY<BR> BlkRef.ZScaleFactor = BLZ </P>
<P> Next<BR> MsgBox "放大成功!!!", vbExclamation, "提示"<BR>End Sub</P>
页:
[1]