Message 1 of 8
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
This was my first semi-successful attempt at using this function.
I adapted it right out of the help.
The purpose is to copy missing layers (of choice) from one drawing to another. Both must be open in the same AutoCAD session.
All works fine except at the very end and I don't know why.
(defun c:copylayers ( / docs source target layers spec objCollection count)
(defun @msgbox (Title Buttons Message / useri1 value)
(vl-load-com)
(or *acad* (setq *acad* (vlax-get-acad-object)))
(setq useri1 (getvar "useri1"))
(acad-push-dbmod)
(vla-eval
*acad*
(strcat
"ThisDrawing.SetVariable \"USERI1\","
"MsgBox (\""
Message "\","
(itoa Buttons) ",\""
Title "\")"
)
)
(setq value (getvar "useri1"))
(setvar "useri1" useri1)
(acad-pop-dbmod)
value
)
(and
(setq *acad* (vlax-get-acad-object)
docs (vlax-get *acad* 'Documents)
target (vlax-get *acad* 'ActiveDocument)
)
(or
(> (vlax-get docs 'count) 1)
(prompt "There are no other drawings open.")
)
(or
(= (vlax-get docs 'count) 2)
(prompt "There are more than just one (1) other drawing open.")
)
(vlax-for doc docs
(if (not (equal doc target))(setq source doc))
1
)
source
(setq ans (@msgbox "PAY ATTENTION" 52 "The current drawing is the target.\nThe other drawing is the source.\n\nDo you wish to continue?"))
(= ans 6) ;; Yes
(setq spec (getstring "\nEnter layer spec: "))
(vlax-for layer (vlax-get source 'layers)
(if (wcmatch (strcase (vlax-get layer 'Name))(strcase spec))
(setq layers (cons layer layers))
)
1
)
layers
(setq objCollection (vlax-make-safearray vlax-vbObject (cons 0 (- (length layers) 1)))
count 0
)
;; Build collection as an array
(foreach layer layers
(vlax-safearray-put-element objCollection count layer)
(setq count (1+ count))
)
;; Copy objects and get back a collection of the new objects (copies)
(setq Copies (vla-CopyObjects source objCollection (vlax-get target 'layers)))
(print Copies)
;; **** THIS IS WHERE IT FAILS ****
(setq Copylist (vlax-safearray->list (vlax-variant-value Copies)))
)
(princ)
)
John F. Uhden
Solved! Go to Solution.