guitarguy1685 发表于 2022-7-6 11:42:42

getpoint和DXF

您好。我将继续学习如何通过DXF代码创建/修改实体。我试图编写一个lisp,根据用户输入创建一个以其中心为中心的圆。这是我第一次尝试的
 
 
(defun C:UA ()
(setq CPT (getpoint "\nSpecify insertion point: "))
(entmake '((0 . "CIRCLE") (8 . "TEST") (10 CPT) (40 0.375)))
)
 
第10组出现DXF错误。我最初认为可能是因为CPT会返回带括号的(x y z),而组应该是(10 x y z)而不是(10(x y z)),所以接下来我尝试了
 

(defun C:UA ()
(setq CPT (getpoint "\nSpecify insertion point: "))
(entmake '((0 . "CIRCLE") (8 . "TEST") (10 (car CPT) (cdr CPT) (cddr CPT)) (40 0.375)))
)
 
我还是有同样的问题。我错过了什么?

CarlB 发表于 2022-7-6 12:10:57

由于并非所有数据都是文字,因此不能使用带引号的列表。尝试:
 
(entmake(list’(0。“CIRCLE”)'(8。“TEST”)(cons 10 CPT)'(40 0.375)))

The Buzzard 发表于 2022-7-6 12:22:49

 
您不需要使用car,getpoint返回x、y和z值。
要在列表中使用变量,需要使用cons。
 
(defun C:UA (/ CPT)
(setq CPT (getpoint "\nSpecify insertion point: "))
(entmake
   (list
   (cons 0 "CIRCLE")
   (cons 8 "TEST")
   (cons 10 CPT)
   (cons 40 0.375)
   )
)
(princ))
 
 
 
当你决定去那里的时候,会额外增加一点:
 
设置图层和线型默认值。
创建线型定义HIDDEN2。
(注意:如果使用的是连续线型,则不需要线型定义。)
创建一个名为CIRCLE的层。
图层颜色为红色。
线型HIDDEN2。
线宽25mm。
获取半径和中心点。
把圆圈放在图层上。
 
(defun C:UA2 (/ CPT RAD LNAM LTYP LWGT LCLR)                         ;Define function, Declare local variables
(setq LNAM "CIRCLE"                                             ;Set layer name
       LCLR1                                                   ;Set layer color
       LTYP"HIDDEN2"                                             ;Set linetype
       LWGT25)                                                   ;Set lineweight
(or (tblsearch "ltype" "HIDDEN2")                                 ;Search drawing for linetype
   (entmake                                                      ;Entity make
   (list                                                         ;Start list
       (cons   0 "LTYPE")                                          ;Entity type
       (cons 100 "AcDbSymbolTableRecord")                        ;Subclass marker
       (cons 100 "AcDbLinetypeTableRecord")                        ;Subclass marker
       (cons   2 "HIDDEN2")                                        ;Linetype name
       (cons700)                                             ;Standard flag values (bit-coded values)
       (cons   3 "Hidden2 (.5x) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ");Linetype description
       (cons7265)                                              ;Alignment code; value is always 65, the ASCII code for A
       (cons732)                                             ;The number of linetype elements
       (cons400.1875)                                          ;Total pattern length
       (cons490.125)                                           ;Dash, dot or space length (one entry per element)
       (cons740)                                             ;Complex linetype element type (one per element). Default is 0 (no embedded shape/text)
       (cons49 -0.0625)                                          ;Dash, dot or space length (one entry per element)
       (cons740)                                             ;Complex linetype element type (one per element). Default is 0 (no embedded shape/text)
   )                                                             ;End list
   )                                                               ;End entity make
)                                                               ;End or
(if (null (tblsearch "layer" LNAM))                               ;Search drawing for layer name
   (entmake                                                      ;Entity make
   (list                                                         ;Start list
       (cons 0   "LAYER")                                          ;Entity type
       (cons 100 "AcDbSymbolTableRecord")                        ;Subclass marker
       (cons 100 "AcDbLayerTableRecord")                           ;Subclass marker
       (cons 2    LNAM)                                          ;Layer Name
       (cons 6    LTYP)                                          ;Linetype
       (cons 62   LCLR)                                          ;Layer color
       (cons 70   0)                                             ;Layer state
       (cons 2901)                                             ;Plotting flag
       (cons 370LWGT)                                          ;Set lineweight
   )                                                             ;End list
   )                                                               ;End entity make
)                                                               ;End if
(setq RAD (getreal   "\nSpecify radius: ")                        ;Get Radius
       CPT (getpoint "\nSpecify circle center point: "))         ;Get center point
(entmake                                                          ;Entity Make
   (list                                                         ;Start list
   (cons   0 "CIRCLE")                                           ;Entity type
   (cons 100 "AcDbEntity")                                       ;Subclass marker                           
   (cons 410 "Model")                                          ;Model Space
   (cons   8LNAM)                                              ;Layer
   (cons 100 "AcDbCircle")                                       ;Subclass marker
   (cons10CPT)                                             ;Center point
   (cons40RAD)                                             ;Radius
   )                                                               ;End list
)                                                               ;End Entity make
(princ))                                                          ;Exit quietly

The Buzzard 发表于 2022-7-6 12:32:25

从Acad开发者帮助:
 
cons功能
 
将元素添加到列表的开头,或构造虚线列表
(cons新的第一元素列表或原子)
 
论据
 
新的第一个元素
要添加到列表开头的元素。该元素可以是原子或列表。
 
列表或原子
列表或原子。
 
返回值
 
返回的值取决于列表或原子的数据类型。如果list或atom是一个列表,则cons返回该列表,并将新的第一个元素添加为列表中的第一项。如果list或atom是一个atom,则cons返回一个由新的第一个元素和list或atom组成的点对。
 
 
示例
命令:(cons“a”(b c d))
(A B C D)
命令:(cons’(a)'(b c d))
((A)B C D)
命令:(cons’a 2)
(A.2)
 
下面是一个关于实体生成块的有趣线程,展示了cons的使用。
 
http://www.cadtutor.net/forum/showthread.php?t=36793&highlight=entmake+方块

Lee Mac 发表于 2022-7-6 12:56:15

嗨,吉他小子,
 
您的问题可能已经得到了回答,但这绝对值得以后阅读:
 
http://www.cadtutor.net/forum/showpost.php?p=258390&postcount=20
页: [1]
查看完整版本: getpoint和DXF