antoniusxylem Posted September 19, 2017 Share Posted September 19, 2017 (edited) Problem I have 13 floors when and I have options that I need to work when changing xref paths. I can do 2 floors with the initget "1 2" but I cant seem to get this to work with more than 2 floors. Please help, Thanks in advance. The routine I've come up with so far is a sample; once someone puts me on the right track I can continue so I show only 3 floors. once again thank you for your assistance. (this do not work BTW) (defun c:***18 () (setvar "CMDECHO" 0) (initget "1 2 3") (setq levels (getkword "\nWhat level is this for?: " ) ) (cond (= levels "1") (L1) ) (= levels "2") (L2) ) (= levels "3") (L3) ) (defun L1 () (prompt "\nRepathing InWallworkzone-L1: ") (command "_xref" "p" "*inwall*" "Y:/dir/Drafting/10 BIM-3D-2D/Electrical-DC/In Wall Workzone Boundary/InWallWorkZone-L1.dwg") (command "_xref" "r" "*inwall*")) (defun L2 () (prompt "\nRepathing InWallworkzone-L2: ") (command "_xref" "p" "*inwall*" "Y:/dir/Drafting/10 BIM-3D-2D/Electrical-DC/In Wall Workzone Boundary/InWallWorkZone-L2.dwg") (command "_xref" "r" "*inwall*")) (defun L3 () "\nRepathing InWallworkzone-L3: ") (command "_xref" "p" "*inwall*" "Y:/dir/Drafting/10 BIM-3D-2D/Electrical-DC/In Wall Workzone Boundary/InWallWorkZone-L3.dwg") (command "_xref" "r" "*inwall*")) ) ) Edited September 27, 2017 by antoniusxylem Quote Link to comment Share on other sites More sharing options...
BKT Posted September 19, 2017 Share Posted September 19, 2017 At first glance, it appears you've left off part of the code for L3: "\nRepathing InWallworkzone-L3: ") To match the code for L1 and L2 it should be: (prompt "\nRepathing InWallworkzone-L3: ") Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted September 20, 2017 Share Posted September 20, 2017 (cond (= levels "1") (L1) ) (= levels "2") (L2) ) (= levels "3") (L3) ) cond structure should be like this (cond (test_1 result_1 ...)(test_2 result_2 ... ) (test_n result_n ... ) etc.. )) alternative without cond method1 - assoc if sub-function name varies ((eval(cdr([color="blue"]assoc[/color] [color="red"][b]levels[/b][/color] (mapcar 'cons '("1" "2" "3" "4" etc...) '(L1 L2 L3 Ln etc.. )))))) method2 - sub-function name identical to floor name [color="green"];direct evaluates sub-functions L1 L2 L3 without using cond[/color] (([color="blue"]eval[/color](read (strcat "L" [color="red"][b]levels[/b][/color])))) method3 - concatenate naming [color="green"];or without both cond & sub-func L1 L2 L3 , simply strcat filename if drawing names are identical with getkword[/color] ([color="blue"]strcat[/color] "Y:/dir/Drafting/10 BIM-3D-2D/Electrical-DC/In Wall Workzone Boundary/InWallWorkZone-L" [color="red"][b]levels[/b][/color] ".dwg") my rm0.02 p/s: Please read the Code Posting Guidelines and edit your Code to be included in Code Tags. [NOPARSE] Your Code Here[/NOPARSE] will look like this Your Code Here Quote Link to comment Share on other sites More sharing options...
ronjonp Posted September 20, 2017 Share Posted September 20, 2017 (edited) Here's a quick one: ( not tested ) (defun c:***18 (/ level xrp) ; <- Localize variables (setq xrp "Y:/dir/Drafting/10 BIM-3D-2D/Electrical-DC/In Wall Workzone Boundary/InWallWorkZone-L") (if (setq level (getint "\nWhat level is this for?: ")) (if (findfile (strcat xrp (itoa level) ".dwg")) (progn (prompt (strcat "\nRepathing InWallworkzone-L" (itoa level) ": ")) (command "-.xref" "_Path" (strcat "InWallWorkZone-L" (itoa level)) (strcat xrp (itoa level) ".dwg") ) (command "-.xref" "_Reload" "*inwall*") ) ) ) (princ) ) Edited September 27, 2017 by ronjonp Quote Link to comment Share on other sites More sharing options...
antoniusxylem Posted September 22, 2017 Author Share Posted September 22, 2017 Here's a quick one: ( not tested ) (defun c:***18 (/ level xrp) ; <- Localize variables (setq xrp "Y:/dir/Drafting/10 BIM-3D-2D/Electrical-DC/In Wall Workzone Boundary/InWallWorkZone-L") (if (setq level (getint "\nWhat level is this for?: ")) (if (findfile (strcat xrp (itoa level) ".dwg")) (progn (prompt (prompt "\nRepathing InWallworkzone-L" (itoa level) ": ")) (command "-.xref" "_Path" (strcat "InWallWorkZone-L" (itoa level)) (strcat xrp (itoa level) ".dwg") ) (command "-.xref" "_Reload" "*inwall*") ) ) ) (princ) ) I like the lisp but once run it places the ".dwg" as a command. Is there anyway to fix this? Quote Link to comment Share on other sites More sharing options...
Grrr Posted September 22, 2017 Share Posted September 22, 2017 method1 - assoc if sub-function name varies ((eval(cdr([color="blue"]assoc[/color] [color="red"][b]levels[/b][/color] (mapcar 'cons '("1" "2" "3" "4" etc...) '(L1 L2 L3 Ln etc.. )))))) Note that directly 'nth' accessing should be alot faster: (nth (vl-position levels '("1" "2" "3" "4" etc...)) (list L1 L2 L3 Ln etc.. )) Rather than building assoc list from the two lists, and trying to access item the classical (cdr (assoc ...)) way. Also LM wrote somewhere that the eval is too slow, so I assumed that evaluating all lists with the list function would be faster. Quote Link to comment Share on other sites More sharing options...
antoniusxylem Posted September 25, 2017 Author Share Posted September 25, 2017 cond structure should be like this (cond (test_1 result_1 ...)(test_2 result_2 ... ) (test_n result_n ... ) etc.. )) alternative without cond method1 - assoc if sub-function name varies ((eval(cdr([color="blue"]assoc[/color] [color="red"][b]levels[/b][/color] (mapcar 'cons '("1" "2" "3" "4" etc...) '(L1 L2 L3 Ln etc.. )))))) Thank you I understand where the issue was but new issue arrived when using the new lsp command I get a nil at the end of the command. any ideas why (defun c:*-*-() (setvar "CMDECHO" 0) (initget "1 2 3") (setq Levels (getkword "\nWhat level is this for?: ") ) (cond (1 LEV1)(2 LEV2 ) (3 LEV3) (setq levels (getkword "\nWhat level is this for?: ") ) (defun LEV1 () (prompt "\nRepathing InWallworkzone-L1: ") (command "-xref" "p" "*inwall*" "X:/DIR/Drafting/10 BIM-3D-2D/Electrical-DC/In Wall Workzone Boundary/InWallWorkZone-L1.dwg") (command "-xref" "r" "*inwall*")) (defun LEV2 () (prompt "\nRepathing InWallworkzone-L2: ") (command "-xref" "p" "*inwall*" "X:/DIR/Drafting/10 BIM-3D-2D/Electrical-DC/In Wall Workzone Boundary/InWallWorkZone-L2.dwg") (command "-xref" "r" "*inwall*")) (defun LEV3 () (prompt "\nRepathing InWallworkzone-L3: ") (command "-xref" "p" "*inwall*" "X:/DIR/Drafting/10 BIM-3D-2D/Electrical-DC/In Wall Workzone Boundary/InWallWorkZone-L3.dwg") (command "-xref" "r" "*inwall*")) ) ) Thanks in advance Quote Link to comment Share on other sites More sharing options...
SLW210 Posted September 26, 2017 Share Posted September 26, 2017 Please read the Code Posting Guidelines and edit your Code to be included in Code Tags.[NOPARSE] Your Code Here[/NOPARSE] = Your Code Here Quote Link to comment Share on other sites More sharing options...
antoniusxylem Posted September 26, 2017 Author Share Posted September 26, 2017 Please read the Code Posting Guidelines and edit your Code to be included in Code Tags.[NOPARSE]Your Code Here[/NOPARSE] = Your Code Here If you look at my last reply not the first you will see that this was done, hanhphuc mentioned it in their post. Quote Link to comment Share on other sites More sharing options...
ronjonp Posted September 26, 2017 Share Posted September 26, 2017 I like the lisp but once run it places the ".dwg" as a command. Is there anyway to fix this? I'm not sure I understand ".dwg" as a command? Quote Link to comment Share on other sites More sharing options...
antoniusxylem Posted September 26, 2017 Author Share Posted September 26, 2017 Ronjonp, The lisp runs through the routine but when you call up the acad text window cad states ".dwg" unknown command. Quote Link to comment Share on other sites More sharing options...
SLW210 Posted September 27, 2017 Share Posted September 27, 2017 If you look at my last reply not the first you will see that this was done, hanhphuc mentioned it in their post. Your original post still has not been corrected. Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted September 27, 2017 Share Posted September 27, 2017 I'm not sure I understand ".dwg" as a command? Here's a quick one: ( not tested ) (defun c:***18 (/ level xrp) .... (progn (prompt ([color="red"]prompt[/color] "\nRepathing InWallworkzone-L" (itoa level) ": ")) (command "-.xref".... hi ronjonp, typo bug prompt - too many arguments i think you too fast typing omitted the strcat Quote Link to comment Share on other sites More sharing options...
ronjonp Posted September 27, 2017 Share Posted September 27, 2017 hi ronjonp, typo bug prompt - too many argumentsi think you too fast typing omitted the strcat Thanks for the catch .. that's why code should be tested .. Code fixed. Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted September 27, 2017 Share Posted September 27, 2017 Thanks for the catch .. that's why code should be tested .. Code fixed. no worries Thank you I understand where the issue was but new issue arrived when using the new lsp command I get a nil at the end of the command. any ideas why In your case , i prefer concatenate method like ronjonp wrote, please look at his example is more generic you may try activeX method (defun c:***18 (/ doc dwg level matched path) ;hanhphuc 28.09.2017 (setq path "X:\\DIR\\Drafting\\10 BIM-3D-2D\\Electrical-DC\\In Wall Workzone Boundary" doc '((l / doc) (setq doc (vlax-get-acad-object)) (foreach x l (setq doc (vlax-get doc x)))) ) (if (and (progn (initget 1) (setq level (getint "\nWhat level is this for?: "))) (setq level (strcat "InWallWorkZone-L" (itoa level))) (or (vl-file-directory-p path) (setq path (acet-ui-pickdir))) (or (setq matched (findfile (strcat path "\\" level))) (setq dwg (getfiled "XREF" path "dwg;*" 16)) ) ) (progn (vl-catch-all-apply 'vla-attachexternalreference (list (setq doc (doc '(ActiveDocument ActiveLayout Block))) dwg (if matched level (vl-filename-base dwg) ) (vlax-3d-point '(0. 0. 0.)) 1 1 1 0 0 ) ) (vlax-release-object doc) ) (princ "\nOops.. failed to load xref!") ) (princ) ) (vl-load-com) Note that directly 'nth' accessing should be alot faster: (nth (vl-position levels '("1" "2" "3" "4" etc...)) (list L1 L2 L3 Ln etc.. )) Rather than building assoc list from the two lists, and trying to access item the classical (cdr (assoc ...)) way. Also LM wrote somewhere that the eval is too slow, so I assumed that evaluating all lists with the list function would be faster. Yes, your are correct eval should be avoided for large lists, though my previous example only performs single evaluation, i still appreciate your debug & suggestion Thanks also vl-position example too Quote Link to comment Share on other sites More sharing options...
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.