Jump to content

Two Drawings open at the same time ....


scremin

Recommended Posts

Hello everyone,

 

I've been learning AutoLisp for the last couple of weaks and started to write some simple codes to help me in my everyday-work. But today, while writting my program I faced some trouble trying to handle 2 dwg files open at the same time in AutoCAD. I'm trying to write a lisp to copy part of my original drawing, past that to a new drawing created automatically by the program and then execute some other commands at the second drawing. After all the commands I need my original file to be active again and the second one must close.

Everytime the AutoCAD executes all the commands at the first drawing instead of doing that at the second. Is there a way to "pass" the lisp routine to the second file?? How can I change the active drawing and make the lisp program to change together?

 

I'm stucked at this. If anyone have already passed trough this trouble, please help!

Link to comment
Share on other sites

Unfortunately, LISP is a Document level API, and must be loaded into each Drawing (read Document) for the code to be accessible.

 

There may be a way of accomplishing what you're after, but without knowing specifically the code you're attempting to have execute, I cannot say for sure... Alternatives if LISP is in fact incapable of performing the task(s) you're after, are going to be Script (potentially), otherwise you'll be relegated to stepping up into a higher level API such as .NET or ObjectARX.

 

Again, to early to tell for sure... More information is needed.

 

Cheers

Link to comment
Share on other sites

...... Is there a way to "pass" the lisp routine to the second file?? How can I change the active drawing and make the lisp program to change together?.....

 

Now that would be something. Cross-over a routine between two drawings. You can however use the next best thing. "pass" the value of variables to the second file via vl-propagate.

 

vl-propagate (AutoLISP)

 

Copies the value of a variable into all open document namespaces (and sets its value in any subsequent drawings opened during the current AutoCAD session)

 

.....to early to tell for sure... More information is needed.

 

1+

Link to comment
Share on other sites

Depending on the operations to be performed in the second drawing, perhaps ObjectDBX could be considered (for example: Copy to Drawing); or if the second drawing is already open, the drawing could be manipulated by retrieving the relevant Document Object from the Documents Collection.

Link to comment
Share on other sites

Sorry guys, maybe I should have been more specific.

The thing I want to do is the following:

- While my drawing is open, the routine should ask me to select a line.

- Based on the selected line, the program would select objects near the line and create a selection set.

- Then the routine creates a new drawing in the same directory of the original file and opens that file.

- The previous created selection set should be copied to the new drawing and then be rotated based on the line's midpoint ( but the rotate command must be executed on the second drawing). Here I get problems, because my LISP routine can change the active document but the following commands (rotate) are executed on the first one.

Link to comment
Share on other sites

Methinks it would be simpler to instead manipulate the selection set within the originating drawing first, then WBLOCK (removing any changes made to the source, etc.), followed by code to open, and active the resultant drawing.

Link to comment
Share on other sites

Black Box, I understand what you're saying about WBLOCK, but again my problem is not in passing the object to another open drawing, my problem is how to keep the program working using the new drawing.

If AutoLISP is an document level language, which language should I use to work at Application level?

What I actualy want to do is to be able to make changes in 2 drawing open at the same time with the same routine.

Link to comment
Share on other sites

Here's an idea:

 

One routine with flags:

(defun c:r1 ()
 	(cond
         ((= flg 1)
          	(princ "\nSomething"))
         ((= flg 2)
          	(princ "\nSomething Something"))
         ((= flg 2)
          	(princ "\nSomething Something Something"))
         (vl-propagate 'flg); etc... it can be as many as you want
 	))

 

Now running the same routine on the "other drawing" it should pick up where it left off. You can use implied selection to select the "pasted objects".

Link to comment
Share on other sites

I can't say that I know the code you need to carry out your task but VB.NET works pretty good for me when trying to work with AutoCAD from outside of AutoCAD...if you catch my drift. I too run into this same issue, wishing that one lisp file could jump from one drawing to another. From time to time, I rely on an old trick of having the software write it's own software... for example, I have an operation that prints a PDF and then uses 7Zip to compress the completed dwg and pdf file prepared by an automation program. The LISP file writes a batch file based on the values in the currently running drawing, then it executes this DOS Batch file which correctly prepares and saves the zip file before it's sent over the Internet back to the customer who requested the drawing. Your process would be slightly different but I could see that you could write a new LISP file on the fly from with the existing LISP program, then launch a script to open a new drawing, load and run the new LISP. It would begin to get awfully spaghetti like so you may wish to look at VB.NET or C# or something that would take control outside of AutoCAD environment.

Link to comment
Share on other sites

Black Box, I understand what you're saying about WBLOCK, but again my problem is not in passing the object to another open drawing, my problem is how to keep the program working using the new drawing.

If AutoLISP is an document level language, which language should I use to work at Application level?

What I actualy want to do is to be able to make changes in 2 drawing open at the same time with the same routine.

 

As I briefly mentioned back on the first page, if the issue is code execution... This:

 

you may wish to look at VB.NET or C# or something that would take control outside of AutoCAD environment.

 

The .NET API (i.e., C#, F#, VB.NET, etc.) will allow for you to access multiple Documents already opened within the Editor, or those not already opened as side Database (via ReadDwgFile() Method). :thumbsup:

 

 

 

If you're new to .NET development, you may find this thread to be useful:

 

 

 

 

Cheers

Link to comment
Share on other sites

From time to time, I rely on an old trick of having the software write it's own software... for example, I have an operation that prints a PDF and then uses 7Zip to compress the completed dwg and pdf file prepared by an automation program. The LISP file writes a batch file based on the values in the currently running drawing, then it executes this DOS Batch file which correctly prepares and saves the zip file before it's sent over the Internet back to the customer who requested the drawing. Your process would be slightly different but I could see that you could write a new LISP file on the fly from with the existing LISP program, then launch a script to open a new drawing, load and run the new LISP.

 

I do not recall what version you're on at work (2013, or multiple?), but have you had a chance to take a peek at the new JavaScript API on AutoCAD 2014?

 

I know you're supporting a range of Web/Network service(s), and thought you might find value in it, and/or offering the new functionality to your customers.

Link to comment
Share on other sites

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