REQ:NOOB...Having fun, learning, need help

Discussion in 'AutoCAD' started by Dan, Jun 23, 2004.

  1. Dan

    Dan Guest

    Scenario: I have a drawing opened, I want to select the entities(not all,
    dimstlyes, textstyles, etc) in the drawing with the copybase command. Then I
    want to get the current drawings path and filename, then close the drawing
    without saving, create a new drawing, paste the contents from clipboard,
    then saveas the original path and filename. Is this possible?

    Problem: I have tried a combination with Lisp, Scripts, and VBA. I can
    almost get my complete result, but I cannot figure out how to successfully
    close the original drawing. I can get to the end, but when the saveas
    initiates, it will not complete because there is the following error "dwg
    exists and is open for editing in another session or by another user and
    cannot be replaced."

    Any help would greatly be appreciated.

    I am very new to AutoCAD VBA, so go easy on me.
     
    Dan, Jun 23, 2004
    #1
  2. Dan

    Jason Wilder Guest

    If you're simply saving over the original file and executing everything in
    VBA, can you either delete or rename the original file? Thereby avoiding
    the "dwg exists..."?

    Or are you creating the new drawing before the original is closed? Then
    you'd need to switch back to the original drawing at the application level
    of AutoCAD in order to close the drawing, then saveas the new one.
     
    Jason Wilder, Jun 24, 2004
    #2
  3. Dan

    Dan Guest

    I am attempting to grab entities from an existing drawing "A", closing
    drawing "A" without saving, Creating a new Drawing "X", pasting in the
    entities from Drawing "A", and resaving Drawing "A", overwriting the
    original drawing "A". The string of code I was hooked up on was
    "ActiveDocument.Close False" To make everything work, I have created a
    button macro to execute a script, lisp, and vba macro. Very clumsy at the
    moment and I am sure it can be cleaned up, but I have not learned all the
    coding require to carry out the functions I need. It works now though. I
    will post what I have:

    ^C^Cfiledia;0;-i;*f1text;0,0;;;textstyle;ct1;'z;10000,10000;-10000,-10000;e;
    l;;'z;p;_script;f11.scr;'z;p;\'z;e;10000,10000;-10000,-10000;;(load"runmacro
    ndwg.lsp");

    f1text:
    Is simply a text block with th e text style, and I set the drawing to that
    text style.

    f11.scr:
    (setvar "osmode" 0)
    (setq STARTFILE (strcat (getvar "dwgprefix")(getvar "dwgname")))
    (setq PT1 '(1.0 1.0))
    (command "text" PT1 "" STARTFILE /013)
    (setvar "clayer" "0")
    (command "zoom" "extents")
    (command "-purge" "all" "" "n")
    (command "-purge" "all" "" "n")
    (setvar "osmode" 71)
    (command "copybase")

    runmacrondwg.lsp:
    (setvar "filedia" 0)//To avoid the VBALOAD dialog box display
    (command "_VBALOAD" "c:\\ff1.dvb")
    (setvar "filedia" 1)//Reset filedia to 1
    (command "_-VBARUN" "ff1")//- To avoid the VBARUN dialog box display)

    ff1.dvb:
    Sub ff1()

    SendToCommandPrompt "F1" & vbCr
    ThisDrawing.SetVariable "FILEDIA", 0
    ActiveDocument.Close False
    Dim Document0 As AcadDocument
    Set Document0 =
    ThisDrawing.Application.Documents.Add("H:\template\acad.dwt")
    Document0.Activate
    ThisDrawing.SetVariable "MODEMACRO", "C&T Draw Scale: NADA ."
    ThisDrawing.SetVariable "FILEDIA", 1
    SendToCommandPrompt "F2" & vbCr
    ThisDrawing.SendCommand "zoom" & vbCr
    ThisDrawing.SendCommand "e" & vbCr
    ThisDrawing.SendCommand "qsave" & vbCr
    ThisDrawing.SendCommand "close" & vbCr
    End Sub

    F2.LSP:
    (defun c:f2 ()

    (setvar "clayer" "0")
    (command "pasteclip" "0,0")
    (command "zoom" "extents")
    (command "-purge" "all" "" "n")
    (command "-purge" "all" "" "n")
    (setq ENT (entlast))
    (setq ENT1 (entget ENT))
    (setq NFNAME (cdr(assoc 1 ENT1)))
    (entdel ENT)
    (command "save" NFNAME)

    (princ)
    )
     
    Dan, Jun 24, 2004
    #3
  4. Dan,

    Wblock method would be more stright forward....?

    Paul
     
    Paul Richardson, Jun 25, 2004
    #4
  5. Dan

    Jason Wilder Guest

    Maybe if I understood exactly what all this accomplishing? At this point,
    you're simply creating a blank drawing and saving over the original file?
    Just transposing the name via copybase and pasteclip? You'd have a better
    time just writing a simple LISP routine that will create a script that could
    cover this all in one shot without having to use VBA or otherwise. The only
    hangup being that a script does have to execute through and open drawing
    session.

    Heck, if you're just opening and template and saving over an existing file,
    I fail to see why a routine is required for this, unless your drafters don't
    know how to open a template and save a file. Unless you're doing this in
    volume over a bunch of drawings.

    Also, you won't need to mess with filedia if you use this:

    (vl-vbaload "c:\\ff1.dvb")
    (vl-vbarun "ff1")
     
    Jason Wilder, Jun 25, 2004
    #5
  6. Dan

    Dan Guest

    Thank you for your attention. The whole goal of this process is to have a
    drafter redefine the insertion base point of hundreds of blocks, and strip
    out dimstyles, and text style, etc, at the same time.
     
    Dan, Jun 25, 2004
    #6
  7. Dan

    Jason Wilder Guest

    Wow. That's a bit of a task. Is this supposed to be a one time thing? Or
    does this occur often?

    Just a thought, is what if you used a routine just to rip through the blocks
    stripping out the dimstyles and textstyles.

    Then a drafter can run through the blocks to change the basepoint?

    Just my opinion, but the amount of time used struggling to do the
    open/close/saveas is about as much time as it might take a good drafter run
    through the blocks manually - just a few extra clicks.

    I have some routines I'll look through, see if I have anything that gets in
    the ballpark of what you're trying to accomplish.
     
    Jason Wilder, Jun 26, 2004
    #7
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.