乐筑天下

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

[编程交流] AutoLisp启动请求

[复制链接]

26

主题

1495

帖子

20

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
118
发表于 2022-7-6 12:14:12 | 显示全部楼层
斯基普索,
 
你从事什么学科。如果你对这门学科有基本的了解,那么常规就更有意义了-大卫
回复

使用道具 举报

14

主题

185

帖子

180

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
73
发表于 2022-7-6 12:16:19 | 显示全部楼层
轨道结构
 
E、 G.信号架/基础/平台设计等
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 12:23:14 | 显示全部楼层
跳过,
 
如果你刚刚开始,我的方法是尝试一些基本的操作,例如,改变一个对象的层-从这样的例子中可以学到很多东西,还有很多方法。
 
我将从学习AutoLISP开始,当您完全能够使用AutoLISP功能时,进入一点Visual LISP,AutoCAD程序的结构将发挥更大的作用。
 
首先,我建议您先更改对象的DXF组码。
 
文本是一个很好的起点,因为你可以处理高度、内容、层次、颜色、样式等,所有这些都非常直观。
 
那么,为了让您开始,我们可以一步一步地通过一个简单的程序来更改选定文本项的文本高度吗?然后,如果你有任何困难,我们会帮助你
 
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 12:23:39 | 显示全部楼层
跳过,
 
这将使您大致了解如何使用其DXF数据修改enity。
 
