Author Topic: Using (Command ".open" ... )  (Read 4765 times)

0 Members and 1 Guest are viewing this topic.

Hangman

  • Swamp Rat
  • Posts: 566
Using (Command ".open" ... )
« on: January 05, 2007, 04:35:16 PM »
I want to pick on an xref and open the drawing as a second drawing or MDI.
But when I use the (command ".open" ... ), It comes back saying unrecognizable command.
Quote
Command: (command ".open" blk-path)
.open
Command: D:\temp\Tests\Xref\2.dwg Unknown command "D:\TEMP\TESTS\XREF\2.DWG". 
Press F1 for help.

I've tried using ".fileopen", but it comes back saying it has to establish SDI mode in order to open.
Quote
Command: (command ".fileopen" blk-path)
.fileopen
Cannot run FILEOPEN if SDI mode cannot be established.

Command: D:\temp\Tests\Xref\2.dwg Unknown command "D:\TEMP\TESTS\XREF\2.DWG". 
Press F1 for help.

I'm using AutoLisp 'cause I don't know VLA yet.
If this is no longer possible with AutoLisp, can someone help me integrate it into my code ??

Thanks,
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Using (Command ".open" ... )
« Reply #1 on: January 05, 2007, 04:49:26 PM »
Here is how I do it.
Code: [Select]
(defun MyOpen (FileName ReadOnly)

(vla-Open
 (vla-get-Documents
  (vlax-get-Acad-Object)
 )
 FileName
 (if ReadOnly
  :vlax-true
  :vlax-false
 )
)
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Hangman

  • Swamp Rat
  • Posts: 566
Re: Using (Command ".open" ... )
« Reply #2 on: January 05, 2007, 05:18:01 PM »
Thanks Tim for your quick response.
So, would I work it in something like ...  (I'm just reading and editing this here, I haven't tried it yet.)

Code: [Select]
vl-load-com
...
  (command ".undo" "be")
  (setq echoprv (getvar "cmdecho")
        old_err *error*
        *error* $error
        fdiaprv (getvar "filedia")
        SDIprev (getvar "SDI"))
  (setvar "cmdecho" 1)
  (setvar "filedia" 0)
  (setvar "SDI" 0); Some users like SDI, but want to be able to open another drawing on the fly.
;
  (while (/= xref-type "INSERT")
    (setq xref-1 (entsel "\nSelect XREF to open for editing: "))
    (while (= xref-1 nil)
      (setq xref-1 (entsel "\nSelect XREF to open for editing: ")))
    (setq xref-2 (car xref-1)); gets entity name
    (setq xref-data (entget xref-2)); gets entity data
    (setq xref-type (cdr (assoc 0 xref-data)))); determines entity type
;
  (setq blk-name (cdr (assoc 2 xref-data))); gets xref name
  (setq blk-list (tblsearch "block" blk-name)); gets xref location info
  (setq blk-path (cdr (assoc 1 blk-list))); gets xref path
  (vla-Open
    (vla-get-Documents
      (vlax-get-Acad-Object))
    blk-path  ;;;                                                   ????   D:\temp\Tests\Xref\2.dwg   ????
      (if ReadOnly
        :vlax-true
        :vlax-false))
;;;(command ".open" blk-path)
;
  (setvar "filedia" fdiaprv)
  (setvar "SDI" SDIprev)
  (setvar "cmdecho" echoprv)
  (princ)
)


If I drop in the  blk-path  , will it read the entire path ??  Or do I have to spell it out ??

Thanks,
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Using (Command ".open" ... )
« Reply #3 on: January 05, 2007, 05:34:10 PM »
If the path returns a full path, then yea, but you will need to provide something else as to the 'ReadOnly' variable now.  See below.
Code: [Select]
  (vla-Open
    (vla-get-Documents
      (vlax-get-Acad-Object))
    blk-path  ;;;                                                   ????   D:\temp\Tests\Xref\2.dwg   ????
      (if ReadOnly
        :vlax-true
        :vlax-false))
Since you will most likely be making changes to the file, I would just make it look like
Code: [Select]
  (vla-Open
    (vla-get-Documents
      (vlax-get-Acad-Object))
    blk-path  ;;;                                                   ????   D:\temp\Tests\Xref\2.dwg   ????
        :vlax-false)

Edit:  One way to make sure that what is returned is a full path is to use findfile, so something like
Code: [Select]
  (vla-Open
    (vla-get-Documents
      (vlax-get-Acad-Object))
    (findfile blk-path)  ;;;                                                   ????   D:\temp\Tests\Xref\2.dwg   ????
        :vlax-false)
