乐筑天下

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

[编程交流] Help with VBA-RUN

[复制链接]

76

主题

312

帖子

254

银币

后起之秀

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

铜币
390
发表于 2022-7-5 17:09:37 | 显示全部楼层 |阅读模式
Hello everybody,
 
Im quite new to LISP coding, and mostly i create the tools with copy-pasting and trial and error. tho the case below i cannot solve myself.
 
I want to command TESTLISP to reload a .lin and a .shx file. This is working.
Now i want to do a 'Layer change', where is replace the linetypes of all layers for other specified ones.
 
When i use the code below, the LISP doesnt run 'LAYERCHANGER'.
 
When i add 'C:' to make LAYERCHANGER a command for itself, then it WILL work. (Marked in red)
 
How can i merge the code from the LAYERCHANGER within the code of 'TESTLISP'.
 
Note: this is a part of a must lager code, but this is the only part thats failing.
 
Hope someone can help.
 
  1. (defun c:TESTLISP ()(princ "\nHB Huisstyle vervangen...")(princ)(setvar "CMDECHO" 0)(princ "\nAanpassen shape files...")(princ)(command "LOAD" "HBShapes.shx")(while (> (getvar"cmdactive") 0) (command ""))(princ "\nAanpassen linetype files...")(princ)(command "-linetype" "L" "*" "HBLinetypes.lin")(while (> (getvar"cmdactive") 0) (command ""))(princ "\nAanpassen linetypes van layers...")(princ)[b](vl-vbarun "LAYERCHANGER" )[/b](princ))(vl-load-com)(defun [color="red"]C:[/color]LAYERCHANGER (/ put_linetype linetypes ltyp ltyps)(vl-load-com)(or adoc (setq adoc (vla-get-activedocument (vlax-get-acad-object))))(setq linetypes (vla-get-linetypes adoc))(vlax-for ltyp (vla-get-linetypes adoc)(setq ltyps (cons (vla-get-name ltyp) ltyps)))(defun put_linetype (obj linetype linefile)(if (vl-position linetype ltyps)(vla-put-linetype obj linetype)(progn(vla-load linetypes linetype linefile)(setq ltyps (cons linetype ltyps))(vla-put-linetype lay linetype))))(vlax-for lay (vla-get-layers adoc)(cond ((wcmatch (setq ltyp (vla-get-linetype lay)) "PERSRIOOL1")(vla-put-linetype lay "PERSRIOOL"))((wcmatch (setq ltyp (vla-get-linetype lay)) "50-50")(put_linetype lay "50-50_200" "HBLinetypes.lin"))((wcmatch (setq ltyp (vla-get-linetype lay)) "100-100")(put_linetype lay "100-100_200" "HBLinetypes.lin"))((wcmatch (setq ltyp (vla-get-linetype lay)) "05-05_200")(put_linetype lay "50-50_200" "HBLinetypes.lin"))((wcmatch (setq ltyp (vla-get-linetype lay)) "05-05_500")(put_linetype lay "50-50_500" "HBLinetypes.lin"))((wcmatch (setq ltyp (vla-get-linetype lay)) "HBFENCELINE3")(put_linetype lay "FENCELINE3" "HBLinetypes.lin"))((wcmatch (setq ltyp (vla-get-linetype lay)) "HBFENCELINE4")(put_linetype lay "FENCELINE4" "HBLinetypes.lin"))((wcmatch (setq ltyp (vla-get-linetype lay)) "HBFENCELINE5")(put_linetype lay "FENCELINE5" "HBLinetypes.lin"))((wcmatch (setq ltyp (vla-get-linetype lay)) "HBFENCELINE6")(put_linetype lay "FENCELINE6" "HBLinetypes.lin"))((wcmatch (setq ltyp (vla-get-linetype lay)) "HBFENCELINE7")(put_linetype lay "FENCELINE7" "HBLinetypes.lin"))((wcmatch (setq ltyp (vla-get-linetype lay)) "HBFENCELINE8")(put_linetype lay "FENCELINE8" "HBLinetypes.lin"))((wcmatch (setq ltyp (vla-get-linetype lay)) "HBZIGZAG")(put_linetype lay "ZIGZAG" "HBLinetypes.lin"))((wcmatch (setq ltyp (vla-get-linetype lay)) "ACAD_ISO06W100")(put_linetype lay "ONDERZOEKSLOCATIE" "HBLinetypes.lin"))))(princ))
