lisp rewrite help

lisp rewrite help

cwofford
Participant Participant
144 Views
1 Reply
Message 1 of 2

lisp rewrite help

cwofford
Participant
Participant

I need help.

 

The attached file is a lsp routine that does not work. it was written for a earlier version of autocad. i need it for autocad 2020.

 

It is supposed to enable the user to copy or delete an object or text from a multiple selected layout tabs.

 

Unsure what else anyone would need to fix this so if you have more questions or need something else from me  you can reach me at (chad.j.wofford@gmail.com)

0 Likes
145 Views
1 Reply
Reply (1)
Message 2 of 2

ronjonp
Advisor
Advisor

@cwofford Here's what I use to copy to selected tabs:

(defun c:ctabs (/ ad ch f fn fno id l lyts r s x)
  ;; RJP » 2019-08-21
  ;; Original idea: http://www.theswamp.org/index.php?topic=3012.msg37650#msg37650
  (vlax-for x
	    (setq lyts (vla-get-layouts (setq ad (vla-get-activedocument (vlax-get-acad-object)))))
    (setq l (cons (list (vla-get-taborder x) (vla-get-name x)) l))
  )
  ;; RJP » 2022-01-19 (layoutlist) returns an odd order this is better
  (setq l (mapcar 'cadr (cdr (vl-sort l '(lambda (r j) (< (car r) (car j)))))))
  (cond
    ((null (setq l (vl-remove (getvar 'ctab) l))) (princ "\nHahahaha..."))
    ((or (> (getvar 'cvport) 1) (= (getvar 'tilemode) 1))
     (princ "\nPlease go to a paperspace tab...")
    )
    ((not (setq s (ssget ":L"))) (princ "\nBye..."))
    ((and (setq fn (vl-filename-mktemp nil nil ".dcl")) (setq fno (open fn "w")))
     (foreach x	(list "ctabs : dialog"
		      "{"
		      "    label = \"Available Layouts\";"
		      "    :boxed_column"
		      "    {"
		      "        label = \"Select layouts to copy objects to:\";"
		      "        : list_box"
		      "        {"
		      (strcat "            key = \"layouts\";"
			      "            height = "
			      (itoa (+ 2 (length l)))
			      ";"
		      )
		      "            multiple_select = true;"
		      "        }"
		      "    }"
		      "    : row"
		      "    {"
		      "        : button"
		      "        {"
		      "            label = \"&Select...\";"
		      "            key = \"select\";"
		      "        }"
		      "        : button"
		      "        {"
		      "            label = \"&All...\";"
		      "            key = \"all\";"
		      "        }"
		      "        : button"
		      "        {"
		      "            label = \"&Cancel\";"
		      "            is_cancel = true;"
		      "            key = \"cancel\";"
		      "        }"
		      "    }"
		      "}"
		)
       (write-line x fno)
     )
     (close fno)
     (setq id (load_dialog fn))
     (new_dialog "ctabs" id)
     (start_list "layouts")
     (mapcar 'add_list l)
     (end_list)
     (mode_tile "select" 1)
     (action_tile "layouts" "(mode_tile \"select\" 0)(setq ch $value)")
     (action_tile
       "select"
       "(setq r (mapcar '(lambda (x) (nth x l)) (read (strcat \"(\" ch \")\")))) (done_dialog 1)"
     )
     (action_tile "all" "(setq r l) (done_dialog 1)")
     (setq f (start_dialog))
     (unload_dialog id)
     (vl-file-delete fn)
     (cond
       (r
	(setq s (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))))
	(foreach x r
	  (vlax-invoke ad 'copyobjects s (vla-get-block (vla-item lyts x)) nil)
	  (princ (strcat "\n" (itoa (length s)) " items copied to tab: " x))
	)
       )
     )
    )
    ((print "Something went wrong..."))
  )
  (princ)
)