【问题标题】:AutoLISP getting a National Grid Reference from a PostcodeAutoLISP 从邮政编码获取国家网格参考
【发布时间】:2023-02-07 07:54:09
【问题描述】:

我想在 CAD 中制作一个脚本,它将返回国家电网参考并输入邮政编码

例如 用户输入:AL1 1BY 退货:TL 14584 06989

我从操作系统“CodePoint - Open”获得了一个 CSV,它提供邮政编码、东距、北距、纬度和经度,可用于获取部分网格参考,但获取前 2 个字母“TL”是主要问题因为 csv 不提供这个,我不确定这是如何计算的。

我考虑过使用邮政编码制作多个 CSV(AL.csv、DN.csv、SL.csv ...),例如将网格参考链接到

铝.csv

AL1 1BY TL 14584 06989

AL1 1DQ TL 14524 06737

但这会导致速度阅读超过 10,000 行以上的问题吗?

我还想知道是否可以使用 AutoLisp 实现 API 调用以使用邮政编码转换为 NGR 代码,但这不是我以前做过的事情或者不知道它是否可能?

我没有把任何东西放在适当的位置,因为我正在努力思考实现它的最佳方法是什么。

【问题讨论】:

    标签: autocad cad autolisp bricscad


    【解决方案1】:

    我没有阅读 10,000 多行代码,但您可以调整下面的代码,以便 DraftSight 在第一次扫描后记住它读取的内容。如果您需要 autolisp 函数的源代码,请查看 here

    (defun C:Test01 (/ sFile FileID sLine sDelimiter lDetails sInfo *lPostCodes*)
    
        ;; Constant
        (setq sDelimiter " "); "	" for tab deliminator
    
        ;; Manual File Path
        (setq sFile (getfiled "Select a file" "" "csv" 0))
    
        ; ;; Automatic file path
        ; (setq sFile "[Drive letter]:\[File path]\[File name.extension]")
        ; (setq sFile (findfile sFile))
    
        ;; Reading the file
        (setq FileID (open sFile "r"))
        (while (setq sLine (read-line FileID))
            
            ;; Reading contents
            (setq sInfo "")
            (while (> (strlen sLine) 0)
                (if (= (substr sLine 1 1) sDelimiter)
                    (progn ;; True
                        (if (> (strlen sInfo) 0)(setq lDetails (cons sInfo lDetails)))
                        (setq sInfo "")
                    );progn ; True
                    ;; False
                    (setq sInfo (strcat sInfo (substr sLine 1 1)))
                );if
                (setq sLine (substr sLine 2)); next character
            );while - Each character
            (if (/= (car lDetails) sInfo)(setq lDetails (cons sInfo lDetails)))
    
            ;; Updating list
            (setq lDetails (reverse lDetails))
            (setq *lPostCodes* (cons lDetails *lPostCodes*))
            (setq lDetails (list))
        );while - Each line
        
        ;; Closing the file
        (close FileID)
    
        ;; Returning value
        (setq *lPostCodes* (reverse *lPostCodes*))
        (princ "
    Results : ")(prin1 *lPostCodes*)(terpri)(princ)
    );C:Test01
    
    Command: TEST01
    Results : (("AL1" "1BY" "TL" "14584" "06989") ("AL1" "1DQ" "TL" "14524" "06737"))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-15
      • 2017-10-22
      • 1970-01-01
      • 1970-01-01
      • 2018-10-20
      • 1970-01-01
      • 1970-01-01
      • 2014-01-27
      相关资源
      最近更新 更多