我试图尽可能清楚地解释代码的每一步,但如果您有任何问题,请尽管问。
 
  1. [i][color=#990099];; Example to Change Text height of a selected item  ;;[/color][/i]
  2. [i][color=#990099];; to 2.0                                            ;;[/color][/i]
  3. [b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] c:ChangeHeight
  4.       [i][color=#990099];; Here we are defining the function, we[/color][/i]
  5.       [i][color=#990099];; use (defun c:..) to indicate that the[/color][/i]
  6.       [i][color=#990099];; user can invoke the function from the[/color][/i]
  7.       [i][color=#990099];; command-line.[/color][/i]
  8.       [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] ent[b][color=RED])[/color][/b]
  9.       [i][color=#990099];; Inside these bracket we list all the[/color][/i]
  10.       [i][color=#990099];; arguments needed for the function to[/color][/i]
  11.       [i][color=#990099];; work (before the forward slash), in this[/color][/i]
  12.       [i][color=#990099];; case none, and all the local variables[/color][/i]
  13.       [i][color=#990099];; i.e. symbols which have a value bound to[/color][/i]
  14.       [i][color=#990099];; them, which are used in the function.[/color][/i]
  15.       [i][color=#990099];; These variables will be set to nil when[/color][/i]
  16.       [i][color=#990099];; when the function is invoked and when the[/color][/i]
  17.       [i][color=#990099];; function completes.[/color][/i]
  18. [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b]  [i][color=#990099];; We must allow for the user not selecting[/color][/i]
  19.       [i][color=#990099];; anything.[/color][/i]
  20.    [b][color=RED]([/color][/b][b][color=BLUE]and[/color][/b] [i][color=#990099];; Both of the following conditions must[/color][/i]
  21.         [i][color=#990099];; return True for the IF statement to proceed.[/color][/i]
  22.      [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] ent [b][color=RED]([/color][/b][b][color=BLUE]car[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]entsel[/color][/b] [b][color=#a52a2a]"\nSelect Text Object: "[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
  23.      [i][color=#990099];; If the user picks something, entsel will return a[/color][/i]
  24.      [i][color=#990099];; list with two elements. The first element will be[/color][/i]
  25.      [i][color=#990099];; the entity name of the entity that was picked, and[/color][/i]
  26.      [i][color=#990099];; the second element will be the actual point that was[/color][/i]
  27.      [i][color=#990099];; picked, i.e. (3.4 5.2 0.0). We are only interested in[/color][/i]
  28.      [i][color=#990099];; the entity name, so we use 'car' to get the first element[/color][/i]
  29.      [i][color=#990099];; of the list, and then use 'setq' to bound this entity[/color][/i]
  30.      [i][color=#990099];; name to a variable, so that we can reference it later.[/color][/i]
  31.      [i][color=#990099];; Note that, if the user doesn't pick anything, entsel[/color][/i]
  32.      [i][color=#990099];; will return nil, and so (car (entsel)) will also return[/color][/i]
  33.      [i][color=#990099];; nil, and our IF statement will not be fullfilled.[/color][/i]
  34.      [b][color=RED]([/color][/b][b][color=BLUE]eq[/color][/b] [b][color=#a52a2a]"TEXT"[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cdr[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]assoc[/color][/b] [b][color=#009900]0[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]entget[/color][/b] ent[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
  35.      [i][color=#990099];; This is the second of our conditions that must be[/color][/i]
  36.      [i][color=#990099];; met for the AND statement to return True, and hence the[/color][/i]
  37.      [i][color=#990099];; IF statement to proceed.[/color][/i]
  38.      [i][color=#990099];; The 'entget' function will return the DXF data associated[/color][/i]
  39.      [i][color=#990099];; with an entity name, this includes all the data that[/color][/i]
  40.      [i][color=#990099];; describe that particular entity.[/color][/i]
  41.      [i][color=#990099];; The Group code '0' is the entity type, and each group[/color][/i]
  42.      [i][color=#990099];; code is listed as the code coupled with the data associated[/color][/i]
  43.      [i][color=#990099];; with that code, in this way:[/color][/i]
  44.      [i][color=#990099];;         ((0 . "TEXT") (40 . 2.5) ...)[/color][/i]
  45.      [i][color=#990099];; We can use the 'assoc' function to look at the first element[/color][/i]
  46.      [i][color=#990099];; in each of these lists, and retrieve the one that starts with '0'.[/color][/i]
  47.      [i][color=#990099];; We now have (0 . "TEXT"), so we can get at the second part of this[/color][/i]
  48.      [i][color=#990099];; using the 'cdr' function. We can then test to see whether this equals[/color][/i]
  49.      [i][color=#990099];; "TEXT" using the 'eq' function. If not, the user has selected an[/color][/i]
  50.      [i][color=#990099];; object that isn't text.[/color][/i]
  51.    [b][color=RED])[/color][/b] [i][color=#990099]; End AND[/color][/i]
  52.    [i][color=#990099];; Now we can proceed with the THEN statement, this is the statement[/color][/i]
  53.    [i][color=#990099];; that is evaluated if the text expression for the IF function is[/color][/i]
  54.    [i][color=#990099];; satisfied.[/color][/i]
  55.    [b][color=RED]([/color][/b][b][color=BLUE]entmod[/color][/b] [i][color=#990099];; Modify the entity after doing the following...[/color][/i]
  56.      [b][color=RED]([/color][/b][b][color=BLUE]subst[/color][/b]  [i][color=#990099];; Substitute[/color][/i]
  57.        [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]40[/color][/b] [b][color=#009999]2.0[/color][/b][b][color=RED])[/color][/b]  [i][color=#990099];; A dotted pair '(40 . 2.0)[/color][/i]
  58.          [b][color=RED]([/color][/b][b][color=BLUE]assoc[/color][/b] [b][color=#009900]40[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]entget[/color][/b] ent[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [i][color=#990099];; For the DXF group 40 entry in the list[/color][/i]
  59.        [b][color=RED]([/color][/b][b][color=BLUE]entget[/color][/b] ent[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [i][color=#990099];; The data list that is being operated on.[/color][/i]
  60.    [i][color=#990099];; This is the business end of the function. Here we are using the[/color][/i]
  61.    [i][color=#990099];; 'subst' function to substitute '(40 . 2.0) for the entry that[/color][/i]
  62.    [i][color=#990099];; starts with 40 in the DXF data list.[/color][/i]
  63.    [i][color=#990099];; The DXF code 40 represents the Text Height of the text, and,[/color][/i]
  64.    [i][color=#990099];; once we have made the substitution, we must update the entity[/color][/i]
  65.    [i][color=#990099];; using the 'entmod' function.[/color][/i]
  66.    [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=#a52a2a]"\n** Object is Not Text **"[/color][/b][b][color=RED])[/color][/b]
  67.    [i][color=#990099];; This is the ELSE statement for the IF function, so here we[/color][/i]
  68.    [i][color=#990099];; are alerting the user that they have not picked a text object.[/color][/i]
  69. [b][color=RED])[/color][/b] [i][color=#990099]; End IF[/color][/i]
  70. [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b][b][color=RED])[/color][/b] [i][color=#990099];; Exit Cleanly.[/color][/i]
  71. [b][color=RED])[/color][/b] [i][color=#990099];; End DEFUN[/color][/i]
  72.      
回复

使用道具 举报

14

主题

185

帖子

180

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
73
发表于 2022-7-6 12:29:16 | 显示全部楼层
干杯,李,
 
明天我会看一看(当我睡了一会儿的时候!哈哈)如果我有任何问题,我会让你知道的。
 
(如果我这么做,我会觉得很傻!!)
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 12:33:07 | 显示全部楼层
不用担心,乐意帮忙
回复

使用道具 举报

26

主题

1495

帖子

20

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
118
发表于 2022-7-6 12:35:15 | 显示全部楼层
这是我认为很有趣的一个。这都是英寸(我只是不是一个公制的家伙)
 
  1. (defun c:gate (/ hgt len qty sp xp maxx bn)
  2. (initget 7)
  3. (setq hgt (getdist "\nHeight To Pivot Point:   "))
  4. (while (or (not len)
  5.             (< len 96))
  6.         (initget 7)
  7.         (setq len (getdist "\nGate Length:   ")))
  8. (initget 6)
  9. (setq qty (getint "\nNumber Of Lights <4>:   "))
  10. (if (not qty)
  11.      (setq qty 4))
  12. ;;;START THE BLOCK DEFINITION
  13. (entmake (list (cons 0 "BLOCK")(list 10 0 0 0)(cons 70 0)
  14.               (cons 2 (strcat "GATE" (rtos len 2 0) "x" (itoa qty)))))
  15. ;;;MAKE THE COUNTER WEIGHT AND PIVOT
  16. (entmake (list (cons 0 "CIRCLE")(cons 8 "3D")(cons 39 10)(cons 10 (list 8 0 -5))(cons 40 1)(cons 210 (list 0 1 0))))
  17. (entmake (list (cons 0 "SOLID")(cons 8 "3D")(cons 39 4)(cons 10 (list -2 -5 -2))(cons 11 (list 0 -5 -2))(cons 12 (list -2 5 -2))(cons 13 (list 0 5 -2))))
  18. (entmake (list (cons 0 "SOLID")(cons 8 "3D")(cons 39 4)(cons 10 (list -32.48528137 -5 6.48528137))(cons 11 (list -30.48528137 -5 6.48528137))(cons 12 (list -32.48528137 5 6.48528137))(cons 13 (list -30.48528137 5 6.48528137))))
  19. (entmake (list (cons 0 "TRACE")(cons 8 "3D")(cons 39 2)(cons 10 (list 0 2 5))(cons 11 (list 0 -2 5))(cons 12 (list 11.17157288 2 5))(cons 13 (list 12.82842712 -2 5))(cons 210 (list 0 1 0))))
  20. (entmake (list (cons 0 "TRACE")(cons 8 "3D")(cons 39 2)(cons 10 (list 11.17157288 2 5))(cons 11 (list 12.82842712 -2 5))(cons 12 (list 19.65685425 10.48528137 5))(cons 13 (list 21.3137085 6.48528137 5))(cons 210 (list 0 1 0))))
  21. (entmake (list (cons 0 "TRACE")(cons 8 "3D")(cons 39 2)(cons 10 (list 19.65685425 10.48528137 5))(cons 11 (list 21.3137085 6.48528137 5))(cons 12 (list 32.48528137 10.48528137 5))(cons 13 (list 32.48528137 6.48528137 5))(cons 210 (list 0 1 0))))
  22. (entmake (list (cons 0 "TRACE")(cons 8 "3D")(cons 39 2)(cons 10 (list 19.65685425 10.48528137 -7))(cons 11 (list 21.3137085 6.48528137 -7))(cons 12 (list 32.48528137 10.48528137 -7))(cons 13 (list 32.48528137 6.48528137 -7))(cons 210 (list 0 1 0))))
  23. (entmake (list (cons 0 "TRACE")(cons 8 "3D")(cons 39 2)(cons 10 (list 11.17157288 2 -7))(cons 11 (list 12.82842712 -2 -7))(cons 12 (list 19.65685425 10.48528137 -7))(cons 13 (list 21.3137085 6.48528137 -7))(cons 210 (list 0 1 0))))
  24. (entmake (list (cons 0 "TRACE")(cons 8 "3D")(cons 39 2)(cons 10 (list 0 2 -7))(cons 11 (list 0 -2 -7))(cons 12 (list 11.17157288 2 -7))(cons 13 (list 12.82842712 -2 -7))(cons 210 (list 0 1 0))))
  25. ;;;MAKE THE LIGHTS
  26. (setq sp (/ len qty)
  27.      xp (* sp 0.5))
  28. (repeat qty
  29. (entmake (list (cons 0 "CIRCLE")(cons 8 "3D-RED")(cons 39 2)(cons 10 (list xp 6 -1))(cons 40 3)(cons 210 (list 0 -1 0))))
  30. (entmake (list (cons 0 "CIRCLE")(cons 8 "3D-BLACK")(cons 39 1.5)(cons 10 (list xp 0 2))(cons 40 0.5)))
  31. (setq xp (+ xp sp)))
  32. ;;;THE ARM STARTER SECTION
  33. (entmake (list (cons 0 "SOLID")(cons 8 "3D-WHITE")(cons 39 2)
  34.               (cons 10 (list 0 -2 -1))
  35.               (cons 11 (list 0  2 -1))
  36.               (cons 12 (list 2 -2 -1))
  37.               (cons 13 (list 6  2 -1))
  38.               (cons 210 (list 0 -1 0))))
  39. ;;;THE RED AND WHITE STRIPS
  40. (setq xp 2
  41.    maxx (- len 2))
  42. (while (< xp len)
  43.   (entmake (list (cons 0 "SOLID")(cons 8 "3D-RED")(cons 39 2)
  44.                  (cons 10 (list (min maxx (+ xp 0))  -2 -1))
  45.                  (cons 11 (list (min maxx (+ xp 4))   2 -1))
  46.                  (cons 12 (list (min maxx (+ xp 24)) -2 -1))
  47.                  (cons 13 (list (min maxx (+ xp 26))  2 -1))
  48.                  (cons 210 (list 0 -1 0))))
  49.   (entmake (list (cons 0 "SOLID")(cons 8 "3D-WHITE")(cons 39 2)
  50.                  (cons 10 (list (min maxx (+ xp 24)) -2 -1))
  51.                  (cons 11 (list (min maxx (+ xp 26))  2 -1))
  52.                  (cons 12 (list (min maxx (+ xp 48)) -2 -1))
  53.                  (cons 13 (list (min maxx (+ xp 52)) 2 -1))
  54.                  (cons 210 (list 0 -1 0))))
  55.   (setq xp (+ xp 48)))
  56. ;;;THE END CAP
  57. (entmake (list (cons 0 "SOLID")(cons 8 "3D-WHITE")(cons 39 2)
  58.               (cons 10 (list (- len 2)  2 -1))
  59.               (cons 11 (list (- len 0)  2 -1))
  60.               (cons 12 (list (- len 6) -2 -1))
  61.               (cons 13 (list (- len 0) -2 -1))
  62.               (cons 210 (list 0 -1 0))))
  63. ;;;FINISH THE BLOCK DEFITION
  64. (setq bn (entmake (list (cons 0 "ENDBLK")(cons 8 "0"))))
  65. ;;;SET THE LAYER COLORS
  66. (command "_.LAYER" "_C" 254 "3D" "_C" 1 "3D-RED" "_C" 7 "3D-WHITE" "")
  67. ;;;INSERT THE NEW BLOCK AT THE GIVEN HEIGHT
  68. (entmake (list (cons 0 "INSERT")(cons 2 bn)(cons 8 "0")
  69.               (cons 10 (list 0 0 hgt))))
  70. (prin1))

 
玩得开心-大卫
123723ew0077jjp7b7qmqb.jpg
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 12:37:49 | 显示全部楼层
干得好,大卫!我希望我在3D方面做得更好
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-6 02:03 , Processed in 0.738172 second(s), 68 queries .

© 2020-2025 乐筑天下

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