明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2447|回复: 4

[求助]如何自定义UCS坐标的表达方式?

[复制链接]
发表于 2009-7-21 20:01:00 | 显示全部楼层 |阅读模式

如何建立自定义表达方式的UCS. 例如,想建立这样一个UCS, 原点在WCS的原点上,Y、Z方向按WCS表述,X方向按肋位号表示。如:肋位为0-100,每档肋位间距500mm,这样,相对于WCS的点(6000,1200,3000)按此UCS方法表示就是(FR12,1200,3000).

我的问题就是能否建立上述坐标系,可以自定义坐标的表达方式。如在画直线命令时,以(FR12,1200,3000)的形式输入点坐标,而不是(6000,1200,3000)。不知道能否实现。望达者解惑,等待...

发表于 2009-7-24 12:54:00 | 显示全部楼层
学习AUTOCAD二次开发第九章
  1. Sub test_AddOrgUCS()
  2.      '原点UCS调用示例
  3.      Dim myUCS As AcadUCS, NewOrgPt As Variant
  4.      NewOrgPt = ThisDrawing.Utility.GetPoint(, vbCrLf & "请输入新原点:")
  5.      Set myUCS = AddOrgUCS(NewOrgPt, "abc")
  6.      ThisDrawing.ActiveUCS = myUCS
  7. End Sub
  8. Sub test_AddXAngUCS()
  9.      'X轴旋转UCS调用示例
  10.      Dim myUCS As AcadUCS, Ang As Double
  11.      Ang = ThisDrawing.Utility.GetAngle(, vbCrLf & "请指定绕 X 轴的旋转角度:")
  12.      Set myUCS = AddXAngUCS(Ang, "abc")
  13.      ThisDrawing.ActiveUCS = myUCS
  14. End Sub
  15. Sub test_AddYAngUCS()
  16.      'Y轴旋转UCS调用示例
  17.      Dim myUCS As AcadUCS, Ang As Double
  18.      Ang = ThisDrawing.Utility.GetAngle(, vbCrLf & "请指定绕 Y 轴的旋转角度:")
  19.      Set myUCS = AddYAngUCS(Ang, "abc")
  20.      ThisDrawing.ActiveUCS = myUCS
  21. End Sub
  22. Sub test_AddZAngUCS()
  23.      'Z轴旋转UCS调用示例
  24.      Dim myUCS As AcadUCS, Ang As Double
  25.      Ang = ThisDrawing.Utility.GetAngle(, vbCrLf & "请指定绕 Z 轴的旋转角度:")
  26.      Set myUCS = AddZAngUCS(Ang, "abc")
  27.      ThisDrawing.ActiveUCS = myUCS
  28. End Sub
  29. ' 移动原点创建UCS
  30. ' ptOriginWcs:新UCS的原点在WCS中的坐标
  31. Public Function AddOrgUCS(ptOriginWcs As Variant, strUcsName As String) As AcadUCS
  32.      ' 获得新UCS原点在当前UCS中的坐标
  33.      Dim ptOriginUcs As Variant
  34.      ptOriginUcs = PtWcs2Ucs(ptOriginWcs)
  35.      'Debug.Print ptOriginWcs(0)
  36.      ' 获得X、Y正半轴上任一点的UCS坐标
  37.      Dim ptXUcs(0 To 2) As Double, ptYUcs(0 To 2) As Double
  38.      ptXUcs(0) = ptOriginUcs(0) + 1
  39.      ptXUcs(1) = ptOriginUcs(1)
  40.      ptXUcs(2) = ptOriginUcs(2)
  41.      ptYUcs(0) = ptOriginUcs(0)
  42.      ptYUcs(1) = ptOriginUcs(1) + 1
  43.      ptYUcs(2) = ptOriginUcs(2)
  44.      
  45.      ' 获得X、Y正半轴上任一点的WCS坐标
  46.      Dim ptXWcs As Variant, ptYWcs As Variant
  47.      ptOriginWcs = PtUcs2Wcs(ptOriginUcs)
  48.      ptXWcs = PtUcs2Wcs(ptXUcs)
  49.      ptYWcs = PtUcs2Wcs(ptYUcs)
  50.      'Debug.Print ptOriginWcs(0)
  51.      ' 创建UCS
  52.      Set AddOrgUCS = ThisDrawing.UserCoordinateSystems.Add(ptOriginWcs, ptXWcs, ptYWcs, strUcsName)
  53. End Function
  54. ' 旋转X轴创建新的UCS
  55. ' angle:弧度值,绕X轴旋转的角度(旋转方向由右手定则决定)
  56. Public Function AddXAngUCS(angle As Double, strUcsName As String) As AcadUCS
  57.      ' 定义新UCS原点的三维WCS坐标
  58.      Dim ptOriginUcs(0 To 2) As Double
  59.      ptOriginUcs(0) = 0: ptOriginUcs(1) = 0: ptOriginUcs(2) = 0
  60.      Dim ptOriginWcs As Variant
  61.      ptOriginWcs = PtUcs2Wcs(ptOriginUcs)
  62.      
  63.      ' 定义新UCS在X轴正方向上一个点的三维WCS坐标
  64.      Dim ptXUcs(0 To 2) As Double
  65.      ptXUcs(0) = 1: ptXUcs(1) = 0: ptXUcs(2) = 0
  66.      Dim ptXWcs As Variant
  67.      ptXWcs = PtUcs2Wcs(ptXUcs)
  68.      
  69.      ' 定义新UCS在Y轴正方向上一个点的三维WCS坐标
  70.      Dim ptYUcs(0 To 2) As Double
  71.      ptYUcs(0) = 0: ptYUcs(1) = Cos(angle): ptYUcs(2) = Sin(angle)
  72.      Dim ptYWcs As Variant
  73.      ptYWcs = PtUcs2Wcs(ptYUcs)
  74.      
  75.      Set AddXAngUCS = ThisDrawing.UserCoordinateSystems.Add(ptOriginWcs, ptXWcs, ptYWcs, strUcsName)
  76. End Function
  77. ' 旋转Y轴创建新的UCS
  78. ' angle:弧度值,绕Y轴旋转的角度(旋转方向由右手定则决定)
  79. Public Function AddYAngUCS(angle As Double, strUcsName As String) As AcadUCS
  80.      ' 定义新UCS原点的三维WCS坐标
  81.      Dim ptOriginUcs(0 To 2) As Double
  82.      ptOriginUcs(0) = 0: ptOriginUcs(1) = 0: ptOriginUcs(2) = 0
  83.      Dim ptOriginWcs As Variant
  84.      ptOriginWcs = PtUcs2Wcs(ptOriginUcs)
  85.      
  86.      ' 定义新UCS在X轴正方向上一个点的三维WCS坐标
  87.      Dim ptXUcs(0 To 2) As Double
  88.      ptXUcs(0) = Cos(angle): ptXUcs(1) = 0: ptXUcs(2) = -Sin(angle)
  89.      Dim ptXWcs As Variant
  90.      ptXWcs = PtUcs2Wcs(ptXUcs)
  91.      
  92.      ' 定义新UCS在Y轴正方向上一个点的三维WCS坐标
  93.      Dim ptYUcs(0 To 2) As Double
  94.      ptYUcs(0) = 0: ptYUcs(1) = 1: ptYUcs(2) = 0
  95.      Dim ptYWcs As Variant
  96.      ptYWcs = PtUcs2Wcs(ptYUcs)
  97.      
  98.      Set AddYAngUCS = ThisDrawing.UserCoordinateSystems.Add(ptOriginWcs, ptXWcs, ptYWcs, strUcsName)
  99. End Function
  100. ' 旋转Z轴创建新的UCS
  101. ' angle:弧度值,绕Z轴旋转的角度(旋转方向由右手定则决定)
  102. Public Function AddZAngUCS(angle As Double, strUcsName As String) As AcadUCS
  103.      ' 定义新UCS原点的三维WCS坐标
  104.      Dim ptOriginUcs(0 To 2) As Double
  105.      ptOriginUcs(0) = 0: ptOriginUcs(1) = 0: ptOriginUcs(2) = 0
  106.      Dim ptOriginWcs As Variant
  107.      ptOriginWcs = PtUcs2Wcs(ptOriginUcs)
  108.      
  109.      ' 定义新UCS在X轴正方向上一个点的三维WCS坐标
  110.      Dim ptXUcs(0 To 2) As Double
  111.      ptXUcs(0) = Cos(angle): ptXUcs(1) = Sin(angle): ptXUcs(2) = 0
  112.      Dim ptXWcs As Variant
  113.      ptXWcs = PtUcs2Wcs(ptXUcs)
  114.      
  115.      ' 定义新UCS在Y轴正方向上一个点的三维WCS坐标
  116.      Dim ptYUcs(0 To 2) As Double
  117.      ptYUcs(0) = -Sin(angle): ptYUcs(1) = Cos(angle): ptYUcs(2) = 0
  118.      Dim ptYWcs As Variant
  119.      ptYWcs = PtUcs2Wcs(ptYUcs)
  120.      
  121.      Set AddZAngUCS = ThisDrawing.UserCoordinateSystems.Add(ptOriginWcs, ptXWcs, ptYWcs, strUcsName)
  122. End Function
  123. ' 将点的UCS坐标转化到WCS坐标
  124. Private Function PtUcs2Wcs(ptUcs As Variant) As Variant
  125.      PtUcs2Wcs = ThisDrawing.Utility.TranslateCoordinates(ptUcs, acUCS, acWorld, False)
  126. End Function
  127. ' 将点的WCS坐标转化到UCS坐标
  128. Private Function PtWcs2Ucs(ptWcs As Variant) As Variant
  129.      PtWcs2Ucs = ThisDrawing.Utility.TranslateCoordinates(ptWcs, acWorld, acUCS, False)
  130. End Function
 楼主| 发表于 2009-7-27 11:10:00 | 显示全部楼层

楼上的应该没有明白我的意思,我是想在坐标的输入方式上有所更改,用(FR12,1200,3000)代替(6000,1200,3000)。

发表于 2009-7-27 12:18:00 | 显示全部楼层
hzh2000发表于2009-7-27 11:10:00楼上的应该没有明白我的意思,我是想在坐标的输入方式上有所更改,用(FR12,1200,3000)代替(6000,1200,3000)。

在VBA中(FR12,1200,3000),(6000,1200,3000)需要在在VBA的UCS中,点坐标转换.

Set myUCS = AddOrgUCS(NewOrgPt, "abc")

式中的NewOrgPt是dim NewOrgPT(0 to 2) as double.

FR12是你自己定义,在VBA中没有,这应属VB字符替换知识.

 楼主| 发表于 2009-7-27 23:07:00 | 显示全部楼层

FR12代替6000,12与6000的关系是12*500,同理FR15就是15*500=7500,不可能每个字符都定义,所以有很大差距

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

本版积分规则

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

GMT+8, 2024-11-26 02:32 , Processed in 0.163508 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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