Aftertouch Posted October 3, 2016 Posted October 3, 2016 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) [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) ) Quote
Roy_043 Posted October 3, 2016 Posted October 3, 2016 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. Quote
BIGAL Posted October 4, 2016 Posted October 4, 2016 Vbarun means that you want to run visual basic code not lisp. (vl-vbaload "P:/AutoDESK/VBA/Design Toolkit.dvb") (vl-vbarun "ToolKit") Quote
Aftertouch Posted October 4, 2016 Author Posted October 4, 2016 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. Quote
BIGAL Posted October 5, 2016 Posted October 5, 2016 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 [b](vl-vbarun "LAYERCHANGER" )[/b] new [b](C:LAYERCHANGER)[/b] [b] [/b] Quote
Aftertouch Posted October 5, 2016 Author Posted October 5, 2016 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' Quote
BIGAL Posted October 5, 2016 Posted October 5, 2016 (edited) 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) Edited October 5, 2016 by BIGAL Quote
Roy_043 Posted October 5, 2016 Posted October 5, 2016 @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 Quote
Aftertouch Posted October 5, 2016 Author Posted October 5, 2016 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! :-) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.