David Bethel 发表于 2022-7-6 12:14:12

斯基普索,
 
你从事什么学科。如果你对这门学科有基本的了解,那么常规就更有意义了-大卫

skipsophrenic 发表于 2022-7-6 12:16:19

轨道结构
 
E、 G.信号架/基础/平台设计等

Lee Mac 发表于 2022-7-6 12:23:14

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

Lee Mac 发表于 2022-7-6 12:23:39

跳过,
 
这将使您大致了解如何使用其DXF数据修改enity。
 
我试图尽可能清楚地解释代码的每一步,但如果您有任何问题,请尽管问。
 

;; Example to Change Text height of a selected item;;
;; to 2.0                                          ;;

(defun c:ChangeHeight

      ;; Here we are defining the function, we
      ;; use (defun c:..) to indicate that the
      ;; user can invoke the function from the
      ;; command-line.

      (/ ent)

      ;; Inside these bracket we list all the
      ;; arguments needed for the function to
      ;; work (before the forward slash), in this
      ;; case none, and all the local variables
      ;; i.e. symbols which have a value bound to
      ;; them, which are used in the function.

      ;; These variables will be set to nil when
      ;; when the function is invoked and when the
      ;; function completes.

(if;; We must allow for the user not selecting
      ;; anything.

   (and ;; Both of the following conditions must
      ;; return True for the IF statement to proceed.

   (setq ent (car (entsel "\nSelect Text Object: ")))

   ;; If the user picks something, entsel will return a
   ;; list with two elements. The first element will be
   ;; the entity name of the entity that was picked, and
   ;; the second element will be the actual point that was
   ;; picked, i.e. (3.4 5.2 0.0). We are only interested in
   ;; the entity name, so we use 'car' to get the first element
   ;; of the list, and then use 'setq' to bound this entity
   ;; name to a variable, so that we can reference it later.

   ;; Note that, if the user doesn't pick anything, entsel
   ;; will return nil, and so (car (entsel)) will also return
   ;; nil, and our IF statement will not be fullfilled.

   (eq "TEXT" (cdr (assoc 0 (entget ent))))

   ;; This is the second of our conditions that must be
   ;; met for the AND statement to return True, and hence the
   ;; IF statement to proceed.

   ;; The 'entget' function will return the DXF data associated
   ;; with an entity name, this includes all the data that
   ;; describe that particular entity.

   ;; The Group code '0' is the entity type, and each group
   ;; code is listed as the code coupled with the data associated
   ;; with that code, in this way:
   ;;         ((0 . "TEXT") (40 . 2.5) ...)
   ;; We can use the 'assoc' function to look at the first element
   ;; in each of these lists, and retrieve the one that starts with '0'.

   ;; We now have (0 . "TEXT"), so we can get at the second part of this
   ;; using the 'cdr' function. We can then test to see whether this equals
   ;; "TEXT" using the 'eq' function. If not, the user has selected an
   ;; object that isn't text.

   ) ; End AND

   ;; Now we can proceed with the THEN statement, this is the statement
   ;; that is evaluated if the text expression for the IF function is
   ;; satisfied.

   (entmod ;; Modify the entity after doing the following...

   (subst;; Substitute

       (cons 40 2.0);; A dotted pair '(40 . 2.0)

         (assoc 40 (entget ent)) ;; For the DXF group 40 entry in the list

       (entget ent))) ;; The data list that is being operated on.

   ;; This is the business end of the function. Here we are using the
   ;; 'subst' function to substitute '(40 . 2.0) for the entry that
   ;; starts with 40 in the DXF data list.

   ;; The DXF code 40 represents the Text Height of the text, and,
   ;; once we have made the substitution, we must update the entity
   ;; using the 'entmod' function.

   (princ "\n** Object is Not Text **")

   ;; This is the ELSE statement for the IF function, so here we
   ;; are alerting the user that they have not picked a text object.

) ; End IF

(princ) ;; Exit Cleanly.

) ;; End DEFUN

   

skipsophrenic 发表于 2022-7-6 12:29:16

干杯,李,
 
明天我会看一看(当我睡了一会儿的时候!哈哈)如果我有任何问题,我会让你知道的。
 
