Click Block Open

Discussion in 'AutoCAD' started by izzy, Feb 26, 2004.

  1. izzy

    izzy Guest

    Please help. Somehow skips open command and tells me my filename is an unknown command.

    ;Click block open
    (defun C:BO ()
    (setq Ent (car (entsel "\nSelect a block to open: "))
    Entlist (entget Ent))
    (setq blockname (cdr (assoc 2 Entlist)))
    (setq fname (strcat (getvar "DWGPREFIX") blockname ".dwg"))
    (command "OPEN" fname)
    (princ)
    ); end
     
    izzy, Feb 26, 2004
    #1
  2. izzy

    apc Guest

    I've tried to use the open command in lisp by use of the (command "open" filename) and never got it to work (if someone knows how to properly execute this I would be very interested in knowing how to do so). Although, as a work around you could start another instance of autocad by means of:
    (STARTAPP "ACAD" "yourpathetcetc")
     
    apc, Feb 26, 2004
    #2
  3. izzy

    Jeff Mishler Guest

    Use this in place of (command "open"):
    (if (findfile fname)
    (progn
    (if (= (getvar "SDI") 0)
    (vla-open (vla-get-documents (vlax-get-acad-object)) fname)
    (vla-open (vla-get-activedocument (vlax-get-acad-object)) fname)
    )
    )
    (princ "\nFile not found")
    )

    Jeff

    filename) and never got it to work (if someone knows how to properly execute
    this I would be very interested in knowing how to do so). Although, as a
    work around you could start another instance of autocad by means of:
     
    Jeff Mishler, Feb 26, 2004
    #3
  4. izzy

    izzy Guest

    Thanks Jeff.
     
    izzy, Feb 27, 2004
    #4
  5. izzy

    ECCAD Guest

    Jeff,
    I tried your example, neat. Only thing is, I had to add:
    (vl-load-com)
    to get vlx functions loaded, no problem. I did notice that the
    'block' chosen has to be in 'current' folder - with the open .dwg at hand. Also, when opening, it didn't show up on-screen, had to 'switch' screens. Is there a way to 'make' the block chosen - the 'current' drawing ?

    Bob
     
    ECCAD, Feb 27, 2004
    #5
  6. izzy

    izzy Guest

    This is the way BO looks after Jeff's help. Expanding it to include support directory would be a plus if someone has time. See RED below for lisp ot redefine block after revisions.

    ;Select block open
    (defun C:BO ()
    (setq Ent (car (entsel "\nSelect a block to open: "))
    Entlist (entget Ent))
    (setq blockname (cdr (assoc 2 Entlist)))
    (setq fname (strcat (getvar "DWGPREFIX") blockname ".dwg"))
    (if (findfile fname)
    (progn
    (if (= (getvar "SDI") 0)
    (vla-open (vla-get-documents (vlax-get-acad-object)) fname)
    (vla-open (vla-get-activedocument (vlax-get-acad-object)) fname)
    )
    )
    (princ "\nFile not found")
    )
    (princ)
    ); end

    (defun c:RED ()
    (setq attreq (getvar "attreq"))
    (setvar "attreq" 0)
    (while (not (setq ename (entsel "\nSelect Block to replace: "))))
    (setq ename (car ename))
    (setq pt (cdr (assoc 10 (entget ename))))
    (setq blkname (cdr (assoc 2 (entget ename))))
    (setq rot (angtos (cdr (assoc 50 (entget ename)))))
    (setq xscl (cdr (assoc 41 (entget ename))))
    (setq yscl (cdr (assoc 42 (entget ename))))
    (setq zscl (cdr (assoc 43 (entget ename))))
    (setq attlist (getatts ename))
    (entdel ename)
    (command ".insert" (strcat blkname "=") pt "x" xscl yscl zscl rot)
    (setatts (entlast) attlist)
    (setvar "attreq" attreq)
    (princ)
    )

    (defun GetAtts (Obj)
    (setq obj (vlax-ename->vla-object obj))
    (mapcar
    '(lambda (Att)
    (cons (vla-get-TagString Att) (vla-get-TextString Att))
    )
    (vlax-invoke Obj "GetAttributes")
    )
    )

    (defun SetAtts (Obj Lst / AttVal)
    (setq obj (vlax-ename->vla-object obj))
    (mapcar
    '(lambda (Att)
    (if (setq AttVal (cdr (assoc (vla-get-TagString Att) Lst)))
    (vla-put-TextString Att AttVal)
    )
    )
    (vlax-invoke Obj "GetAttributes")
    )
    (vla-update Obj)
    (princ)
    ); end
     
    izzy, Feb 27, 2004
    #6
  7. izzy

    Jeff Mishler Guest

    Hi Bob,
    I keep forgetting about the (vl-load-com) because I have it autoload in my
    acaddoc.lsp file.

    As for the current folder, that's just how the OP wrote it......

    As for making the block drawing current, I'm not sure what's going on
    because the help says for "Open":
    "Opens an existing drawing file (DWG) and makes it the active document"

    I think it has to do with lisp and only being able to operate in one
    drawing.....I suppose you could add (vla-put-activedocument
    (vlax-get-acad-object) fname), but then the routine wouldn't complete until
    you return to the original drawing.

    Jeff

    Also, when opening, it didn't show up on-screen, had to 'switch' screens. Is
    there a way to 'make' the block chosen - the 'current' drawing ?
     
    Jeff Mishler, Feb 27, 2004
    #7
  8. izzy

    ECCAD Guest

    Jeff,
    Thanks.
    Yes, I realize the OP wrote it..
    Once a 'block' is chosen, you could 'wblock' it to a known location, then open it..
    I'm running R2002 still, got to update (have no machine with XP..).
    I see the problem with (vla-put-activedocument
    (vlax-get-acad-object) fname), while still in 'active' document.
    Just wondered how to 'open' yet another .dwg, and jump out of the 'active' one. Hmm.

    Bob
     
    ECCAD, Feb 27, 2004
    #8
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.