mccad 发表于 2002-5-28 20:52:00

[例程]使用UCS坐标系

Public Sub UseUcs()

    Dim ucsObj As AcadUCS             '声明新的UCS对象变量
    Dim orgPnt(0 To 2) As Double      'UCS原点数组变量
    'X轴和Y轴上的定向点变量
    Dim xPnt(0 To 2) As Double, yPnt(0 To 2) As Double
    '保存当前活动视窗的变量
    Dim cueViewport As AcadViewport
   
    '保存当前活动视窗
    Set curViewport = ThisDrawing.ActiveViewport
   
    '创建一个圆,一开始只能在WCS中实现
    Dim cirObj As AcadCircle
    Dim center(0 To 2) As Double, radius As Double
    center(0) = 25: center(1) = 25: center(2) = 0
    radius = 18
    Set cirObj = ThisDrawing.ModelSpace.AddCircle(center, radius)
   
    ZoomAll
   
    '为UCS的原点和X轴、Y轴上的定向点赋值
    orgPnt(0) = 50: orgPnt(1) = 50: orgPnt(2) = 0
    xPnt(0) = 75: xPnt(1) = 50: xPnt(2) = 0
    yPnt(0) = 50: yPnt(1) = 75: yPnt(2) = 0
   
    '创建一个名为UCS1的用户坐标系
    Set ucsObj = ThisDrawing.UserCoordinateSystems.Add _
               (orgPnt, xPnt, yPnt, "UCS1")
    '使新创建的UCS1成为活动坐标系
    ThisDrawing.ActiveUCS = ucsObj
    '显示UCS1的图标
    ThisDrawing.ActiveViewport.UCSIconOn = True
    '使UCS1的图标定在原点上
    ThisDrawing.ActiveViewport.UCSIconAtOrigin = True
   
    Dim transMatrix As Variant
   
    '获得UCS相对WCS坐标的变换矩阵
    transMatrix = ucsObj.GetUCSMatrix()
   
    '将WCS中的圆变换到UCS中
    cirObj.TransformBy transMatrix
    cirObj.Update
   
    MsgBox "现在圆已被转换到UCS坐标中了!"
   
    '将当前视窗回复到WCS坐标系中
    ThisDrawing.ActiveViewport = curViewport

End Sub

兰州人 发表于 2007-5-13 15:37:00

本帖最后由 作者 于 2007-5-13 17:56:25 编辑 <br /><br /> <p>上面例子说明如何在UCS坐标系中建立圆的方法.</p><p>反之在用户坐标系中已经建立了一个实体.如图示所示的圆弧--句柄为A7圆弧实体</p><p>如何获得A7实体的UCS信息??</p><p>通过获取A7圆弧的属性数据</p><p>RetVal = object.AddArc(Center, Radius, StartAngle, EndAngle)</p><p>和用户坐标系恢复到图示的句柄 A7实体状态</p><p><br/><img title="dvubb" alt="图片点击可在新窗口打开查看" src="http://www.mjtd.com/BBS/skins/default/filetype/jpg.gif" border="0"/>此主题相关图片如下:<br/><a href="http://www.mjtd.com/BBS/showimg.asp?BoardID=4&amp;fileid=34488" target="_blank"><img title="dvubb" alt="图片点击可在新窗口打开查看" src="http://www.mjtd.com/BBS/showimg.asp?BoardID=4&amp;fileid=34488" border="0"/></a><br/></p><p>采用list 查询两个圆弧属性如下:</p><p>&nbsp;句柄 = A6<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 圆心 点,X=&nbsp;&nbsp; 1.0611&nbsp; Y=&nbsp;&nbsp; 1.0491&nbsp; Z=&nbsp;&nbsp; 0.0000<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 半径&nbsp;&nbsp;&nbsp; 0.2594&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 起点 角度&nbsp;&nbsp; 269&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 端点 角度&nbsp;&nbsp;&nbsp; 91&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 长度&nbsp;&nbsp;&nbsp; 0.8258</p><p>句柄 = A7<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 圆心 点,X=&nbsp;&nbsp; 1.0558&nbsp; Y=&nbsp;&nbsp; 1.0491&nbsp; Z=&nbsp;&nbsp; 0.0054<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 半径&nbsp;&nbsp;&nbsp; 0.2594&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p><p>&nbsp;相对于 UCS 的拉伸方向:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; X=&nbsp; -1.0000&nbsp; Y=&nbsp;&nbsp; 0.0000&nbsp; Z=&nbsp;&nbsp; 0.0000<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 长度&nbsp;&nbsp;&nbsp; 0.8258<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 累计角度&nbsp;&nbsp;&nbsp; 182</p><p>问题如下</p><p>Sub ls()<br/>&nbsp; Dim lsArc As AcadArc<br/>&nbsp; Dim rr As AcadEntity<br/>&nbsp; For Each rr In ThisDrawing.ModelSpace<br/>&nbsp;&nbsp;&nbsp; Set lsArc = rr<br/>&nbsp;&nbsp;&nbsp; Debug.Print lsArc.StartAngle</p><p>&nbsp; Next rr<br/>End Sub<br/>用传统方法获取Arc的属性只能是WCS坐标系下的Arc SartPoint,EndPoint,CenterPoint等属性数据.</p><p>我需要的数据是</p><p><font color="#ff0000">相对于 UCS 的拉伸方向:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; X=&nbsp; -1.0000&nbsp; Y=&nbsp;&nbsp; 0.0000&nbsp; Z=&nbsp;&nbsp; 0.0000<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 长度&nbsp;&nbsp;&nbsp; 0.8258<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 累计角度&nbsp;&nbsp;&nbsp; 182</font></p><p></p>
页: [1]
查看完整版本: [例程]使用UCS坐标系