Jump to content

Please help multiple lines for redefining path to xrefs


antoniusxylem

Recommended Posts

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 by antoniusxylem
Link to comment
Share on other sites

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: ")

Link to comment
Share on other sites

(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

Link to comment
Share on other sites

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 by ronjonp
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

hi ronjonp, typo bug prompt - too many arguments

i think you too fast typing omitted the strcat

 

Thanks for the catch .. that's why code should be tested :) .. Code fixed.

Link to comment
Share on other sites

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 :thumbsup:

Thanks also vl-position example too ;)

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...