doslib won't open file with dos_getfile

Discussion in 'AutoCAD' started by devon, Jun 24, 2004.

  1. devon

    devon Guest

    Hi,

    Got this code finally soted, does everything i need, but when i select a dwg and hit open, i get no dwg opening.

    Any idea why? acad does nothing. no error on cmd line even


    (dos_getfiled "Select a file" (getvar "dwgprefix") "Drawing files (XS*.dwg)|XS*.dwg|All files (*.*)|*.*||")

    Acad2005
    xp-pro sp1
     
    devon, Jun 24, 2004
    #1
  2. devon

    zeha Guest

    Devon,

    Look also at http://discussion.autodesk.com/thread.jspa?threadID=340747

    ;;Test 1 allways opens a new session with the selected drawing
    ;;choose under filetypes for XC or XS
    (defun c:test1 ( / dwgname)
    (vl-load-com)
    (and
    (setq dwgname (dos_getfiled "Select a Drawing file XC or XS" (getvar "dwgprefix") "Drawing files XC*.dwg|XC*.dwg|Drawing files XS*.dwg|XS*.dwg|"))
    (findfile dwgname)
    )
    (startapp (strcat (vla-Get-FullName (vlax-get-acad-object)) " \"" dwgname "\"")))
    )
    ;;Test2 open the drawing selected in the same session if SDI = 1 otherwise it prompted
    ;;The drawing will be saved to the name given at the command line
    ;;choose under filetypes for XC or XS
    (defun c:test2 ( / dwgname)
    (if
    (and
    (setq dwgname (dos_getfiled "Select a Drawing file XC or XS" (getvar "dwgprefix") "Drawing files XC*.dwg|XC*.dwg|Drawing files XS*.dwg|XS*.dwg|"))
    (findfile dwgname)
    )
    (progn
    (setvar "sdi" 1)
    (setvar "cmdecho" 1)
    (if (= (getvar "sdi") 1)
    (if (> (getvar "dbmod") 0)(command "_.save" pause ".open" dwgname)(command ".open" dwgname))
    (alert (strcat "Can't open " dwgname "\nClose all drawings en set variable SDI to 1"))
    )
    )
    )
    )
    ;;Test3 opens a new session if SDI = 0 otherwise it open the drawing selected in the same session
    ;;The current drawing will not!!! be saved
    (defun c:test3 ( / dwgname)
    (vl-load-com)
    (and
    (setq dwgname (dos_getfiled "Select a Drawing file XC or XS" (getvar "dwgprefix") "Drawing files XC*.dwg|XC*.dwg|Drawing files XS*.dwg|XS*.dwg|"))
    (findfile dwgname)
    )
    (progn
    (setvar "sdi" 1)
    (setvar "cmdecho" 1)
    (if (= (getvar "sdi") 1)
    (if (> (getvar "dbmod") 0)(command ".open" "y" dwgname)(command ".open" dwgname))
    (startapp (strcat (vla-Get-FullName (vlax-get-acad-object)) " \"" dwgname "\"")))
    )
    )
    )

    Good luck
     
    zeha, Jun 24, 2004
    #2
  3. devon

    devon Guest

    Zeha,

    Thanks so much for the indepth replys, you are fantastic.

    I have some more questions if thats ok?

    1. All our machines have SDI set to '0' which is multi sheet sessions.

    I just want to use your filter code and open another dwg in the current session without disrupting the other open dwgs.

    the 'test3' solution won't open another dwg without closing the current dwg thats open.

    the 'test2' solution seems to have a similar issue also.

    is it possible to have sdi 0, and open another dwg in that session and not close, save or do anything to the other open drawings?
    I have played around with no luck on that.

    Thanks
    Devon
     
    devon, Jun 25, 2004
    #3
  4. devon

    zeha Guest

    Experience whit this
    There is no check for drawings opened in the same session
    ReOpening the same drawing if this wil go to read only
    In Single Drawing mode the drawing changes will discard
    Search on the ng for other solutions


    ;;Test4 SDI = 0 open the drawing selected otherwise
    ;;The current drawing will not!!! be saved when sdi = 1
    (defun c:test4 ( / dwgname)
    (vl-load-com)
    (and
    (setq dwgname (dos_getfiled "Select a Drawing file XC or XS" (getvar "dwgprefix") "Drawing files XC*.dwg|XC*.dwg|Drawing files XS*.dwg|XS*.dwg|All Drawings *.dwg|*.dwg|"))
    (findfile dwgname)
    )
    (if (= (getvar "sdi") 0)
    (vla-open (vla-get-documents (vlax-get-acad-object))dwgname)
    (if (> (getvar "dbmod") 0)(command ".open" "y" dwgname)(command ".open" dwgname))
    )
    )

    Good luck

    Harrie
     
    zeha, Jun 25, 2004
    #4
  5. devon

    devon Guest

    Zeha,

    Thanks so much for all ths input. You have been fantastic.
    This works perfect.

    1 last question.

    Since this is filtering out particular xrefs I have in a xref directory. Is it possible if i ran this in a drawing that was 1 level up from "xrefs" that it could auto navigate to the xref directory?

    currently dir is "job number\drawings\disipline" & "job number\drawings\xrefs"

    Cheers
     
    devon, Jun 28, 2004
    #5
  6. devon

    zeha Guest

    This is a way to do that
    There is no check for exist directory xref or discipline
    Wcmatch look with wildchards of there 'xref" is in the name then switch to discipline otherwise switch to xrefs

    (defun c:test4 ( / dwgname dirname)
    (vl-load-com)
    (setq dirname (getvar "dwgprefix")
    dirname (strcat dirname (if (wcmatch dirname "xref*") "..\\discipline\\""..\\xrefs\\"))
    )
    (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)
    )
    (if (= (getvar "sdi") 0)
    (vla-open (vla-get-documents (vlax-get-acad-object))dwgname)
    (if (> (getvar "dbmod") 0)(command ".open" "y" dwgname)(command ".open" dwgname))
    )
    )
    )
     
    zeha, Jun 28, 2004
    #6
  7. devon

    devon Guest

    Zeha,

    Thanks again, this is great!

    2 things... If this is not over steping the line...

    I get this error.. #<VLA-OBJECT IAcadDocument 0e58d350>
    once a dwg is opened.
    any idea what this means? I can't find this error code in the forum. i am on acad2k5 and xp pro.

    Also, when you open a dwg from the dialogue, it opens but then reverts back to the other dwg that was open, instead of having the freshly opened dwg active.
    What causes this?

    Last thing, If i was not using doslib, there is a lisp command called 'getfiled' with the '4' which enables a dialogue with a preview window, like the autocad file open window.
    (setq xref_file (getfiled "Select Xref file.." (getvar"dwgprefix") "dwg" 4))

    is there an alternative in doslib that I may have missed?

    Thanks again for your help.

    Cheers.
    Devon
     
    devon, Jun 29, 2004
    #7
  8. devon

    zeha Guest

    Devon,

    First #<VLA-OBJECT IAcadDocument 0e58d350> is not a error;

    Simply a princ at the end of the function.

    Second when a drawing is opened you can ativate them by
    (vla-activate (vla-open (vla-get-documents (vlax-get-acad-object))dwgname))

    Maybe you can try the folow
    Not good tested it seem to be work
    The code is based on VBA this must activated


    (defun c:test6 ( / dwgname)
    (if
    (and
    (setq dwgname (dos_getfiled "Select a Drawing file XC or XS" (strcat (getvar "dwgprefix") "..\\") "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)))
    )
    (princ)
    )
     
    zeha, Jun 29, 2004
    #8
  9. devon

    devon Guest

    Zeah,

    Thanks again. As you can tell, i'm just starting to get my head around all these different functions & I thank you for 'explaining' why/how they work. This helps out a huge amount.

    This is what I have ended up with...

    (defun c:XO ( / dwgname dirname)
    (vl-load-com)
    (setq dirname (getvar "dwgprefix")
    dirname (strcat dirname (if (wcmatch dirname "xref*") "..\\discipline\\""..\\xrefs\\"))
    )
    (if
    (and
    (setq dwgname (dos_getfiled "Select file to open XA, XC, XM or XS" dirname "Drawing files XS*.dwg|XS*.dwg|Drawing files

    XC*.dwg|XC*.dwg|Drawing files XM*.dwg|XM*.dwg|Drawing files XA*.dwg|XA*.dwg|All Drawings *.dwg|*.dwg|"))
    (findfile dwgname)
    )
    (command "vbastmt" (strcat "AcadApplication.Documents.Open" (chr 34) dwgname (chr 34)))
    )
    (princ)
    )

    This works great. Every time you help me out, I see further down the track and then ask more questions.

    Now I wonder why or how this routine is deciding to goto the "xref\str" directory every time I run this lisp? Can this just default to the 'xref' directory?
    ** these are just thoughts and I am not really looking for a solution.

    But...
    Is there anyway to get the file open dialogue with the thumbnail showing?

    Cheers
     
    devon, Jun 29, 2004
    #9
  10. devon

    zeha Guest

    Devon,

    The way the routine decide to go to Xref is the if statement
    if testexpressie ... then .... else

    ;Try this on the command line

    (if (wcmatch "XrefsDrawings" "Xref*") "Yes this is XrefsDrawings" "No this is not XrefsDrawings")

    ;;testexpressie-->(wcmatch "XrefsDrawings" "Xref*")
    ;;then-->"Yes this is XrefsDrawings"
    ;;else-->"No this is not XrefsDrawings"

    ;or

    (if (wcmatch "DisciplineDrawings" "Xref*") "Yes this is XrefsDrawings" "No this is not XrefsDrawings")

    ;or

    (if (wcmatch "DisciplineDrawings" "Xref*") "Yes this is XrefsDrawings")

    ;So you can see if the current drawing came from the xref directory it use the else statement


    ; the modified routine below always go to the xref directory on condition that the from the up directory
    ; the xref directory exist
    ; another way is to use 2 functions where one go's to the xref and the other go's to the discipline

    ;it remains to be seen which is better to use the routine or the Autocad standard open
    ;I think the standard autocad and use the Icon at startup to directory beginning in ... Your directory
    ; you also can filter in the open dialog under editbox 'File_name' with typing XA* or XC* etc..

    (defun c:XO ( / dwgname)
    (if
    (and
    (setq dwgname
    (dos_getfiled "Select file to open XA, XC, XM or XS"
    (strcat (getvar "dwgprefix")"..\\xrefs\\"); edit this line to something like "c:\\YourDir\\YourSubDir\\Xrefs\\"
    "Drawing files XS*.dwg|XS*.dwg|Drawing files XC*.dwg|XC*.dwg|Drawing files XM*.dwg|XM*.dwg|Drawing files XA*.dwg|XA*.dwg|All Drawings *.dwg|*.dwg|"))
    (findfile dwgname)
    )
    (command "vbastmt" (strcat "AcadApplication.Documents.Open" (chr 34) dwgname (chr 34)))
    )
    (princ)
    )


    ;There is a way to show thumbnail with function dos_dwgpreview but there is no filtering possible

    (dos_dwgpreview "Preview a drawing" (strcat (getvar "dwgprefix")"..\\xrefs\\"))

    ;Hopes this helps
     
    zeha, Jun 30, 2004
    #10
  11. devon

    devon Guest

    Hi Zeha,

    I am not sure if i'm having a bad day ,but I have strange things happening. the dialogue seems to pop up with the last know dwg dir each time.

    I also think I have the code looking at the wrong dir location.

    Here is a screen shot of my proj dir...

    PROJ DIR
    -DRAWINGS
    +-------Disipline
    +-------Disipline
    +-------Disipline
    +-------Xrefs
    +-----------XR_Disipline
    +-----------XR_Disipline

    Like so. I am thinking that the functions are looking 'proj dir\drawings\disipline\xref" compared to 'proj dir\drawings\xref"

    hrmmm :-(
     
    devon, Jul 1, 2004
    #11
  12. devon

    devon Guest

    OK, I have developed this further and come up with:

    (defun c:XO ( / 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 file to open XA, XC, XM or XS" dirname "Drawings *.dwg|*.dwg|"))
    (findfile dwgname)
    )
    (if (= (getvar "sdi") 0)
    (vla-activate (vla-open (vla-get-documents (vlax-get-acad-object))dwgname))
    (if (> (getvar "dbmod") 0)(command ".open" "y" dwgname)(command ".open" dwgname))
    )
    )
    (princ)
    )

    This almost does what I want, but opens the open dialogue in the same folder as the current drawing.
    I am confused to why.

    If I have a dwg open thats in "drawings\structural" I want it to read open the file dia in "drawings\models"

    If the dwg thats open is "drawings\models\str" I want it to open the file dia in "drawings\models"


    Where have i gone wrong Zeha?

    Thanks
     
    devon, Jul 2, 2004
    #12
  13. devon

    devon Guest

    OK,
    After more mucking around, I have this...

    (defun c:XO ( / dwgname)
    (if
    (and
    (setq dwgname
    (dos_getfiled "Select file to open DWG, XA, XC, XM, XS"
    (strcat (getvar "dwgprefix") "..\\drawings\\""..\\models\\"); edit this line to something like "c:\\YourDir\\YourSubDir\\Xrefs\\"
    "All Drawings *.dwg|*.dwg|Drawing files XS*.dwg|XS*.dwg|Drawing files XC*.dwg|XC*.dwg|Drawing files XM*.dwg|XM*.dwg|Drawing files XA*.dwg|XA*.dwg|"))
    (findfile dwgname)
    )
    (command "vbastmt" (strcat "AcadApplication.Documents.Open" (chr 34) dwgname (chr 34)))
    )
    (princ)
    )

    But it's still not going into the correct sub directorys when i'm in a xref drawings. It seems to remember the last upened directory.

    Any idea why?
     
    devon, Jul 13, 2004
    #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.