回复

使用道具 举报

18

主题

1529

帖子

973

银币

中流砥柱

Rank: 25

铜币
649
发表于 2022-7-5 17:23:19 | 显示全部楼层
Your question is somewhat strange since your code contains the solution to your problem.
 
This is how you call a Lisp function with 3 arguments:
  1. (put_linetype lay "50-50_200" "HBLinetypes.lin")
To call a Lisp function with 0 arguments you use:
  1. (LAYERCHANGER)
IMO you should move away from your current Copy-Paste approach and get better acquainted with the basics of the Lisp language.
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 17:25:23 | 显示全部楼层
Vbarun means that you want to run visual basic code not lisp.
 
  1. (vl-vbaload "P:/AutoDESK/VBA/Design Toolkit.dvb") (vl-vbarun "ToolKit")
回复

使用道具 举报

76

主题

312

帖子

254

银币

后起之秀

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

铜币
390
发表于 2022-7-5 17:32:41 | 显示全部楼层
I agree that i have to let go of my copy-past method. Tho i think its a good way to learn LISP by reading working code and trying to understand it.
But anyhow. What would be the correct way to let this LISP work?
 
The reason i want to call this part of code seperately, is because the LAYERCHANGER 'command' is going to be put in a whole list of commands that need to be exectued when i enter the command TESTLISP.
 
Thanks in advance.
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 17:43:18 | 显示全部楼层
Just re read the above because C:Layerchanger is a defun you need to call it the simple way as Roy_043 posted though you may need (c:layerchanger)
 
  1. old[b](vl-vbarun "LAYERCHANGER" )[/b]new[b](C:LAYERCHANGER)[/b][b]
回复

使用道具 举报

76

主题

312

帖子

254

银币

后起之秀

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

铜币
390
发表于 2022-7-5 17:52:59 | 显示全部楼层
Alright, i tried it the right way then.
But when i try to run TESTLISP, i get the message: 'error: no function definition: C:LAYERCHANGER'
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 17:55:19 | 显示全部楼层
There was some errors, missing ")" need to initialise list, did the same thing twice.
 
  1. (defun C:LAYERCHANGER (/ put_linetype linetypes ltyp ltyps)(vl-load-com)(IF (= adoc NIL) (setq adoc (vla-get-activedocument (vlax-get-acad-object))))(setq ltyps '() ) ; LIST OF NIL(vlax-for ltyp (vla-get-linetypes adoc)(setq ltyps (cons (vla-get-name ltyp) ltyps)))(c:Layerchanger)
回复

使用道具 举报

18

主题

1529

帖子

973

银币

中流砥柱

Rank: 25

铜币
649
发表于 2022-7-5 18:06:10 | 显示全部楼层
@BIGAL:
There is no need to initialize the ltyps list. It's value is already nil since it is a localized variable.
  1. (equal '() nil) => T
回复

使用道具 举报

76

主题

312

帖子

254

银币

后起之秀

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

铜币
390
发表于 2022-7-5 18:13:00 | 显示全部楼层
Thanks guys,
 
It seems like the piece of code BIGAL posted fixed the problem. :-)
I was also able to remove the 'C:' in both parts, so the command LAYERCHANGER cannot be executed from AutoCAD but only called by the lisp itself.
 
Thanks guys! :-)
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-13 08:46 , Processed in 0.501173 second(s), 70 queries .

© 2020-2025 乐筑天下

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