Trizza 发表于 2022-7-6 09:20:44

LISP在2010年工作,但不是201年

好的,所以我在2010年在家里写了这个LISP,并按照我的期望让它工作。将其保存到一根棍子上,使其工作,并在2011年根据其创建目的运行它,然后出现了一个错误(我相信这是consp,不能确定,因为z服务器已关闭,稍后将再次保证)
 
LISP设计为在多段线的每个端点处放置一个点:

;;Place points at each vertice of a polyline
(defun c:pl2pt (/ SelSet o_max o object Location ent_db ent_t ent_v X Y Z p)
(setq SelSet (ssget))
(setq o_max (sslength SelSet))
(setq o 0)
(while (< o o_max) ;search through selected objects
   (setq ent_db (entget (ssname SelSet o)))
   (setq ent_t (cdr (assoc 0 ent_db)))
   (princ ent_t)
   ;Line "LINE"
   ;End of Line case
   
   
   ;Polyline
   ;(if (= ent_t "LWPOLYLINE")
   ;( ;true statement
   ;(cond
   ;((= ent_t "LWPOLYLINE") (
       (setq Z (cdr (assoc 38 ent_db)))
       (setq ent_v (cdr (assoc 90 ent_db)))
       (setq p 13)
       (while (< p (+ (* ent_v 5) 9))
         (setq X (cadr (nth p ent_db)))
         (setq Y (caddr (nth p ent_db)))
         (setq Location (list X Y Z))
         (command "_point" Location)
         (setq p (+ p 5)) ;next sector of polyline
       ) ;endwhile - end of polyline search
      ;endtrue - end of true statement
    ;endif
    ;end condition
   ;End of Polyline case

   
   ;2DPolyline
   ;End of 2DPolyline case

   
   ;3DPolyline "POLYLINE"
   ;End of 3DPolyline case

   (setq o (+ o 1)) ;next object
   
) ;endwhile for objects in selection set
)

 
我还希望能够对直线、三维多段线和二维多段线执行此操作(如果有人知道二维多段线的类型,这将节省我几分钟的时间),但当我引入“if(=ent\t“LWPOLYLINE”)”语句时,该语句当前是创建点脚本生成的注释,并出现错误(由于服务器关闭,因此无法再次给出错误)。我还尝试使用案例,看看这是否有效,但没有积极的结果。
 
有线索吗?

Ahankhah 发表于 2022-7-6 09:33:58


;;Place points at each vertice of a polyline
(defun c:pl2pt (/ SelSet o_max o object Location ent_db ent_t ent_v X Y Z p)
(setq SelSet (ssget))
(setq o_max (sslength SelSet))
(setq o 0)
(while (< o o_max) ;search through selected objects
   (setq ent_db (entget (ssname SelSet o)))
   (setq ent_t (cdr (assoc 0 ent_db)))
   (princ ent_t)
   ;Line "LINE"
   ;End of Line case
   
   
   ;Polyline
   ;(if (= ent_t "LWPOLYLINE")
   ;( ;true statement
   ;(cond
   ;((= ent_t "LWPOLYLINE") (
       (setq Z (cdr (assoc 38 ent_db)))
       (setq ent_v (cdr (assoc 90 ent_db)))
       (setq p 13)
       (while (< p (+ (* ent_v 5) 9))
         (setq X (cadr (nth p ent_db)))<--It refers to a cons list: (39 . 0.0), it isn't point list
          (setq Y (caddr (nth p ent_db)))
         (setq Location (list X Y Z))
         (command "_point" Location)
         (setq p (+ p 5)) ;next sector of polyline
       ) ;endwhile - end of polyline search
      ;endtrue - end of true statement
    ;endif
    ;end condition
   ;End of Polyline case

   
   ;2DPolyline
   ;End of 2DPolyline case

   
   ;3DPolyline "POLYLINE"
   ;End of 3DPolyline case

   (setq o (+ o 1)) ;next object
   
) ;endwhile for objects in selection set
)
有几件事我有点困惑
1、如何使用AT:命令
2.objPnt变量如何定义
3.lambda函数在这个函数中做什么(即它返回/定义了什么)PS。我通常需要了解lambda函数,但它通常与mapcar一起使用
4.与fix函数类似,我知道它将实数转换为整数,但无论如何都不会使用该整数

Trizza 发表于 2022-7-6 09:43:14

 
对于前面没有“c”的LISP函数:(
 

(defun AT:Segment (objPnt)
;; Retreive segment number and Start & End points
;; objPnt - List with object & point
;; Alan J. Thompson, 11.10.09 / 08.19.10
(if (vl-consp objPnt)
   ((lambda (seg)
      (list seg
            (list (vlax-curve-getPointAtParam (car objPnt) seg)
                  (cond
         ((vlax-curve-getPointAtParam (car objPnt) (1+ seg)))
                     ((vlax-curve-getPointAtParam (car objPnt) (1- seg)))
                  ) ;end cond
            ) ;end list
      ) ;end list = (seg# ((list.xyz) (cond.xyz)) )
    ) ;end lambda (function)
   (fix (vlax-curve-getParamAtPoint
            (car objPnt)
            (vlax-curve-getClosestPointTo (car objPnt) (trans (cadr objPnt) 1 0))
          )
   ) ;end fix
   ) ;end true
) ;endif
) ;end func

 
... 只需确保包含该函数的限定参数,即(cons-vla-Object-PointList)。
 
Lambda可能需要一点时间才能理解。在这种情况下,它(lambda)简洁地提供了一种方法,通过执行fix函数和lambda本身内的vlax curve getpointatparam函数来提供lambda的“seg”参数。
 
这可能没有意义,但基本上,替代方法是先执行fix函数(存储到变量),然后执行vlax curve getpointatparam组件,然后执行princ/prompt等。。posted方法是一种更简洁的方法。
 
希望这有帮助!

BlackBox 发表于 2022-7-6 09:58:33

再次感谢。
 
嗯,我得好好想想
 
在其他线程的帮助下,我一直在编写另一个例程(已编辑)

(AT:Segment objPnt)

我不断发现“参数太少”的错误,我仔细检查了,检查了括号,查找了命令,并确保所有内容都在那里。也许我一直在错过它,但我就是找不到导致错误的原因。
我发现我误用了entmod和subst命令,但通过更新代码,我得到了“点对输入中的额外CDR”。如果我在visual lisp控制台中运行脚本而不使用while并手动增加“i”,那么它可以正常工作。但是怎么可能呢

Trizza 发表于 2022-7-6 10:06:48

BlackBox 发表于 2022-7-6 10:20:34

 
For LISP functions that are not preceded by "c:" (
 

(AT:Segment objPnt)
 
... Just be sure to include a qualified argument for this function, i.e, (cons vla-Object PointList).
 
Lambda may take a little bit to sink in. In this case, it (the lambda) concisely provides a means by which to supply the lambda's "seg" argument by performing the fix function, and performing the vlax-curve-getpointatparam function within the lambda itself.
 
That may not make sense, but basically the alternative would be to perform the fix function first (store to variable), then perform the the vlax-curve-getpointatparam component, followed by a princ/prompt, etc.. The posted method is a more concise method.
 
Hope this helps!

Trizza 发表于 2022-7-6 10:25:17

Thanks again.
 
Hmm, gonna have to ponder on that one
 
I have been working on this other routine with a little help from other threads (edited)

(defun c:ContSep (/ ss i interval ent_db) (setq ss (ssget)) (setq interval (getreal "\nEnter contour interval: ")) (setq i 0) (while (< i (sslength ss))    (       (setq ent_db (entget (ssname ss i)))       (if(= (rem (cdr (assoc 38 ent_db)) interval) 0)         (entmod            (subst            (cons 8 (strcat "Contour_" (rtos interval 2) "m"))      (assoc 8 ent_db)      ent_db         )          )      )       (setq i (1+ i))    ) ))
and i keep getting 'too few arguments' error and i have looked through, check brackets, looked up the commands and made sure everything is there. Maybe i keep missing it but i just cant find what is causing the error.
I found i was misusing entmod and subst commands but with the updated code I am getting 'extra cdrs in dotted pair input'. If i run the script in visual lisp console without the while and increment 'i' manually it works fine. But how can '(
页: [1]
查看完整版本: LISP在2010年工作,但不是201年