Creating new drawing and continue using lisp inside.

Creating new drawing and continue using lisp inside.

Muhammed.OPERA
Advisor Advisor
5,329 Views
5 Replies
Message 1 of 6

Creating new drawing and continue using lisp inside.

Muhammed.OPERA
Advisor
Advisor

Hi everyone,

I'm writing a LISP with an option that i want it to create new drawing and continue lisp procedure inside.

(before that i made the lisp take a copy of some objects to the clipboard)

i managed to make it create new drawing, using :

			  (vla-activate
			    (vla-Add
			      (vla-get-Documents (vlax-get-acad-object))
			      acadiso.dwt
			    )
			  )

But, after creating the drawing, the lisp ends.

How can i make the lisp continue it's upcoming steps in the new created drawing (pasteclip and other stuff).

Thanks 🙂


Muhammed Mamdouh (OPERA)
Structural Engineer, Instructor
Facebook |LinkedIn

EESignature

0 Likes
Accepted solutions (1)
5,330 Views
5 Replies
Replies (5)
Message 2 of 6

Kent1Cooper
Consultant
Consultant

I think the only way to get an AutoLisp routine to start in one drawing and continue in another is to set the SDI [= Single Drawing Interface] System Variable to 1.  That means only one drawing can be open at a time, so you should not have multiple drawings open when you run a routine that sets it that way, and also you should build in a saving of the current drawing or an answer to the question of whether to save it, since it will have to close it to move into the other drawing.  And of course you will probably want to set SDI back to 0 at the end, unless you never need to have more than one drawing open at a time.

Kent Cooper, AIA
Message 3 of 6

doaiena
Collaborator
Collaborator

You can't run autolisp in multiple drawings, because autolisp code runs only in the active document it has been called from. Visual lisp, on the other hand, operates on the application level, and gives the possibility to share information between documents.
I am not sure what task you want to perform between multiple drawings, but you should start the autolisp code from one drawing, open/create new drawings and use only visual lisp to gather info and apply commands to the newly opened drawings. You can also use autolisp to read information from an object in another drawing, using "(vlax-vla-object->ename object)", but you can't manipulate the entity itself, only as an object.

PS. 
You can also use "vla-sendcommand" to target specific drawings.

Message 4 of 6

Kent1Cooper
Consultant
Consultant
Accepted solution

@doaiena wrote:

You can't run autolisp in multiple drawings, because autolisp code runs only in the active document it has been called from. ....


I "knew" that, too, until someone [I forget who] pointed out the exception to the rule, i.e. that with SDI set to 1, AutoLisp will  work across more than one drawing.  For example, this works to copy something from an old drawing into a newly-made different one:

 

(command "_.copybase" pause (ssget) "" "_.qsave" "_.new" "" "_.pasteclip" (getvar 'viewctr))

 

The pause is for the base point for copying, the QSAVE is so it doesn't ask about saving when the NEW command is called, the "" after NEW is to accept the default template as the basis for the new drawing, and it does  successfully open a new Drawing#.dwg [whatever number # it's up to, and closing the old one in the process, because SDI=1], and does  successfully Paste what I selected with that (ssget) while in the old drawing, into the center of the view in the new  drawing.

 

See caveats in my first Reply.

Kent Cooper, AIA
Message 5 of 6

cadffm
Consultant
Consultant

This behavior is an option by default as described by you,
however deactivatable.

Controlled by the variable LISPINIT

 

0= Lisp not re-initialize with "new" file (default)

1= Lisp re-initialize with "new" file

 

 

Sebastian

Message 6 of 6

Muhammed.OPERA
Advisor
Advisor

Hi everyone, thanks for help.

It really worked as Mr. @Kent1Cooper said exactly but the problem that would face the user is that the interface changes every time s/he uses the LISP,  changing the SDI value causes that and after returning it's value back to 0, it requires a restart to the program to return to it's default view.

I have another solution of my own, i have used now and it worked great without the need to change SDI value,

I used Save as command, that enabled me to save in the same directory/destination of the base file and continue working in the new drawing without any change for interface. 

(setq 
   DwgNm (strcat 
                     (getvar "dwgprefix") 
                     "(;Text before the name;)_"
                     (getvar "dwgname")
                  )
)
(if
   (findfile DwgNm) 
   (command "_.saveas" "" DwgNm "Y") 
   (command "_.saveas" "" DwgNm)
)

Muhammed Mamdouh (OPERA)
Structural Engineer, Instructor
Facebook |LinkedIn

EESignature

0 Likes