向现有几何添加点

Adding points to an existing geometry

我有一个在 AutoCAD 中创建的二维几何图形的 dxf 文件,我想在现有几何图形的线上添加点。要添加的点列表存在于文本文件中。

比如我想在上图中3和2之间的直线上加10个点。 10 个点的 (x,y) 坐标存在于文本文件中。有没有办法导入和捕捉靠近边界(/线)的坐标,因为坐标来自预处理步骤,可能与 3 - 2 上的实际点有点偏离。

任何建议都会有很大帮助!

基本上是这样的:

 (defun C:ImportPoints (  / path coordinates askForFile loadPoints draw
 *error* )  (defun *error* ( msg / ) 
     (if (not (null msg ) ) (progn (princ "\nC:ImportPoints:*error*: " ) (princ msg ) (princ "\n")  ) )
 )
  (defun askForFile (  / 
      *error* ) (defun *error* ( msg / ) 
          (if (not (null msg ) )    (progn (princ "\naskForFile:*error*: " ) (princ msg ) (princ "\n")  ) )
      )
      (getfiled "Select the file with coordinates" "txt" 2)
  )

  (defun loadPoints ( path / 
      *error* ) (defun *error* ( msg / ) 
          (if (not (null msg ) )    (progn (princ "\nLoadPoints:*error*: " ) (princ msg ) (princ "\n")  ) )
      )  

    (setq filedesc (open Path "r"))
    (if filedesc(progn 
        (setq OutList (list))
        (setq linia(read-line filedesc))
        (while linia
        (progn
            (setq OutList (append OutList (list linia)))
            (setq linia (read-line filedesc))
        ))
        (close filedesc )
    ))  
    OutList
  )

  (defun draw ( coordinates / 
      *error* ) (defun *error* ( msg / ) 
          (if (not (null msg ) )    (progn (princ "\ndraw:*error*: " ) (princ msg ) (princ "\n")    ) )
      )
      (setq lastOSMODE (getvar "OSMODE"))
      (setvar "OSMODE" 512) ; 512 nearest
      (foreach % coordinates
        (command "_POINT" %)
      )
      (setvar "OSMODE" lastOSMODE ) ; ensure You didn't change anything in user settings
  )   


 (setq path (askForFile) )
 (setq coordinates (LoadPoints path) )
 (draw coordinates)

)

您必须知道这是基本的 "skeleton" 功能。您必须使用的主要功能是:

(getfiled ...) - 让你 select 文件

(setvar "OSMODE" 512) - 哪个make点就会上线

(command "_POINT" coordinates) 这将得出点 结果还将取决于文件中坐标的格式。预期是由 , 分隔的 2 或 3 个坐标,小数点应由 . 分隔我不记得了,但这可能取决于您的本地设置。