Over two drawings...

Over two drawings...

zph
Collaborator Collaborator
728 Views
11 Replies
Message 1 of 12

Over two drawings...

zph
Collaborator
Collaborator

Greetings!

 

Here is the scenario:

 

Drawing 1 has data within that I am pulling from and exporting to a .txt file.

Drawing 2 has entities within that will be modified once the data in the .txt file is imported into Drawing 2.

 

However, the .lsp routine aborts once I open/activate Drawing 2.

 

Is this possible to accomplish with one .lsp routine?  I've begun dabling with .scr, but have hit a bit of a brick wall.

 

Help, please?

0 Likes
Accepted solutions (1)
729 Views
11 Replies
Replies (11)
Message 2 of 12

Kent1Cooper
Consultant
Consultant

@zph wrote:

.... 

Drawing 1 has data within that I am pulling from and exporting to a .txt file.

Drawing 2 has entities within that will be modified once the data in the .txt file is imported into Drawing 2.

 

However, the .lsp routine aborts once I open/activate Drawing 2.

 

Is this possible to accomplish with one .lsp routine?  ....


No, an AutoLisp routine cannot "survive" going from one drawing to another, that is, cannot start in one drawing and continue in another.  Separate AutoLisp routines for the exporting to and the importing from the .txt file would be one way to do it, in addition to the possible Script approach [others would have to help you there -- I haven't dealt with Scripts operating over multiple drawings, and there may be limits to what you can do that way].

Kent Cooper, AIA
Message 3 of 12

zph
Collaborator
Collaborator
Yeah, that's what I figured. Thanks!

So, any ACAD script gurus around?
0 Likes
Message 4 of 12

hmsilva
Mentor
Mentor

Hi zph,

what kind of data are you pulling from 'Drawing 1' and exporting to a .txt file?

Probably,  with 'Drawing 2' as current, and 'Drawing 1' closed, using ObjectDBX it might be possible to 'open' 'Drawing 1' and export the data to a .txt file (or a list) and use the data in the txt to modify the current dwg 'Drawing 2'...

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 5 of 12

Ajilal.Vijayan
Advisor
Advisor

or by using vl-propagate transfer the data by creating a list, to other documents and have to run the lisp on Drawing 2.

0 Likes
Message 6 of 12

zph
Collaborator
Collaborator

The only data contained in the .txt file (from Drawing 1 are integers) are strings...one string per line.

 

I have set up a .bat to copy an existing drawing (call it Drawing 3) to a second location, rename it (this is now Drawing 2), and then open Drawing 2.  This is also when my .lsp file 'dies'.

 

I broke the .lsp file into two separate .lsp files (part 1 and 2) and began researching .scr files in the hopes that a script could run over both drawings.  I am trying code lisp part1 to run on Drawing 1, then run the .bat file, and finish by running lisp part2 on Drawing 2.  In the end both Drawing 1 and 2 are open which is what I want, because then I am going to take data from Drawing 2 and place it in Drawing 1.

 

Does this help?

0 Likes
Message 7 of 12

zph
Collaborator
Collaborator

Currently, I am using the .txt file, but I don't have to.  Originally I was using two .txt files, but eliminated the first using a list instead.  This also increased the speed of my routine.  The only reason I retained the .txt file I am using was as a means to retain data from Drawing 1 when I move to Drawing 2.

 

I'll check out vl-propagate.

0 Likes
Message 8 of 12

Ajilal.Vijayan
Advisor
Advisor

zph wrote:

I'll check out vl-propagate.


If you are trying with vl-propagate, here is one simple example.

;In Drawing 1 define the list
(setq lst '(1 2 3 4))

;propagate the list to other drawings
(vl-propagate 'lst)

;And in Drawing2 
(car lst);this should return 1
0 Likes
Message 9 of 12

hmsilva
Mentor
Mentor

@zph wrote:

The only data contained in the .txt file (from Drawing 1 are integers) are strings...one string per line.

 

I have set up a .bat to copy an existing drawing (call it Drawing 3) to a second location, rename it (this is now Drawing 2), and then open Drawing 2.  This is also when my .lsp file 'dies'.

 

I broke the .lsp file into two separate .lsp files (part 1 and 2) and began researching .scr files in the hopes that a script could run over both drawings.  I am trying code lisp part1 to run on Drawing 1, then run the .bat file, and finish by running lisp part2 on Drawing 2.  In the end both Drawing 1 and 2 are open which is what I want, because then I am going to take data from Drawing 2 and place it in Drawing 1.

 

Does this help?


With both dwg open, the ObjectDBX route, will error...

With both dwg open, using a .scr file, will error...

Could you please share with us 'part 1' routine?

 

Henrique

EESignature

0 Likes
Message 10 of 12

zph
Collaborator
Collaborator

Sure.  Attached is my part1.  I went ahead and attached part2 as well.

 

Here are the contents of the .bat file:

 

@Anonymous off
:: turns off Windows command line window prompt

echo y| del "C:\Users\HULLZP\Desktop\CUSTOM\Count\Batch\*.*"
:: deletes all files contained in Batch folder

copy "C:\Users\HULLZP\Desktop\CUSTOM\Count\Master\MasterPartsList.dwg" "C:\Users\HULLZP\Desktop\CUSTOM\Count\Batch"
:: copies 'fresh' master parts list to Batch folder

rename "C:\Users\HULLZP\Desktop\CUSTOM\Count\Batch\MasterPartsList.dwg" WorkingPartsList.dwg
:: renames 'fresh' master parts to working to reflect status

start "" "C:\Users\HULLZP\Desktop\CUSTOM\Count\Batch\WorkingPartsList.dwg"
:: opens working parts list drawing

 

 

0 Likes
Message 11 of 12

hmsilva
Mentor
Mentor

Hi zph,

sorry but I have a deadline to meet today, so I don't have much free time, but just as a starting point...

Run the following demo in Drawing2 (active dwg), to get the text values in Drawing1 (opened and not active)

 

(defun c:demo (/ allValues docs dwg FindMaxNo txtValue)
   (setq docs (vla-get-documents (vlax-get-acad-object)))
   (if (and (>= (vla-get-count docs) 2)
            (progn (vlax-for doc docs
                      (if (= (vla-get-name doc) "Drawing1.dwg");change to the correct name
                         (setq dwg doc)
                      )
                   )
                   dwg
            )
            (= (vla-get-active dwg) :vlax-false)
            (setq FindMaxNo 1)
       )
      (progn
         (vlax-for layt (vla-get-layouts dwg)
            (vlax-for blk (vla-get-block layt)
               (if (and (= (vla-get-objectname blk) "AcDbText")
                        (= (vla-get-layer blk) "ONE")
                   )
                  (progn
                     (setq txtValue (vla-get-textstring blk))
                     (if (>= (atoi txtValue) FindMaxNo)
                        (setq FindMaxNo (atoi txtValue))
                     )
                     (setq allValues (append allValues (list txtValue)))
                  )
               )
            )
         )
         allValues
      )
   )
)

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 12 of 12

zph
Collaborator
Collaborator
Accepted solution

I figured it out.

 

The solution uses a script file.

 

The script is executed at the end of the part1.lsp, it opens the next file, and then loads and then calls part2.lsp.

 

Now that it's working, I'll try to incorporate the vl-propagate so I can eliminate the remaining .txt file and speed up the routine a bit more.

 

Thanks for your help guys.  Cheers!

0 Likes