Add codes programmatically

Discussion in 'AutoCAD' started by Stanley, Jan 27, 2005.

  1. Stanley

    Stanley Guest

    Hi everyone,

    Is it possible to add codes to the drawing document programmatically?

    I mean the codes is embed into the drawing.

    Thanks in advance.
     
    Stanley, Jan 27, 2005
    #1
  2. Hi Stanley,

    Do you mean program code?

    If so, the answer is yes. You can insert VBA macros in the same way as you
    do in Word Documents.

    I would not advise you to do this, as most users would (quite rightly in my
    opinion) by scared of an AutoCAD file containing macros unless they knew the
    whole reasons for doing it and what the macros did.

    --

    Regards,


    Laurie Comerford
    www.cadapps.com.au
     
    Laurie Comerford, Jan 27, 2005
    #2
  3. Stanley

    Stanley Guest

    Hi Laurie Comerford,

    Thank you.

    The reason I want to embed program code into the drawing document

    is to display a warning message to users when opening the drawing that

    had been categorize as an outdated document.

    That means the code will only be inserted to outdated drawings

    and I want the code be inserted by VBA program (Not manually inserted).

    Will you show me an example of how to do it?

    Thanks for help.

    Regards.

    Stanley.
     
    Stanley, Jan 27, 2005
    #3
  4. Hi Stanley,

    I still have no idea of what you really want to do.

    I made a guess, but I can't even if I wanted to, give examples of of things
    when I don't know what they are and how you want them to work.

    What I would do, would be to delete the drawing and then no-one could have
    difficulties with it being out of date.

    --

    Regards,


    Laurie Comerford
    www.cadapps.com.au
     
    Laurie Comerford, Jan 27, 2005
    #4
  5. Stanley

    Stanley Guest

    Hi Laurie Comerford,

    I can't delete the drawing. Every time I modify the drawing I have save as a
    new drawing.

    So there may be many old drawings, but I just need it as a trace back
    purpose.

    To avoid other people from opening a outdated drawing to work on it.

    So I need to put program code in those outdated drawing, the program is just
    to popup a warning

    message.

    I know AutoCad 2004 have a security option to password protect drawing
    document.

    But out company have both AutoCad 2002 & 2005, I must save drawings in
    Acad2000 format.

    Regards.
     
    Stanley, Jan 27, 2005
    #5
  6. Stanley

    Jon Guest

    I found this quite intersting and looked into it a bit.
    Using VBAMAN, I create a new project bound vba.
    In the code, I create a module which I called Sub Startup for no other
    reason than it seemed like a good module name.
    In that module I placed 1 lineBack in vbaman I embedded the code into the drawing.
    Now all it needs is the ability to auto run on drawing startup.
    Who knows how to do that?
    I like the idea of this and see other uses for this tagging of my own
    drawings.
    Mind you, as Laurie says, most of us hate receiving drawings with embedded
    macros and are loathe to allow them to run.

    Jon
     
    Jon, Jan 27, 2005
    #6
  7. Hi,

    Why do anything so complex?

    Make yourself a block containing information like:

    "This drawing was superseded by drawing xxxx on xxxx date"

    Insert the block and zoom to extents of the block and save the drawing.

    Or even easier - save the drawing inclusive of a date value in the file
    name.

    eg MyProject Drawing.dwg
    Save it as:
    MyProjectDrawing20050127.dwg
    Save again as MyProjectDrawing and continue to work with it.

    --

    Regards,


    Laurie Comerford
    www.cadapps.com.au
     
    Laurie Comerford, Jan 27, 2005
    #7
  8. Stanley

    Ed Jobe Guest

    Have you ever looked into document management software?
     
    Ed Jobe, Jan 27, 2005
    #8
  9. Stanley

    Matt W Guest

    Why not just put the old drawings in a network location that only YOU have
    access to??
    Sounds like you're trying to make a mountain out of a mole hill to me.
     
    Matt W, Jan 27, 2005
    #9
  10. Sounds like you're trying to make a mountain out of a mole hill to me
    I have perfected this method...;0)
     
    Paul Richardson, Jan 27, 2005
    #10
  11. Stanley

    Stanley Guest

    Hi everyone,

    I know it seems to make things complicated.

    But I've to share drawings with others, I can't put it into

    a location only accessible by me.

    To put a text "This drawing was superseded by drawing xxxx on xxxx date"

    on drawing is not a good method. Because other people can erase the text
    then

    save the drawing again. That kind of things always happen in my firm.

    Now I've written a program to do following things:

    When the drawing opened, It pops up an InputBox let user enter
    password. If the password matched the drawing can be viewed &
    editable. On cancel or password mismatch all the content will be
    turned into invisible state.

    The above program works fine. I just want this module be inserted into

    drawing by a host program.
     
    Stanley, Jan 28, 2005
    #11
  12. Stanley

    Ed Jobe Guest

    Because other people can erase the text then save the drawing again. That
    kind of things always happen in my firm.

    That's why you need a document management system. Its a lot of work to write
    your own although it could be done. With a dms, the files are stored in a
    secure area and requires users (whom you've given permission do do so) to
    check them out before editing. Checking in creates a new revision, not
    overwriting the previous one. Any method you use in vba can be worked
    around, just like erasing a piece of text.
     
    Ed Jobe, Jan 28, 2005
    #12
  13. Stanley

    Ed Jobe Guest

    However, should you still decide to do it yourself, the security in vba
    doesn't allow you to programatically embed or extract code from a dwg. You
    can only do that with the VBAMAN command. What I would try is storing info
    as xdata in the dwg and then modifying the Open cmd with your code to check
    the dwg for version info. But as I said, this can be worked around by using
    the default command. You could also use events to watch for a dwg to open.
     
    Ed Jobe, Jan 28, 2005
    #13
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.