Jump to content

Recommended Posts

Posted

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:

 

  1. Select all of the drawing
  2. Copybase 0,0
  3. Do a "qnew" for a new drawing
  4. 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

Posted

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

Posted

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

Posted
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

Posted

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

Posted
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.

Posted
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

Posted
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

Posted

 

good catch Grrr , maybe little more complicated to use but also more fun :-)

Posted (edited)

WBLOCK?

 

but base UCS coordinates

Edited by hanhphuc
link expired
Posted
WBLOCK?but base UCS coordinates

 

that would be plan D? I'm losing count here :P hope OP has enough choises by now.

Posted
that would be plan D? I'm losing count here :P 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 

 

:lol:

Posted
BTW theres another plan E (by investigating plan C) :

 

:lol:

OP says : "how about plan F? let's get some beer" :beer:

:rofl:

Posted
OP says : "how about plan F? let's get some beer" :beer:

:rofl:

 

thát's the best plan I've heard so far!

 

:beer: cheers guys! burp , oh , excuse me...

Posted
BTW theres another plan E (by investigating plan C) ::lol:

 

nice wblock Grrr :D

Posted

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

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...