(如果我这么做,我会觉得很傻!!)

Lee Mac 发表于 2022-7-6 12:33:07

不用担心,乐意帮忙

David Bethel 发表于 2022-7-6 12:35:15

这是我认为很有趣的一个。这都是英寸(我只是不是一个公制的家伙)
 

(defun c:gate (/ hgt len qty sp xp maxx bn)

(initget 7)
(setq hgt (getdist "\nHeight To Pivot Point:   "))

(while (or (not len)
            (< len 96))
      (initget 7)
      (setq len (getdist "\nGate Length:   ")))

(initget 6)
(setq qty (getint "\nNumber Of Lights <4>:   "))
(if (not qty)
   (setq qty 4))


;;;START THE BLOCK DEFINITION
(entmake (list (cons 0 "BLOCK")(list 10 0 0 0)(cons 70 0)
            (cons 2 (strcat "GATE" (rtos len 2 0) "x" (itoa qty)))))

;;;MAKE THE COUNTER WEIGHT AND PIVOT
(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))))
(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))))
(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))))
(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))))
(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))))
(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))))
(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))))
(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))))
(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))))


;;;MAKE THE LIGHTS
(setq sp (/ len qty)
   xp (* sp 0.5))

(repeat qty
(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))))
(entmake (list (cons 0 "CIRCLE")(cons 8 "3D-BLACK")(cons 39 1.5)(cons 10 (list xp 0 2))(cons 40 0.5)))
(setq xp (+ xp sp)))

;;;THE ARM STARTER SECTION
(entmake (list (cons 0 "SOLID")(cons 8 "3D-WHITE")(cons 39 2)
            (cons 10 (list 0 -2 -1))
            (cons 11 (list 02 -1))
            (cons 12 (list 2 -2 -1))
            (cons 13 (list 62 -1))
            (cons 210 (list 0 -1 0))))

;;;THE RED AND WHITE STRIPS
(setq xp 2
   maxx (- len 2))

(while (< xp len)
(entmake (list (cons 0 "SOLID")(cons 8 "3D-RED")(cons 39 2)
               (cons 10 (list (min maxx (+ xp 0))-2 -1))
               (cons 11 (list (min maxx (+ xp 4))   2 -1))
               (cons 12 (list (min maxx (+ xp 24)) -2 -1))
               (cons 13 (list (min maxx (+ xp 26))2 -1))
               (cons 210 (list 0 -1 0))))
(entmake (list (cons 0 "SOLID")(cons 8 "3D-WHITE")(cons 39 2)
               (cons 10 (list (min maxx (+ xp 24)) -2 -1))
               (cons 11 (list (min maxx (+ xp 26))2 -1))
               (cons 12 (list (min maxx (+ xp 48)) -2 -1))
               (cons 13 (list (min maxx (+ xp 52)) 2 -1))
               (cons 210 (list 0 -1 0))))
(setq xp (+ xp 48)))


;;;THE END CAP
(entmake (list (cons 0 "SOLID")(cons 8 "3D-WHITE")(cons 39 2)
            (cons 10 (list (- len 2)2 -1))
            (cons 11 (list (- len 0)2 -1))
            (cons 12 (list (- len 6) -2 -1))
            (cons 13 (list (- len 0) -2 -1))
            (cons 210 (list 0 -1 0))))

;;;FINISH THE BLOCK DEFITION
(setq bn (entmake (list (cons 0 "ENDBLK")(cons 8 "0"))))

;;;SET THE LAYER COLORS
(command "_.LAYER" "_C" 254 "3D" "_C" 1 "3D-RED" "_C" 7 "3D-WHITE" "")

;;;INSERT THE NEW BLOCK AT THE GIVEN HEIGHT
(entmake (list (cons 0 "INSERT")(cons 2 bn)(cons 8 "0")
            (cons 10 (list 0 0 hgt))))

(prin1))

 
玩得开心-大卫

Lee Mac 发表于 2022-7-6 12:37:49

干得好,大卫!我希望我在3D方面做得更好
页: 1 [2]
查看完整版本: AutoLisp启动请求