Cant quite get these 'if/and' statement working

Discussion in 'AutoCAD' started by devon, Jul 15, 2004.

  1. devon

    devon Guest

    Hi,

    Zeha helped me a while back with a routine that opens a doslib 'file open' dialogue in the "xref" directory of a project, dependant apon if you were in a sheet or xref, you got different results.

    Here is my Project directory structure...
    PROJ DIR
    -DRAWINGS
    +-------Disipline
    +-------Disipline
    +-------Disipline
    +-------Xrefs
    +-----------XR_Disipline
    +-----------XR_Disipline

    I am still having some problems with my "if/ and" statements.

    (defun c:xx ( / dwgname dirname)
    (vl-load-com)
    (setq dirname (getvar "dwgprefix")
    dirname (strcat dirname (if (wcmatch dirname "models*") "..\\drawings\\""..\\models"))
    )
    (if
    (and
    (setq dwgname (dos_getfiled "Select a Drawing file XC or XS" dirname "Drawing files XC*.dwg|XC*.dwg|Drawing files XS*.dwg|XS*.dwg|All Drawings *.dwg|*.dwg|"))
    (findfile dwgname)
    )
    (command "vbastmt" (strcat "AcadApplication.Documents.Open" (chr 34) dwgname (chr 34)))
    )

    What I want is 2 things...
    1. When you are in a sheet which would be..
    "Project\drawings\disipline\sheet number"
    I want this routine to open into
    "project\drawings\models"

    2. When you are in a model which would be...
    "project\drawings\models\disipline\xx_number"
    I want this rountine to open into
    "projects\drawings\models\same disipline as active xref"
    so oif it was XS_1234.dwg, the open dialogue would open into "models\str\"

    Does this make sense? am i even close with my code to acheive this?

    Thanks in advance.
     
    devon, Jul 15, 2004
    #1
  2. devon

    zeha Guest

    Devon,

    I can't see if disipline is a static directory.

    ALso i can't see where the models directory is in the project directory structure.
    i guess:

    +-------Disipline
    +-------Disipline
    +-------Disipline
    +-------Xrefs
    +-------Models

    you can try the follow

    type on the command line (in Autocad)

    (getvar"dwgprefix")

    it returns the current drawing(xref) dir

    (strcat (getvar"dwgprefix") "..\\")

    returns one directory up

    (strcat (getvar"dwgprefix") "..\\Models\\")

    returns one directory up from this point the models directory

    i have modified the xx routine so that if not 'models' matched in the dwgprefix it go's to the current (drawing)directory

    the if/and function works as follow:

    (if testexpr thenexpr [elseexpr])

    Arguments

    testexpr

    Expression to be tested.

    thenexpr

    Expression evaluated if testexpr is not nil.

    elseexpr

    Expression evaluated if testexpr is nil.

    Return Values

    The if function returns the value of the selected expression. If elseexpr is missing and testexpr is nil, then if returns nil.

    Examples

    Command: (if (= 1 3) "YES!!" "no.")

    "no."

    Command: (if (= 2 (+ 1 1)) "YES!!")

    "YES!!"

    Command: (if (= 2 (+ 3 4)) "YES!!")

    nil


    (defun c:xx ( / dwgname dirname)
    (vl-load-com)
    (setq dirname (getvar "dwgprefix")
    dirname (if (not (wcmatch dirname "models*")) (strcat dirname"..\\models")(getvar"dwgprefix")))
    )
    (if
    (and
    (setq dwgname (dos_getfiled "Select a Drawing file XC or XS" dirname "Drawing files XC*.dwg|XC*.dwg|Drawing files XS*.dwg|XS*.dwg|All Drawings *.dwg|*.dwg|"))
    (findfile dwgname)
    )
    (command "vbastmt" (strcat "AcadApplication.Documents.Open" (chr 34) dwgname (chr 34)))
    )

    Cheers
     
    zeha, Jul 15, 2004
    #2
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.