乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
楼主: woodman78

[编程交流] 带d的力层平移

[复制链接]

11

主题

968

帖子

919

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
99
发表于 2022-7-6 09:55:38 | 显示全部楼层
这是我提到的主要问题:即,我的代码仅从标准线型集中加载/重新加载线型。如果源DWG包含任何特殊(自定义)线型,则这些线型将仅作为连续线型放置。在这种情况下,Lee的代码工作得更好,尽管Lee的代码没有重新加载/重新定义图层和线型-只导入新的。
 
正如我提到的那样,我遇到了一个可能的解决方案,但必须重新开始。
回复

使用道具 举报

145

主题

590

帖子

446

银币

中流砥柱

Rank: 25

铜币
725
发表于 2022-7-6 09:59:58 | 显示全部楼层
irneb,
 
我已经试着整合你的代码,但我似乎无法让它工作。这就是我所拥有的。你能看一下吗?
  1. (defun c:survey_transform ()
  2.    ; First construct our entity list
  3.    (setq vl1 (list
  4.        (cons 0 "LAYER")        ;Name of entity
  5.        (cons 100 "AcDbSymbolTableRecord")                    ;Open Records
  6.        (cons 100 "AcDbLayerTableRecord")                    ;Locate Layer Table
  7.        (cons 2 "CCC_SURVEY_EXISTING_Feature")                ;Name of Layer
  8.        (cons 6 "Continuous")                        ;Linetype
  9.        (cons 62 150)                            ;colour = light grey
  10.        (cons 70 0)                            ;state
  11.        (cons 290 1)                            ;1=plot, 0=Don't plot
  12.            )                            ;End of entity list
  13.        )
  14.        (entmake vl1)
  15.    (setq vl1 (list
  16.        (cons 0 "LAYER")        ;Name of entity
  17.        (cons 100 "AcDbSymbolTableRecord")                    ;Open Records
  18.        (cons 100 "AcDbLayerTableRecord")                    ;Locate Layer Table
  19.        (cons 2 "CCC_SURVEY_EXISTING_Number")                ;Name of Layer
  20.        (cons 6 "Continuous")                        ;Linetype
  21.        (cons 62 1)                            ;colour = light grey
  22.        (cons 70 0)                            ;state
  23.        (cons 290 1)                            ;1=plot, 0=Don't plot
  24.            )                            ;End of entity list
  25.        )
  26.        (entmake vl1)
  27.    (setq vl1 (list
  28.        (cons 0 "LAYER")        ;Name of entity
  29.        (cons 100 "AcDbSymbolTableRecord")                    ;Open Records
  30.        (cons 100 "AcDbLayerTableRecord")                    ;Locate Layer Table
  31.        (cons 2 "CCC_SURVEY_EXISTING_Level")                ;Name of Layer
  32.        (cons 6 "Continuous")                        ;Linetype
  33.        (cons 62 84)                            ;colour = light grey
  34.        (cons 70 0)                            ;state
  35.        (cons 290 1)                            ;1=plot, 0=Don't plot
  36.            )                            ;End of entity list
  37.        )
  38.        (entmake vl1)
  39.    (setq vl1 (list
  40.        (cons 0 "LAYER")        ;Name of entity
  41.        (cons 100 "AcDbSymbolTableRecord")                    ;Open Records
  42.        (cons 100 "AcDbLayerTableRecord")                    ;Locate Layer Table
  43.        (cons 2 "CCC_SURVEY_Level")                    ;Name of Layer
  44.        (cons 6 "Continuous")                        ;Linetype
  45.        (cons 62 84)                            ;colour = light grey
  46.        (cons 70 0)                            ;state
  47.        (cons 290 1)                            ;1=plot, 0=Don't plot
  48.            )                            ;End of entity list
  49.        )
  50.        (entmake vl1)
  51.    (setq vl1 (list
  52.        (cons 0 "LAYER")        ;Name of entity
  53.        (cons 100 "AcDbSymbolTableRecord")                    ;Open Records
  54.        (cons 100 "AcDbLayerTableRecord")                    ;Locate Layer Table
  55.        (cons 2 "CCC_SURVEY_Number")                    ;Name of Layer
  56.        (cons 6 "Continuous")                        ;Linetype
  57.        (cons 62 1)                            ;colour = light grey
  58.        (cons 70 0)                            ;state
  59.        (cons 290 1)                            ;1=plot, 0=Don't plot
  60.            )                            ;End of entity list
  61.        )
  62.        (entmake vl1)
  63.    ; First construct our entity list
  64.    (setq vl1 (list
  65.        (cons 0 "LAYER")        ;Name of entity
  66.        (cons 100 "AcDbSymbolTableRecord")                    ;Open Records
  67.        (cons 100 "AcDbLayerTableRecord")                    ;Locate Layer Table
  68.        (cons 2 "CCC_SURVEY_Feature")            ;Name of Layer
  69.        (cons 6 "Continuous")                        ;Linetype
  70.        (cons 62 150)                            ;colour = light grey
  71.        (cons 70 0)                            ;state
  72.        (cons 290 1)                            ;1=plot, 0=Don't plot
  73.            )                            ;End of entity list
  74.        )
  75.        (entmake vl1)
  76. (and (setq ss (ssget "X" '((8 . "*CODE"))))
  77.     (command "_.CHPROP" ss "" "_LA" "CCC_SURVEY_EXISTING_Feature" ""))
  78. (and (setq ss (ssget "X" '((8 . "*ID"))))
  79.     (command "_.CHPROP" ss "" "_LA" "CCC_SURVEY_EXISTING_Number" ""))
  80. (and (setq ss (ssget "X" '((8 . "*_Z"))))
  81.     (command "_.CHPROP" ss "" "_LA" "CCC_SURVEY_EXISTING_Level" ""))
  82. (and (setq ss (ssget "X" '((8 . "*Points"))))
  83.     (command "_.CHPROP" ss "" "_LA" "CCC_SURVEY_EXISTING_Level" ""))
  84. (and (setq text1(ssget "x" (list '(0 . "TEXT") (cons 62 70))))
  85.    (command "_.CHPROP" TEXT1 "" "_LA" "CCC_SURVEY_Level" ""))
  86. (and (setq text2(ssget "x" (list '(0 . "TEXT") (cons 62 12))))
  87.    (command "_.CHPROP" TEXT2 "" "_LA" "CCC_SURVEY_Number" ""))   
  88. (and (setq text3(ssget "x" (list '(0 . "TEXT") (cons 62 152))))
  89.    (command "_.CHPROP" TEXT3 "" "_LA" "CCC_SURVEY_Feature" ""))
  90. (and (setq ss (ssget "X" (list (cons 0 "INSERT") (cons 62 70))))
  91.     (command "_.CHPROP" ss "" "_LA" "CCC_SURVEY_Level" ""))
  92. (and (setq ss (ssget "X" (list (cons 0 "INSERT") (cons 62 12))))
  93.     (command "_.CHPROP" ss "" "_LA" "CCC_SURVEY_Number" ""))
  94. (and (setq ss (ssget "X" (list (cons 0 "INSERT") (cons 62 152))))
  95.     (command "_.CHPROP" ss "" "_LA" "CCC_SURVEY_Feature" ""))
  96. (command "_.CHPROP" "all" "" "C" "BYLAYER" "")
  97. (command "_.-layer" "_C" "84" "CCC_SURVEY_Level" "_C" "150" "CCC_SURVEY_Feature" "" )
  98. (ImportLayers "T:\\Drawing Tools\\AutoCad 2010_WARNING_Do Not Modify\\CCC_Survey.dwt" T T)
  99. (command "_-purge" "a" "*" "N")
  100. (princ)
  101. )
  102. ;;; -------------------------------------------------------------------------------------
  103. ;;; Global var to hold last used source drawing
  104. ;;; -------------------------------------------------------------------------------------
  105. (setq *ImportLayersFrom* "T:\\Drawing Tools\\AutoCad 2010_WARNING_Do Not Modify\\CCC_Survey.dwt")
  106. ;;; -------------------------------------------------------------------------------------
  107. ;;; Command to match the current drawing's layers to a specified DWG file
  108. ;;; -------------------------------------------------------------------------------------
  109. (defun ImportLayers (/ ans fn update import)
  110. ;(setq *ImportLayersFrom* "T:\\Drawing Tools\\AutoCad 2010_WARNING_Do Not Modify\\CCC_Survey.dwt")
  111. (if (not (setq fn *ImportLayersFrom*))
  112.    (setq fn (if (and (= (getvar "FILEDIA") 1) (= (logand (getvar "CMDACTIVE") 4) 0))
  113.               (getfiled "Select source drawing" (getvar "DWGPREFIX") "dwg" (+ 4 8 16))
  114.               (getstring "\nSource DWG path: ")
  115.             )
  116.    )
  117. )
  118. (if (setq fn (findfile fn))
  119.    (progn
  120.      (setq *ImportLayersFrom* fn)
  121.      (princ (strcat "\nLoading from Source: " fn))
  122.      (while (progn
  123.               (princ (strcat "\nExisting layers will"
  124.                              (if update
  125.                                ""
  126.                                " NOT"
  127.                              )
  128.                              " be Updated; Linetypes will"
  129.                              (if import
  130.                                ""
  131.                                " NOT"
  132.                              )
  133.                              " be Improted"
  134.                      )
  135.               )
  136.               (initget "Source Update Import Run Cancel")
  137.               (and (setq ans (getkword "\n[source/Update/Import/Run/Cancel] <Run>: "))
  138.                    (not (wcmatch ans "Run,Cancel"))
  139.               )
  140.             )
  141.        (cond
  142.          ((eq ans "Update") (setq update (not update)))
  143.          ((eq ans "Import") (setq import (not import)))
  144.          ((and (eq ans "Source")
  145.                (setq fn (if (and (= (getvar "FILEDIA") 1) (= (logand (getvar "CMDACTIVE") 4) 0))
  146.                           (getfiled "Select source drawing" (vl-filename-directory fn) "dwg" (+ 4 8 16))
  147.                           (getstring "\nSource DWG path: ")
  148.                         )
  149.                )
  150.           )
  151.           (if (setq fn (findfile fn))
  152.             (setq *ImportLayersFrom* fn)
  153.             (progn
  154.               (print (strcat fn " could not be found."))
  155.               (setq fn *ImportLayersFrom*)
  156.             )
  157.           )
  158.          )
  159.        )
  160.      )
  161.      (if (not (eq ans "Cancel"))
  162.        (ImportLayers fn update import)
  163.      )
  164.    )
  165. )
  166. (princ)
  167. )
  168. ;;; -------------------------------------------------------------------------------------
  169. ;;; Function to match the current drawing's layers to a specified DWG file
  170. ;;; -------------------------------------------------------------------------------------
  171. ;;; Arguments:
  172. ;;; fn     : File name (incl. path) of source DWG
  173. ;;; update : T to change existing layer to match, else nil
  174. ;;; ltypes : T to import linetypes if not existing, else nil
  175. ;;; -------------------------------------------------------------------------------------
  176. ;;; Result : T if done, nil if failed
  177. ;;; -------------------------------------------------------------------------------------
  178. (defun ImportLayers (fn update ltypes / dbx1 complete dbxLayers dbxLay Lay val)
  179. (setq complete nil)
  180. (if (setq dbx (vla-GetInterfaceObject
  181.                  (vlax-get-acad-object)
  182.                  (strcat "ObjectDBX.AxDbDocument." (itoa (atoi (getvar "ACADVER"))))
  183.                )
  184.      )
  185.    (progn
  186.      (if (not
  187.            (vl-catch-all-error-p (vl-catch-all-apply 'vlax-invoke (list dbx 'open fn)))
  188.          )
  189.        (progn
  190.          ;; Ensure all vla objects for current dwg
  191.          (or *acad* (setq *acad* (vlax-get-acad-object)))
  192.          (or *doc* (setq *doc* (vla-get-ActiveDocument *acad*)))
  193.          (or *layers* (setq *layers* (vla-get-Layers *doc*)))
  194.          (or *linetypes* (setq *linetypes* (vla-get-LineTypes *doc*)))
  195.          ;; Step through all layers of source dwg
  196.          (setq dbxLayers (vla-get-Layers dbx))
  197.          (vlax-for dbxLay dbxLayers
  198.            (if (vl-catch-all-error-p
  199.                  (setq Lay (vl-catch-all-apply 'vla-Item (list *layers* (vla-get-Name dbxLay))))
  200.                )
  201.              (setq Lay (vla-Add *layers* (vla-get-Name dbxLay))) ;Create if not existing
  202.              (if (not update)
  203.                (setq Lay nil)
  204.              ) ;Only continue if updating layers as well
  205.            )
  206.            (if Lay
  207.              (progn
  208.                ;; Match description
  209.                (if (not
  210.                      (vl-catch-all-error-p (setq val (vl-catch-all-apply 'vla-get-Description (list dbxLay))))
  211.                    )
  212.                  (vla-put-Description Lay val)
  213.                )
  214.                ;; Match Plottable
  215.                (if (not
  216.                      (vl-catch-all-error-p (setq val (vl-catch-all-apply 'vla-get-Plottable (list dbxLay))))
  217.                    )
  218.                  (vla-put-Plottable Lay val)
  219.                )
  220.                ;; Match ViewportDefault
  221.                (if (not
  222.                      (vl-catch-all-error-p
  223.                        (setq val (vl-catch-all-apply 'vla-get-ViewportDefault (list dbxLay)))
  224.                      )
  225.                    )
  226.                  (vla-put-ViewportDefault Lay val)
  227.                )
  228.                ;; Match LineWeight
  229.                (if (not
  230.                      (vl-catch-all-error-p (setq val (vl-catch-all-apply 'vla-get-LineWeight (list dbxLay))))
  231.                    )
  232.                  (vla-put-LineWeight Lay val)
  233.                )
  234.                ;; Match colour
  235.                (if (not
  236.                      (vl-catch-all-error-p (setq val (vl-catch-all-apply 'vla-get-TrueColor (list dbxLay))))
  237.                    )
  238.                  (vla-put-TrueColor Lay val)
  239.                )
  240.                ;; Match linetype
  241.                (if (not
  242.                      (vl-catch-all-error-p (setq val (vl-catch-all-apply 'vla-get-LineType (list dbxLay))))
  243.                    )
  244.                  (if (or (tblsearch "LTYPE" val)
  245.                          (and ltypes ;Load linetype if not existing
  246.                               (not (vl-catch-all-error-p
  247.                                      (vl-catch-all-apply
  248.                                        'vla-Load
  249.                                        (list *linetypes*
  250.                                              val
  251.                                              (if (= (getvar "MEASUREMENT") 0)
  252.                                                "acad.lin"
  253.                                                "acadiso.lin"
  254.                                              )
  255.                                        )
  256.                                      )
  257.                                    )
  258.                               )
  259.                          )
  260.                      )
  261.                    (vla-put-LineType Lay val)
  262.                  )
  263.                )
  264.              )
  265.            )
  266.          )
  267.          (setq complete T)
  268.        )
  269.      )
  270.      (vlax-release-object dbx)
  271.    )
  272. )
  273. complete
  274. )
回复

使用道具 举报

11

主题

968

帖子

919

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
99
发表于 2022-7-6 10:03:34 | 显示全部楼层
我最初的代码是一个命令,而不是一个lisp可调用函数。因此,您不需要将原来的c:ImportLayersFrom重命名为ImportLayersFrom,请看最后,defun已经存在了。虽然这不会引起问题,因为最后一个应该在第一个加载。
 
你能说明你收到了什么错误信息吗?这个消息什么时候出现?加载lisp或运行survey\u transform命令时?你试过在VLIDE中调试吗?我通常会一步一步地检查lisp中的每一行,看看它在做什么,这是我在试图通过打开break-on-error来找到错误位置后做的第二件事。
回复

使用道具 举报

145

主题

590

帖子

446

银币

中流砥柱

Rank: 25

铜币
725
发表于 2022-7-6 10:06:00 | 显示全部楼层
这是我在将代码切换回c:ImportLayersFrom时遇到的错误
 
  1. Command: survey_transform
  2. Initializing...
  3. Initializing...
  4. Initializing...
  5. Initializing...
  6. Initializing...
  7. Initializing...
  8. Initializing...
  9. Initializing...
  10. Initializing...
  11. Initializing...
  12. Initializing...
  13. Initializing...

 
它一直在继续!!!!
回复

使用道具 举报

11

主题

968

帖子

919

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
99
发表于 2022-7-6 10:07:20 | 显示全部楼层
你在执行自动加载吗?“初始化…”信息来自这类事情。如果只加载LSP文件,会发生什么?通过(load“Path/LispfileName.LSP”)或使用AppLoad,或者最好通过VLIDE。我的代码中没有任何地方显示“正在初始化…”。
 
我刚刚试着把它装在我的VLIDE上:
Lisp控制台中的消息是:
然后在ACad的命令行中输入命令:
  1. 7
尽管它失败了,因为我在该路径中没有DWT。
 
顺便说一句,您根本不需要在代码中使用c:ImportLayers-defun,您可以完全取消它。您只使用了最后一个ImportLayers defun。
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 10:10:50 | 显示全部楼层
这听起来很像。
回复

使用道具 举报

145

主题

590

帖子

446

银币

中流砥柱

Rank: 25

铜币
725
发表于 2022-7-6 10:17:10 | 显示全部楼层
这就是我现在拥有的。在阅读了LeeMac的链接后,我将子函数名更改为ImportLayers01,并认为这可以解决问题。当我打开一个绘图并尝试从ribbon运行lisp时,我得到了初始化。。。错误,但如果我执行appload,然后运行它,效果很好。有什么想法吗?
 
  1. 8
回复

使用道具 举报

11

主题

968

帖子

919

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
99
发表于 2022-7-6 10:20:25 | 显示全部楼层
如果使用功能区,则会出现初始化错误。功能区中的宏是否只是发出survey\u transform命令?一、 e.你已经在某个自动加载的地方设置了它(ACADDOC.LSP/Menu.MNL/etc)?如果是这样,那么李指出的联系就是出了什么问题。如果您无法修复它,那么还有其他一些可行的选择:
 
将普通(加载“LispfileNameAndPath”)添加到ACADDOC。LSP或菜单。MNL;或
将此类代码添加到按钮的宏中;或
将LSP文件添加到您的启动套件中;或
 
那个自动加载的东西有一些问题,例如,你不能在一个普通的lisp函数上自动加载(只有lisp命令)。如果LSP文件中有错误或者你的设置中有其他错误,它会无限循环这个初始化错误。由于这些原因,我实际上为自己重新编写了autoload,但这已经超出了本文的主题。
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-7 03:13 , Processed in 1.503593 second(s), 66 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表