乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 41|回复: 6

[编程交流] 阵列维度

[复制链接]

2

主题

5

帖子

3

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-6 10:14:03 | 显示全部楼层 |阅读模式
我想用列表中的元素填充数组。问题是,当我想定义数组的维数时,上界取决于列表的长度,因此我使用以下代码:
 
(setq数组(vlax make safearray vlax vbDouble’(0(-(length newlist)1)))
 
我得到了一个“错误的参数类型:fixnump:((LENGTH NEWLIST)1)”错误。
 
有什么想法真的很有帮助吗?
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
358
发表于 2022-7-6 10:27:41 | 显示全部楼层
既然您已经开始编写所需例程的一些代码,那么最好将它们全部发布以查看它们,或者可以添加我们的代码供您使用。
 
谢谢
 
塔瓦特
回复

使用道具 举报

2

主题

5

帖子

3

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-6 10:35:48 | 显示全部楼层
我想做的是通过删除不重要的点来简化多段线。作为“不重要”,我定义了角度内的每个点。在下图中,点3不重要(内角),但点5很重要。
 

                               
登录/注册后可看大图

 
  1. ;(prompt "\nType "mine" to run........")
  2. (defun c:mine ( / theobj thelist n xval1 yval1 newlist maxdeg amax xval2 yval2 xval3 yval3 d1 d2 d3 z a l anarray mspace myobj)
  3.                            
  4. ;load the visual lisp extensions
  5. (vl-load-com)
  6.                            
  7. ;get the entity and entity name
  8. (setq theobj (car (entsel "\nSelect a Polyline: ")))
  9.                            
  10. ;convert to vl object
  11. (setq theobj (vlax-ename->vla-object theobj))
  12. ;retrieve the coordinates
  13. (setq thelist (vlax-get-property theobj 'coordinates))
  14. ;convert to a list
  15. (setq thelist (vlax-safearray->list  (variant-value thelist)))
  16. ;zero the counter
  17. (setq n 0)
  18. ;make a list of the simplified coordinates
  19. (setq xval1 (car thelist))
  20. (setq yval1 (cadr thelist))
  21. (setq newlist '(xval1 yval1))
  22. ;ask for maximum angle
  23. (setq maxdeg (getint "\nEnter Maximum Angle (0 - 90 deg) : "))
  24. ;convert degrees to radians using "dtr" routine
  25. (setq amax (dtr maxdeg))
  26. ;start the loop and repeat it for (n-2) times
  27. (repeat (- (/ (length thelist) 2) 2)
  28. ;get the x coordinates
  29. (setq xval1 (nth n thelist))
  30. (setq xval2 (nth (+ 2 n) thelist))
  31. (setq xval3 (nth (+ 4 n) thelist))
  32. ;increase the counter
  33. (setq n (1+ n))
  34. ;get the y coordinates
  35. (setq yval1 (nth n thelist))
  36. (setq yval2 (nth (+ 2 n) thelist))
  37. (setq yval3 (nth (+ 4 n) thelist))
  38. ;calculate distances using "distan" routine
  39. (setq d1 (distan xval1 xval2 yval1 yval2))
  40. (setq d2 (distan xval1 xval3 yval1 yval3))
  41. (setq d3 (distan xval2 xval3 yval2 yval3))
  42. ;calculate angle
  43. (setq z (/ (- (+ (expt d1 2) (expt d2 2)) (expt d3 2)) (* 2 (* d1 d2))))   
  44. (setq a (arccos z))
  45. ;compare the angles
  46. (if (> a (/ amax 2))
  47. ;if true do the following
  48. (progn  
  49. ;add the coordinates to the new list
  50. (setq newlist (append '(newlist xval3 yval3)))
  51. );progn
  52. );if
  53. ;increase the counter
  54. (setq n (1+ n))
  55. );repeat
  56. ;add the last point to the simplified list
  57. (setq xval1 (nth (- (length thelist) 1) thelist))
  58. (setq yval1 (last thelist))
  59. (setq newlist (append '(newlist xval1 yval1)))
  60. ;make an array with the points of the simplified list
  61. (setq anarray (vlax-make-safearray vlax-vbDouble '(0 . (- (length newlist) 1))))
  62. ;fill it with x and y values
  63. (vlax-safearray-fill anarray newlist)
  64. ;reference to model space
  65. (setq mspace (vla-get-modelSpace (vla-get-activeDocument (vlax-get-acad-object))))
  66. ;draw the simplified polyline
  67. (setq myobj (vla-addLightweightPolyline mspace anarray))
  68. (princ)
  69. );defun
  70. ;------------------------------------------
  71. ;This function converts Degrees to Radians.
  72. (defun dtr (x)
  73. ;define degrees to radians function
  74. (* pi (/ x 180.0))
  75. ;divide the angle by 180 then
  76. ;multiply the result by the constant PI
  77. ) ;end of function
  78. ;clean loading
  79. (princ)
  80. ;This function calculates distance
  81. (defun distan (x1 x2 y1 y2)
  82. ;calculate dx dy
  83. (setq pt1 (list x1 y1))
  84. (setq pt2 (list x2 y2))
  85. ;find the distance
  86. (distance pt1 pt2)
  87. ) ;end of function
  88. ;clean loading
  89. (princ)
  90. ;This function inverse cosine (ArcCos)
  91. ;Args: -1 <= x <= 1
  92. (defun arccos (x)
  93. (atan (/ (sqrt (- 1 (expt x 2))) x))
  94. )
  95. ;clean loading
  96. (princ)
  97. ;-------------------------------------------
  98. ;End of mine.lsp
  99. ;---------------------------
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 10:46:46 | 显示全部楼层
我做了李建议的改变,没关系(谢谢李!!!)但现在在下一行代码:
 
(vlax safearray fill anarray newlist)
 
我得到一个“lisp值不强制使用这种类型的变量:NEWLIST”错误。
这是什么意思?
回复

使用道具 举报

2

主题

5

帖子

3

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-6 10:59:01 | 显示全部楼层
看看你是如何构建“新列表”的-你确定你读了我的链接。。。
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 11:13:00 | 显示全部楼层
为我的第一个Lisp程序感到自豪。谢谢李的帮助和你的链接(我第二次读了,纠正了很多错误…)。
回复

使用道具 举报

2

主题

5

帖子

3

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-6 11:23:53 | 显示全部楼层
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-6 20:51 , Processed in 0.868317 second(s), 69 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表