Process Multiple Drawings via VBA

Discussion in 'AutoCAD' started by BVH-CAD, Jul 21, 2003.

  1. BVH-CAD

    BVH-CAD Guest

    I've got a program that SHOULD perform multiple tasks to multiple drawings, however, when I run the program, all it does is open then save the drawing and then move on to open and save the next drawing.... It doesn't perform any of the tasks! Am I missing some magic keyword to make this happen or am I just experiencing a brain-freeze??

    Thanks in advance!
      ~ Matt
     
    BVH-CAD, Jul 21, 2003
    #1
  2. BVH-CAD

    BVH-CAD Guest

    This is code within the loop to open, process, and save...



     



    For blah blah blah = 1 to blah blah blah



            ThisDrawing.Open dwg
            ThisDrawing.Activate



            ThisDrawing.SetVariable "filedia", 0
            ThisDrawing.SendCommand "change" & vbCr & "all" & vbCr & "" & vbCr & "p" & vbCr & "c" & vbCr & "bylayer" & vbCr _
                                & "lw" & vbCr & "bylayer" & vbCr & vbCr
            ThisDrawing.SendCommand "mslide" & vbCr
            ThisDrawing.SetVariable "filedia", 1
            ThisDrawing.Save





    Next blah blah blah



     




    --
    Matt W



     



    There are 3 kinds of people:
      Those who can count, and those who can't.
     
    BVH-CAD, Jul 21, 2003
    #2
  3. I notice you only have 1 vbCr after mslide... you need a second vbCr to
    accept the default filename and execute the command.... if you're trying to
    get the program to sit at the filename prompt to let you enter one, I don't
    think SendCommand will allow that, because the code doesn't stop running...
    there are simple tools you can use if you want to input the filenames
    yourself.

    Also, the "change" SendCommand *should* be replaced with a selection set and
    calls to the .COLOR and .LINEWEIGHT properties, but I don't know that this
    is contributing to your problems. If you get it working with this line in
    it, good enough.... I would think that the larger your drawings get, the
    more chance this line would have of causing problems, since it would take
    longer and longer to process.

    HTH,

    James
     
    James Belshan, Jul 21, 2003
    #3
  4. BVH-CAD

    Murph Guest

    Ok Robert (or anyone else) answer me this, The send command runs last in the
    sub no mater where it falls at in the code.As to what I read somewhere. So
    in BVC-CAD's example the "ThisDrawing.save" is executed then the
    sendcommand(s), there by none of the changes are saved. Am I correct?

    Murph
     
    Murph, Jul 21, 2003
    #4
  5. Yes. ;-)

    --
    R. Robert Bell, MCSE
    www.AcadX.com


    | Ok Robert (or anyone else) answer me this, The send command runs last in
    the
    | sub no mater where it falls at in the code.As to what I read somewhere. So
    | in BVC-CAD's example the "ThisDrawing.save" is executed then the
    | sendcommand(s), there by none of the changes are saved. Am I correct?
    |
    | Murph
    |
    |
    |
    | | > SendCommand is likely the problem. You could try a DoEvents after each
    | > SendCommand, but I don't know if that will help. You could iterate thru
    | the
    | > drawing changing your properties, to avoid that SendCommand. There is
    | > nothing in the object model for MSlide.
    | >
    | >
    | > --
    | > R. Robert Bell, MCSE
    | > www.AcadX.com
    | >
    | >
    | > | > | This is code within the loop to open, process, and save...
    | > |
    | > | For blah blah blah = 1 to blah blah blah
    | > | ThisDrawing.Open dwg
    | > | ThisDrawing.Activate
    | > | ThisDrawing.SetVariable "filedia", 0
    | > | ThisDrawing.SendCommand "change" & vbCr & "all" & vbCr & "" &
    | vbCr
    | > & "p" & vbCr & "c" & vbCr & "bylayer" & vbCr _
    | > | & "lw" & vbCr & "bylayer" & vbCr & vbCr
    | > | ThisDrawing.SendCommand "mslide" & vbCr
    | > | ThisDrawing.SetVariable "filedia", 1
    | > | ThisDrawing.Save
    | > | Next blah blah blah
    | > |
    | > |
    | > | --
    | > | Matt W
    | > |
    | > | There are 3 kinds of people:
    | > | Those who can count, and those who can't.
    | >
    | >
    |
    |
     
    R. Robert Bell, Jul 21, 2003
    #5
  6. BVH-CAD

    Murph Guest

    Thanks.
    Murph
     
    Murph, Jul 21, 2003
    #6
  7. What I find is that the SendCommand runs first, and the changes *are* saved.
    Maybe this is not guaranteed because it's not running synchronously, but on
    my quick test drawing, things get changed first, then saved... not vice
    versa.

    James
     
    James Belshan, Jul 21, 2003
    #7
  8. SendCommand has the tendency to run asynchronously on various flavors of
    AutoCAD. Personally, I've never run into trouble either, but many have.


    --
    R. Robert Bell, MCSE
    www.AcadX.com


    | What I find is that the SendCommand runs first, and the changes *are*
    saved.
    | Maybe this is not guaranteed because it's not running synchronously, but
    on
    | my quick test drawing, things get changed first, then saved... not vice
    | versa.
    |
    | James
    |
    |
    | > Yes. ;-)
    | >
    | > | there by none of the changes are saved. Am I correct?
    | > |
    |
    |
     
    R. Robert Bell, Jul 21, 2003
    #8
  9. BVH-CAD

    Matt Guest

    Murph & Robert:

    The DoEvents fixed the "glitch".
    What was happening was exactly what Murph had described; the SendCommand
    events were happening *after* the drawing was saved, therefore, not saving
    anything.

    Thanks for the input guys.
     
    Matt, Jul 21, 2003
    #9
  10. BVH-CAD

    James Murphy Guest

    Your Welcome Matt even though Robert confirmed what I thought. Got to mark
    this date on the calendar got a VBA question right.
    <g>
    Murph
     
    James Murphy, Jul 22, 2003
    #10
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.