GregGleason Posted March 31, 2018 Posted March 31, 2018 I thought this simple program would run, but it looks like I am asking it to do something where the code hangs up and I have to kill the process. The pseudocode is: Select all of the drawing Copybase 0,0 Do a "qnew" for a new drawing Paste clip 0,0 into new drawing (defun c:test ( / s ) (vla-sendcommand (vla-get-activedocument (vlax-get-acad-object)) (strcat "select all \r\r")) (if (setq s (ssget)) (command "_.copybase" "_non" '(0 0) s "")) (princ) (command "._qnew") (command "_.pasteclip" "_non" '(0 0)) (princ) ) (vl-load-com) Which part is not correct? Greg Quote
rlx Posted March 31, 2018 Posted March 31, 2018 Guess you want to paste selection in new template file and not able to use saveas... what's the use of the vla-sendcommand??? but to answer your question , I think that as soon as you start a new drawing your lisp routine stops because lisp runs in its own namespace. What you need is a script file... gr. Rlx Quote
GregGleason Posted March 31, 2018 Author Posted March 31, 2018 Ok, so this one works better in that it will create a new drawing and does not hang up. But it does not paste the information and it wants to create two drawings. (defun c:test ( / s ) (vla-sendcommand (vla-get-activedocument (vlax-get-acad-object)) (strcat "select all \r\r")) (if (setq s (ssget)) (command "_.copybase" "_non" '(0 0) s "")) (princ) (vla-sendcommand (vla-get-activedocument (vlax-get-acad-object)) (strcat "qnew \r")) (command "_.pasteclip" "_non" '(0 0)) (princ) ) (vl-load-com) Greg Quote
GregGleason Posted March 31, 2018 Author Posted March 31, 2018 Guess you want to paste selection in new template file and not able to use saveas... what's the use of the vla-sendcommand??? but to answer your question , I think that as soon as you start a new drawing your lisp routine stops because lisp runs in its own namespace. What you need is a script file... gr. Rlx Hmmm. That makes sense now that you mention it. So a VBA routine would work? Greg Quote
rlx Posted March 31, 2018 Posted March 31, 2018 you could also try to make a script file , for example 'change_template.scr' and save it where ever you want , in your support path but lets say c:/temp/ the script file could look like : copybase 0,0 all qnew y pastclip 0,0 you might not need the empty line on line 7 if the autocad template is pre-set. Then all you would need is call the script : script c:/temp/change_template.scr all is left then is to save the drawing with the name of your choise oopsie had one 0,0 too many , updated the code above Quote
rlx Posted March 31, 2018 Posted March 31, 2018 Hmmm. That makes sense now that you mention it. So a VBA routine would work? Greg yes VBA should work because VBA operates on autocad as an object where lisp only lives in the drawing session. Quote
GregGleason Posted March 31, 2018 Author Posted March 31, 2018 you could also try to make a script file , for example 'change_template.scr' and save it where ever you want , in your support path but lets say c:/temp/ the script file could look like : copybase 0,0 all qnew y pastclip 0,0 you might not need the empty line on line 7 if the autocad template is pre-set. Then all you would need is call the script : script c:/temp/change_template.scr all is left then is to save the drawing with the name of your choise oopsie had one 0,0 too many , updated the code above Thanks rlx! I'll give that a try. Greg Quote
GregGleason Posted March 31, 2018 Author Posted March 31, 2018 yes VBA should work because VBA operates on autocad as an object where lisp only lives in the drawing session. Thanks. For now, that is my new Plan B. Greg Quote
rlx Posted April 1, 2018 Posted April 1, 2018 Plan See good catch Grrr , maybe little more complicated to use but also more fun :-) Quote
hanhphuc Posted April 1, 2018 Posted April 1, 2018 (edited) WBLOCK? but base UCS coordinates Edited April 2, 2018 by hanhphuc link expired Quote
rlx Posted April 1, 2018 Posted April 1, 2018 WBLOCK?but base UCS coordinates that would be plan D? I'm losing count here hope OP has enough choises by now. Quote
Grrr Posted April 1, 2018 Posted April 1, 2018 that would be plan D? I'm losing count here hope OP has enough choises by now. BTW theres another plan E (by investigating plan C) : (defun test ( / cad acDoc acSS v i nDoc ) (setq cad (vlax-get-acad-object)) (setq acDoc (vla-get-ActiveDocument cad)) (setq acSS (vla-get-ActiveSelectionSet acDoc)) (vlax-invoke acSS 'Select acSelectionSetAll) (setq v (vlax-make-safearray vlax-vbObject (cons 0 (1- (setq i (vlax-get acSS 'Count)))))) (vlax-for o acSS (vlax-safearray-put-element v (setq i (1- i)) o)) (setq v (vlax-make-variant v)) (setq nDoc (vla-Add (vla-get-Documents (vlax-get-acad-object)))) (vla-CopyObjects acDoc v (vla-get-block (vla-Item (vla-get-Layouts nDoc) "Model"))) (vlax-put-property cad 'ActiveDocument nDoc) (and acSS (vl-catch-all-apply 'vla-Delete acSS)) ); defun Quote
hanhphuc Posted April 1, 2018 Posted April 1, 2018 BTW theres another plan E (by investigating plan C) : OP says : "how about plan F? let's get some beer" Quote
rlx Posted April 1, 2018 Posted April 1, 2018 OP says : "how about plan F? let's get some beer" thát's the best plan I've heard so far! cheers guys! burp , oh , excuse me... Quote
rlx Posted April 1, 2018 Posted April 1, 2018 BTW theres another plan E (by investigating plan C) : nice wblock Grrr Quote
GregGleason Posted April 3, 2018 Author Posted April 3, 2018 Ok, I don't know what Plan iteration this is, but this is where I am in the process of writing .scr file: filedia 0 copybase 0,0 all qnew pasteclip 0,0 zoom all qsave I want to save the path/name to a variable an save it to a subfolder (like "xyz"). Can that be done? Greg 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.