乐筑天下

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

[编程交流] Auto-Dimension-Update LISP

[复制链接]

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 07:08:12 | 显示全部楼层
 
Wow! This is an old thread - this takes me back to when I first started with LISP.... embarassing times
 
I'll take a look over the code when I get a minute Glen
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 07:10:58 | 显示全部楼层
Give this a shot Glen, perhaps slightly overkill but oh well:
 
  1. (defun c:DimUpd ( / *error* _StartUndo _EndUndo DimLayer DimStyle doc lck ss ) (vl-load-com) ;; © Lee Mac 2010 [color=red][b](setq DimLayer "Dims" DimStyle "Standard")[/b][/color] (defun *error* ( msg )      (if lck (LM:RelockLayers lck))   (if doc (_EndUndo doc))      (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")       (princ (strcat "\n** Error: " msg " **")))   (princ) ) (defun _StartUndo ( doc ) (_EndUndo doc)   (vla-StartUndoMark doc) ) (defun _EndUndo ( doc )   (if (= 8 (logand 8 (getvar 'UNDOCTL)))     (vla-EndUndoMark doc)   ) ) (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))) (or (tblsearch "LAYER" DimLayer)     (vla-Add (vla-get-Layers doc) DimLayer) ) (or (tblsearch "DIMSTYLE" DimStyle)     (vla-Add (vla-get-DimStyles doc) DimStyle) ) (if (ssget "_X" '((0 . "*LEADER,*DIMENSION")))   (progn     (_StartUndo doc) (setq lck (LM:UnlockLayers doc))     (vlax-for obj (setq ss (vla-get-ActiveSelectionSet doc))       (vl-catch-all-apply         (function           (lambda nil             (mapcar               (function                 (lambda ( p v ) (vlax-put-property obj p v))               )              '(Layer Stylename)               (list DimLayer DimStyle)             )           )         )       )     )     (vla-delete ss)     (LM:RelockLayers lck) (_EndUndo doc)    ) ) (princ))         ;;------------------=={ Unlock Layers }==---------------------;;;;                                                            ;;;;  Unlocks all layers in the supplied Document Object and    ;;;;  returns a list of those which were locked                 ;;;;------------------------------------------------------------;;;;  Author: Lee Mac, Copyright © 2010 - www.lee-mac.com       ;;;;------------------------------------------------------------;;;;  Arguments:                                                ;;;;  doc - VLA Document Object                                 ;;;;------------------------------------------------------------;;;;  Returns:  list of previously locked VLA Layer Objects     ;;;;------------------------------------------------------------;;(defun LM:UnlockLayers ( doc / r ) (vlax-for l (vla-get-layers doc)   (if (eq :vlax-true (vla-get-lock l))     (vla-put-lock (car (setq r (cons l r))) :vlax-false)   ) ) (reverse r));;-------------------=={ ReLock Layers }==--------------------;;;;                                                            ;;;;  Locks all layers in the supplied list                     ;;;;------------------------------------------------------------;;;;  Author: Lee Mac, Copyright © 2010 - www.lee-mac.com       ;;;;------------------------------------------------------------;;;;  Arguments:                                                ;;;;  lst - list of VLA Layer Objects                           ;;;;------------------------------------------------------------;;(defun LM:ReLockLayers ( lst ) (mapcar '(lambda ( l ) (vla-put-lock l :vlax-true)) lst))
回复

使用道具 举报

54

主题

3755

帖子

3583

银币

后起之秀

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

铜币
438
发表于 2022-7-6 07:15:16 | 显示全部楼层
What's the point of the following? If the DimStyle doesn't exist, I would rather be informed than just have a generic one created. The user will the be forced to overwrite the dimstyle to get their desired/correct one.
  1.   (or (tblsearch "DIMSTYLE" DimStyle)     (vla-Add (vla-get-DimStyles doc) DimStyle) )
回复

使用道具 举报

1

主题

6

帖子

5

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 07:18:05 | 显示全部楼层
after testing I just noticed that as well, one option that I might want is to set a new dimstyle and all the variables as per our new standards, that way all old dwg's would be updated.
 
Glen
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 07:18:38 | 显示全部楼层
Fair points, I guess this would be better:
 

[code](defun c:DimUpd ( / *error* _StartUndo _EndUndo DimLayer DimStyle doc lck ss ) (vl-load-com) ;; © Lee Mac 2010 (setq DimLayer "Dims" DimStyle "Standard") (defun *error* ( msg )      (if lck (LM:RelockLayers lck))   (if doc (_EndUndo doc))      (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")       (princ (strcat "\n** Error: " msg " **")))   (princ) ) (defun _StartUndo ( doc ) (_EndUndo doc)   (vla-StartUndoMark doc) ) (defun _EndUndo ( doc )   (if (= 8 (logand 8 (getvar 'UNDOCTL)))     (vla-EndUndoMark doc)   ) ) (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))) (or (tblsearch "LAYER" DimLayer)     (vla-Add (vla-get-Layers doc) DimLayer) ) (if (tblsearch "DIMSTYLE" DimStyle)   (if (ssget "_X" '((0 . "*LEADER,*DIMENSION")))     (progn       (_StartUndo doc) (setq lck (LM:UnlockLayers doc))       (vlax-for obj (setq ss (vla-get-ActiveSelectionSet doc))         (vl-catch-all-apply           (function             (lambda nil               (mapcar                 (function                   (lambda ( p v ) (vlax-put-property obj p v))                 )                '(Layer Stylename)                 (list DimLayer DimStyle)               )             )           )         )       )       (vla-delete ss)       (LM:RelockLayers lck) (_EndUndo doc)      )   )   (princ "\n--> Dimension Style not Present
回复

使用道具 举报

54

主题

3755

帖子

3583

银币

后起之秀

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

铜币
438
发表于 2022-7-6 07:23:24 | 显示全部楼层
That makes a lot more sense.
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 07:25:23 | 显示全部楼层
 
Excellent
回复

使用道具 举报

54

主题

3755

帖子

3583

银币

后起之秀

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

铜币
438
发表于 2022-7-6 07:29:39 | 显示全部楼层
Just trying to avoid creating issues for the people using this.
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 07:33:05 | 显示全部楼层
 
Good on you.
回复

使用道具 举报

54

主题

3755

帖子

3583

银币

后起之秀

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

铜币
438
发表于 2022-7-6 07:35:30 | 显示全部楼层
Yup.
.......
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-10 18:24 , Processed in 0.465383 second(s), 70 queries .

© 2020-2025 乐筑天下

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