乐筑天下

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

[编程交流] 块的插入

[复制链接]

31

主题

107

帖子

76

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
155
发表于 2022-7-6 15:41:56 | 显示全部楼层
好我不知道是否有必要。
可以这样写吗:
 
(条件((路径1)
((路径2)
(以上代码都在这里)
(t(否则警报“请勿浏览”))
 
???
回复

使用道具 举报

31

主题

107

帖子

76

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
155
发表于 2022-7-6 15:45:35 | 显示全部楼层
 
cad说:
错误的函数:“K:\\CAD\\Block\\arrow”
 
我不知道为什么。。。
 
这是我试过的代码。。。
 
  1. (defun describe ()
  2. ;;;Do the mapcar function for each layer in the drawing.
  3. (vlax-for layer
  4.        (vla-get-layers
  5.          (vla-get-activedocument
  6.        (vlax-get-acad-object)
  7.        )
  8.          )
  9. ;;;if the current layer being checked matches a predetermined name, add the needed description.
  10.    (mapcar
  11.      (function
  12.    (lambda (layname description)
  13.      (if (= (strcase (vla-get-name layer)) (strcase layname))
  14.        (vla-put-description layer description)
  15.        ()
  16.        )
  17.      )
  18.    )
  19.      '("A-------O2-" ) ; This is your list of layers needing a description.
  20.      '("arrow"); This is the descriptions for each layer.  Make sure the order is EXACTLY the same as in the layer list.
  21.      )
  22.    )
  23. (princ); Silent exit.
  24. )
  25.    (defun layercreation ()
  26.        (if  (tblsearch "LAYER" "A-------O2-")
  27. (command "_layer" "s" "A-------O2-" "")
  28.            (command "-layer" "M" "A-------O2-" "C" "red" "A-------O2-" "")
  29.            ) ; end if
  30.           );en defun
  31. (defun c:test ( / sl oldlay)
  32. (setq path (strcat "K:\\CAD\\Block\\arrow"))
  33. (cond
  34. ((path)
  35.   (
  36. (setq oldlay (getvar "clayer"))
  37. (setq sl nil)
  38. (setq sl (dos_dwgpreview "Välj Block" "K:\\CAD\\Block\\arrow"))
  39. (prompt "\nChoose insertion point...")
  40. (if sl
  41.    (progn
  42.      (layercreation)
  43.      (describe)
  44.      (setvar "clayer" "A-------O2-")
  45.      (command "-insert" sl pause "1" "1" "0")
  46.    (setvar "clayer" oldlay)
  47. );progn
  48.    );if
  49. ))(t (exit)))
  50. )
回复

使用道具 举报

5

主题

194

帖子

193

银币

初来乍到

Rank: 1

铜币
24
发表于 2022-7-6 15:49:43 | 显示全部楼层
au-s公司
 
也许这样会有所帮助
 
  1. ;author        :        jammie
  2. ;version         :        0.0
  3. ;date                :        2009-02-12
  4. ;posted  : cadtutor.net
  5. ;thread : http://www.cadtutor.net/forum/newreply.php?do=newreply&noquote=1&p=212231
  6. (defun c:test (/ laycode lay_name fname oldlay path test)
  7. ;laycodes is a list of a drawing paths and layer names. Each list within laycodes is a pair  (<path> <layer name>)
  8. ;The first element is the block path. The second element is the layer name associated with the block
  9. ;Any blocks found to come from a particular path will be inserted on a preset layer
  10. ;
  11. ;eg
  12. ;("K:\\CAD\\Block\\arrow"         "A-------O2-")
  13. ;A block inserted from "K:\\CAD\\Block\\arrow" will be inserted on layer "A-------O2-"
  14. ;
  15. ;Note the path is case sensitive
  16. (setq laycodes '(
  17.                  ("K:\\CAD\\Block\\arrow"         "A-------O2-");<-edit this list as required
  18.                  ("K:\\CAD\\Block\\cars"         "A-------O1-")
  19.                                           )
  20.       )
  21.         (if
  22.   ;select the drawing to insert
  23.   (and (setq fname (dos_dwgpreview  "Välj Block" "K:\\CAD\\Block\"  ".dwg")) (/= fname ""))
  24.   ;if a file has been selected
  25.   (progn
  26.     ;store the current layer
  27.     (setq oldlay   (getvar "clayer"))
  28.     ;retrieve the path
  29.     (setq path     (vl-filename-directory fname))
  30.     (if
  31.         ;check the path against the laycodes
  32.               (setq test (assoc path laycodes))
  33.               ;if a match is found
  34.       
  35.               (or
  36.           ;test if the preset layer exists
  37.           (tblsearch "layer" (setq lay_name (cadr test)))
  38.            ;if it does not add it
  39.           (command "layer" "m" lay_name ""))
  40.       ;if the file does not match the predefined
  41.       
  42.             (alert
  43.               (strcat "\n<" (vl-filename-base fname) "> is not from a preset directory"
  44.                       " \nValid directories are :"
  45.                       (apply 'strcat (mapcar '(lambda (x) (strcat "\n\t" (car x))) laycodes))
  46.                       "\nBlock <" (vl-filename-base fname) "> will be inserted on layer <" (getvar "clayer")">")))
  47.       
  48.    
  49.     (and lay_name (setvar "clayer" lay_name))
  50.     (command "-insert" fname pause "1" "1" "0")
  51.    
  52.     (and lay_name  (setvar "clayer" oldlay))
  53.     )
  54.   (alert "\nNo file selected")
  55.   )
  56. (princ)
  57. )

 
并添加了修改的layercreation行:
  1. (defun c:test (/ laycode lay_name fname oldlay path test)
  2. ;laycodes is a list of a drawing paths, layer names and preset colors.
  3. ;Each list within laycodes contains 3 elements  (<path> <layer name> <layer color>)
  4. ;The first element is the block path.
  5. ;The second element is the layer name associated with the block
  6. ;The third item in a list references the layer color
  7. ;Any blocks found to come from a particular path will be inserted on a preset layer
  8. ;If the layer does not exist it will be created and a layer color assigned to ir
  9. ;
  10. ;eg
  11. ;("K:\\CAD\\Block\\arrow"         "A-------O2-"   1)
  12. ;A block inserted from "K:\\CAD\\Block\\arrow" will be inserted on layer "A-------O2-" which has a color 1
  13. ;
  14. ;Note the path is case sensitive
  15. (setq laycodes '(
  16.                  ("K:\\CAD\\Block\\arrow"         "A-------O2-"  1);<-edit this list as required
  17.                  ("K:\\CAD\\Block\\cars"         "A-------O1-"  140)
  18.                                           )
  19.       )
  20.         (if
  21.   ;select the drawing to insert
  22.   (and (setq fname (dos_dwgpreview  "Välj Block" "K:\\CAD\\Block\"  ".dwg")) (/= fname ""))
  23.   ;if a file has been selected
  24.   (progn
  25.     ;store the current layer
  26.     (setq oldlay   (getvar "clayer"))
  27.     ;retrieve the path
  28.     (setq path     (vl-filename-directory fname))
  29.     (if
  30.         ;check the path against the laycodes
  31.               (setq test (assoc path laycodes))
  32.               ;if a match is found
  33.       
  34.               (or
  35.           ;test if the preset layer exists
  36.           (tblsearch "layer" (setq lay_name (cadr test)))
  37.            ;if it does not add it
  38.           (and
  39.             (command "layer" "m" lay_name "")
  40.             (command "layer" "c" (caddr test) lay_name "" "" );<-line added to change the layer to the required color
  41.             )
  42.           )
  43.       ;if the file does not match the predefined
  44.       
  45.             (alert
  46.               (strcat "\n<" (vl-filename-base fname) "> is not from a preset directory"
  47.                       " \nValid directories are :"
  48.                       (apply 'strcat (mapcar '(lambda (x) (strcat "\n\t" (car x))) laycodes))
  49.                       "\nBlock <" (vl-filename-base fname) "> will be inserted on layer <" (getvar "clayer")">")))
  50.       
  51.    
  52.     (and lay_name (setvar "clayer" lay_name))
  53.     (command "-insert" fname pause "1" "1" "0")
  54.    
  55.     (and lay_name  (setvar "clayer" oldlay))
  56.     )
  57.   (alert "\nNo file selected")
  58.   )
  59. (princ)
  60. )
回复

使用道具 举报

31

主题

107

帖子

76

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
155
发表于 2022-7-6 15:53:15 | 显示全部楼层
回复

使用道具 举报

5

主题

194

帖子

193

银币

初来乍到

Rank: 1

铜币
24
发表于 2022-7-6 15:57:35 | 显示全部楼层
Your welcome,
 
I was actually a little intrigued by DOSLIB as I had never heard of it before!
 
 
Try the revised version of the code, it only needed a small change.
 
Just add the preset layer color after layer name in each element of the layercodes
 
 

[code](defun c:test (/ laycode lay_name fname oldlay path test);laycodes is a list of a drawing paths, layer names and preset colors.;Each list within laycodes contains 3 elements  (  );The first element is the block path.;The second element is the layer name associated with the block;The third item in a list references the layer color ;Any blocks found to come from a particular path will be inserted on a preset layer;If the layer does not exist it will be created and a layer color assigned to ir;;eg;("K:\\CAD\\Block\\arrow"         "A-------O2-"   1);A block inserted from "K:\\CAD\\Block\\arrow" will be inserted on layer "A-------O2-" which has a color 1;;Note the path is case sensitive (setq laycodes '(                 ("K:\\CAD\\Block\\arrow"         "A-------O2-"  1);
回复

使用道具 举报

31

主题

107

帖子

76

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
155
发表于 2022-7-6 15:59:46 | 显示全部楼层
Yes ...
I was looking into tool palletes.
problem is .. that in this office all architects or 90% of them use 19 inch screens.
With couple of toolpalletes it really require some screen.space.
besides I do not know how they work from a network server.
I tried once and I had bad experiance.
But maybe I did not try enough
 
Thanx Sir!
回复

使用道具 举报

31

主题

107

帖子

76

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
155
发表于 2022-7-6 16:03:41 | 显示全部楼层
Hmm...
It inserts still in color  (white)
回复

使用道具 举报

48

主题

1073

帖子

1043

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
238
发表于 2022-7-6 16:07:58 | 显示全部楼层
I have my palettes set to AutoHide. That way they only take up a thin strip on the side of the screen. 
The palette is just a place holder for the block not a container. You can drag a block from a drawing onto the palette. Then when you drag a block from that palette AutoCAD goes and gets the block definition from the drawing you used to create the block. That is why I have a few drawings in our symbols folder that contain the blocks I want. If I need to update a block it can be done in one drawing that is under my control, not a project specific GA that somebody else could modify. Also my drawing will not get renamed or moved - a real problem to palettes if the source file ceases to exist.
回复

使用道具 举报

31

主题

107

帖子

76

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
155
发表于 2022-7-6 16:11:19 | 显示全部楼层
ah its working now ...
 
I deleted this :
  1. (command "layer" "c" (caddr test) lay_name "" )
 
and added modified the layercreation line:
  1. (command "layer" "m" lay_name "c" (caddr test) lay_name "")
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-4 19:37 , Processed in 0.482282 second(s), 68 queries .

© 2020-2025 乐筑天下

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