Help with VBA-RUN
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.
(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)(vl-vbarun "LAYERCHANGER" )(princ))(vl-load-com)(defun C: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)) 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:
(put_linetype lay "50-50_200" "HBLinetypes.lin")To call a Lisp function with 0 arguments you use:
(LAYERCHANGER)IMO you should move away from your current Copy-Paste approach and get better acquainted with the basics of the Lisp language. Vbarun means that you want to run visual basic code not lisp.
(vl-vbaload "P:/AutoDESK/VBA/Design Toolkit.dvb") (vl-vbarun "ToolKit") 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. 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)
old(vl-vbarun "LAYERCHANGER" )new(C:LAYERCHANGER) 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' There was some errors, missing ")" need to initialise list, did the same thing twice.
(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) @BIGAL:
There is no need to initialize the ltyps list. It's value is already nil since it is a localized variable.
(equal '() nil) => T 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! :-)
页:
[1]