明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3766|回复: 15

边框问题

  [复制链接]
发表于 2004-6-17 15:06:00 | 显示全部楼层 |阅读模式
' 绘边框的VBA程序
Public Sub test()
Dim ss As AcadSelectionSet
Dim i As AcadEntity
Dim pEntity(0) As AcadEntity
Set ss = ThisDrawing.ActiveSelectionSet
ss.Select acSelectionSetAll
ss(0).GetBoundingBox pmin, pmax
For Each i In ss
i.GetBoundingBox p1, p2
If p1(0) < pmin(0) Then pmin(0) = p1(0)
If p1(1) < pmin(1) Then pmin(1) = p1(1)
If p2(0) > pmax(0) Then pmax(0) = p2(0)
If p2(1) > pmax(1) Then pmax(1) = p2(1)
Next i
ThisDrawing.SendCommand "_.RECTANG " & pmin(0) & "," & pmin(1) & vbCr & pmax(0) & "," & pmax(1) & vbCr 把上面程序中的THISDRAWING替换为ACADDOC(在VB中使用) 为什么在Set ss = acaddoc.ActiveSelectionSet时出错"接口出错"
 楼主| 发表于 2004-6-17 15:27:00 | 显示全部楼层
错误信息


       

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
 楼主| 发表于 2004-6-17 15:37:00 | 显示全部楼层
可能是选择集的问题,我重新建立一个CAD文件,就可以运行一次.


有谁可以为我加个判断选择集的语句吗?


呵呵
发表于 2004-6-17 15:40:00 | 显示全部楼层
Dim ssetObj As AcadSelectionSet For Each ssetObj In ThisDrawing.SelectionSets
If ssetObj.Name = "SS" Then
ssetObj.Clear
ssetObj.Delete
Exit For
End If
Next ssetObj Set ssetObj = ThisDrawing.SelectionSets.Add("SS")
 楼主| 发表于 2004-6-17 15:56:00 | 显示全部楼层
<BR>       


  1. ' 绘边框的VBA程序<BR>Public Sub test()<BR>Dim ss As AcadSelectionSet<BR>Dim i As AcadEntity<BR>Dim pEntity(0) As AcadEntity<BR>Dim ssetObj As AcadSelectionSet

  2. For Each ssetObj In ThisDrawing.SelectionSets<BR>                         If ssetObj.Name = "SS" Then<BR>                                                         ssetObj.Clear<BR>                                                         ssetObj.Delete<BR>                                                         Exit For<BR>                         End If<BR>Next ssetObj

  3. Set ssetObj = ThisDrawing.SelectionSets.Add("SS")

  4. Set ss = ThisDrawing.ActiveSelectionSet<BR>ss.Select acSelectionSetAll<BR>ss(0).GetBoundingBox pmin, pmax<BR>For Each i In ss<BR>i.GetBoundingBox p1, p2<BR>If p1(0) &lt; pmin(0) Then pmin(0) = p1(0)<BR>If p1(1) &lt; pmin(1) Then pmin(1) = p1(1)<BR>If p2(0) &gt; pmax(0) Then pmax(0) = p2(0)<BR>If p2(1) &gt; pmax(1) Then pmax(1) = p2(1)<BR>Next i<BR>ThisDrawing.SendCommand "_.RECTANG " &amp; pmin(0) &amp; "," &amp; pmin(1) &amp; vbCr &amp; pmax(0) &amp; "," &amp; pmax(1) &amp; vbCr<BR>Set pEntity(0) = ThisDrawing.ModelSpace(ThisDrawing.ModelSpace.Count - 1)




  5. Dim offsetObj As Variant<BR>offsetObj = pEntity(0).Offset(500)<BR>pEntity(0).Delete<BR>''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''<BR>pmax(0) = pmax(0) + 500<BR>pmin(1) = pmin(1) - 500<BR>Dim ucsobj As AcadUCS<BR>Dim origin As Variant<BR>Dim xAxispnt As Variant<BR>Dim yAxispnt As Variant<BR>Dim utilObj As Object<BR>Set utilObj = ThisDrawing.Utility<BR>'定义ucs<BR>utilObj.CreateTypedArray origin, vbDouble, pmax(0), pmin(1), 3<BR>utilObj.CreateTypedArray xAxispnt, vbDouble, pmax(0) + 1, pmin(1), 3<BR>utilObj.CreateTypedArray yAxispnt, vbDouble, pmax(0), pmin(1) + 1, 3<BR>Set ucsobj = ThisDrawing.UserCoordinateSystems.Add(origin, xAxispnt, yAxispnt, "new_ucs")<BR>ThisDrawing.ActiveViewport.UCSIconAtOrigin = True<BR>        ThisDrawing.ActiveViewport.UCSIconOn = True<BR>         ThisDrawing.ActiveUCS = ucsobj

  6. Set pEntity(0) = ThisDrawing.ModelSpace(ThisDrawing.ModelSpace.Count - 1)<BR>Dim offsetObj1 As Variant<BR>offsetObj1 = pEntity(0).Offset(50)<BR>''''定义块的插入点<BR>Dim blockInspoint(0 To 2) As Double<BR>Dim blockRefobj As AcadBlockReference<BR>blockInspoint(0) = pmax(0)<BR>blockInspoint(1) = pmin(1)<BR>blockInspoint(2) = 3<BR>Set blockRefobj = ThisDrawing.ModelSpace.InsertBlock(inspoint, "F:\我的课题\陶瓷工业梭式窑CAD系统1\窑车标注1.dwg", 1, 1, 1, 0)
还是出现上面的问题.
发表于 2004-6-17 16:15:00 | 显示全部楼层
本帖最后由 作者 于 2004-6-17 22:31:27 编辑

Set ss = ThisDrawing.ActiveSelectionSet去掉,后面的ss用ssetObj代替
发表于 2004-6-17 16:18:00 | 显示全部楼层
ss(1).GetBoundingBox pmin, pmax


当前无选择集,当然会出错!
 楼主| 发表于 2004-6-17 16:23:00 | 显示全部楼层
兄弟 :到底如何做呀.


我的程序是在 画好边框后,在内边框插上标题栏,


只能运行一次扫心了
发表于 2004-6-17 17:07:00 | 显示全部楼层
lzh741206发表于2004-6-17 16:15:00Set ss = ThisDrawing.ActiveSelectionSet去掉,后面的ss用ssobj代替
...... For Each ssetObj In ThisDrawing.SelectionSets
If ssetObj.Name = "SS" Then
ssetObj.Clear
ssetObj.Delete
Exit For
End If
Next ssetObj Set ssetObj = ThisDrawing.SelectionSets.Add("SS") ssetObj .Select acSelectionSetAll
ssetObj .GetBoundingBox pmin, pmax
For Each i In ssetObj
i.GetBoundingBox p1, p2
......
 楼主| 发表于 2004-6-17 17:48:00 | 显示全部楼层
ssetObj .GetBoundingBox pmin, pmax 必须改为ssetOjb(0) 不知道是什么原因,而且运行中在CAD命令行中出现"命令: 忽略块 窑车标注 的重复定义。" 呵呵这不知道是什么意思
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-2-21 03:49 , Processed in 0.196335 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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