« Last Edit: January 05, 2007, 05:35:18 PM by T.Willey »
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Hangman

  • Swamp Rat
  • Posts: 566
Re: Using (Command ".open" ... )
« Reply #4 on: January 05, 2007, 05:44:04 PM »
OK,
so, 2 questions now.
1st, does the ReadOnly set the properties of the drawing to what is specified ??
another words, in the second example, you have only the :vlax-false
Does this set the properties of the drawing to read-write access if the drawing is currently read-only ??

2nd, will this make the new drawing being opened, the active document ??  Or does it open the drawing and then switch back to the original ??

I'm going to go try this & see what I can get, wish me luck    :-)
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Using (Command ".open" ... )
« Reply #5 on: January 05, 2007, 05:51:29 PM »
1. - This will tell Acad to open it as read only or not.  True = read only.

2. - It will open the drawing, make it active, and then switch back to the original drawing.  If you want the other one to be active, then you will have to put a statement like
Code: [Select]
(command "_.vbastmt" (strcat "documents.item \(\"" (vl-filename-base blk-path) "\"\).activate"))
Which has to be the last line in the lisp code (even if it's not, it will be executed at the end of the lisp).
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Hangman

  • Swamp Rat
  • Posts: 566
Re: Using (Command ".open" ... )
« Reply #6 on: January 05, 2007, 06:47:50 PM »
Hey Tim,
It's working well with one exception,  Your last line of code.
Quote
2. - It will open the drawing, make it active, and then switch back to the original drawing.  If you want the other one to be active, then you will have to put a statement like

Code:
(command "_.vbastmt" (strcat "documents.item \(\"" (vl-filename-base blk-path) "\"\).activate"))
Which has to be the last line in the lisp code (even if it's not, it will be executed at the end of the lisp).

It gave me an error:
Quote
Runtime error '-2147467259 (80004005)':
Automation error
Unspecified error

Here's what I have:
Code: [Select]
  (command ".undo" "be");Begin recording .undo information
  (setq echoprv (getvar "cmdecho")
        old_err *error*
        *error* $error
        fdiaprv (getvar "filedia")
        SDIprev (getvar "SDI"))
  (setvar "cmdecho" 1)
  (setvar "filedia" 0)
  (setvar "SDI" 0)
;
  (while (/= xref-type "INSERT")
    (setq xref-1 (entsel "\nSelect XREF to open for editing: "))
    (while (= xref-1 nil)
      (setq xref-1 (entsel "\nSelect XREF to open for editing: ")))
    (setq xref-2 (car xref-1)); gets entity name
    (setq xref-data (entget xref-2)); gets entity data
    (setq xref-type (cdr (assoc 0 xref-data)))); determines entity type
;
  (setq blk-name (cdr (assoc 2 xref-data))); gets xref name
  (setq blk-list (tblsearch "block" blk-name)); gets xref location info
  (setq blk-path (cdr (assoc 1 blk-list))); gets xref path
  (vla-Open
    (vla-get-Documents
      (vlax-get-Acad-Object))
    (findfile blk-path)
      :vlax-false)
;
  (setvar "filedia" fdiaprv)
  (setvar "SDI" SDIprev)
  (setvar "cmdecho" echoprv)
  (command "_.vbastmt" (strcat "documents.item \(\"" (vl-filename-base blk-path) "\"\).activate"))
  (princ)
)
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Using (Command ".open" ... )
« Reply #7 on: January 05, 2007, 06:55:21 PM »
Glad to hear it's almost there.  I guess the last line should be
Code: [Select]
(command "_.vbastmt" (strcat "documents.item \(\"" (vl-filename-base blk-path) ".dwg\"\).activate"))
It should work now that the file extention is added, sorry about that.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Hangman

  • Swamp Rat
  • Posts: 566
Re: Using (Command ".open" ... )
« Reply #8 on: January 05, 2007, 07:05:34 PM »
Hey, that did the trick.  Boy I've gotta learn this stuff.

Ya know, r2007 is not all it's cracked up to be.  It takes almost twice as long to load a drawing than it did in '06.

Thanks Tim.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Using (Command ".open" ... )
« Reply #9 on: January 05, 2007, 07:12:13 PM »
Hey, that did the trick.  Boy I've gotta learn this stuff.

Ya know, r2007 is not all it's cracked up to be.  It takes almost twice as long to load a drawing than it did in '06.

Thanks Tim.
Maybe that is why my company skipped 07 and is waiting to evaluate 08.

You're welcome.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

LE

  • Guest
Re: Using (Command ".open" ... )
« Reply #10 on: January 05, 2007, 07:34:09 PM »