Yes its clear what you are trying to do, I was merely pointing out that
GetObject can't accomplish that. However, maybe you are trying to do more
than you need to. I can't think of any commercial app that does that.
Wouldn't the user know if they already have the dwg open? Its not always
possible or advisable to code for every contingency. As a programmer, you
usually have to make some assumptions about the environment you work in.
That determines the way your program works, and then the users learn your
program. For example, I have one Acess app I use, where the user selects
text from acad wiring schedules to import into a table for printing wiring
tags. Rather than try and figure out all the possibilities of drawing
combinations, I just have the user open the one they need first. Its still
the same amount of steps for the user, but the code logic is much simpler.
See here:
On Error Resume Next
'If acad is open, assume the active drawing is the one they need.
Set acad = GetObject(, "AutoCAD.Application")
If Err <> 0 Then
Set acad = CreateObject("AutoCAD.Application")
acad.Visible = True
AppActivate acad.Caption
'User needs to navigate to the right drawing.
acad.ActiveDocument.Utility.Prompt "Open the drawing file first and
then re-execute this command!"
Exit Sub
End If
They quickly learn that they need the right drawing open before they run the
command.
--
----
Ed
----
"Mark Propst" wrote in message
news:405a5136_3@newsprd01...
> Hi Ed,
> Thanks for staying with me on this. I apologize if I'm just beating a
dead
> horse here.
> It seems to me that this would be a very normal and usual thing that
> everyone would need to be able to do...but since I'm the only one beating
my
> head on this wall I guess that shows just how really ABnormal I am!!!
> :-)
> (but then we already knew that eh?)
>
> I'm may not have explained what I want to accomplish clearly enough.
> It also may be that I'm trying to do something that is not possible.
> Furthermore, it is probably not absolutely necessary to do what I want
> either since I'm just writing routines that I will use and I can then work
> around their limitations and work in a controlled environment, eg: not
call
> this function when a running instance of acad exists with the target
drawing
> open if more that one acad is running and if the open target drawing is
not
> in the first session started. No big deal really, I just thought that if
> there were a way, then a generic getacad function should utilize it....I
> didn't realize it was going to be such a headache!
> |:-\ <----(flattened head from banging on desk)
>
> (If this app were for the open market I would think it would have to have
a
> more robust method of acquiring a specific drawing whether or not it was
> open and whether or not multiple instances of acad were running and
whether
> or not the open dwg was in the first instance of acad to have been started
> during that editing session. So I assumed the power houses here would
> already know how to do this, but maybe...........)
>
> As it stands, if the drawing is open in the first instance, or if there's
> only one instance, or if the drawing is not open in any instance, or if
> there are no instances of acad running then it will work as desired.
> However if the sdwg is open, and there are more than one acad running, and
> the open sDwg is not in the first acad started(AcadInstance1), then it
does
> not work....in the sense that instead of returning the open sDwg (in
> AcadInstance1+x), AcadInstance1 opens a read only copy of sDwg and
returns
> that document object.
>
> Is it clear what I'm trying to do?
> Is it just not possible?
> Or am I just being dense?
>
>
> "Ed Jobe" wrote in message
> news:405a3b20$1_2@newsprd01...
> > Mark, I think this exerpt from vb help is the key to your problem.
> > "If the pathname argument is omitted, GetObject returns a currently
active
> > object of the specified type."
>
> I'm well familiar with that section (believe me, I've read the help files
> many many times on this and many many hours on google) but I don't see
that
> this is the key to my problem.
> Maybe I'm not understanding something correctly. (oooh now that would be
> different! lol)
> That statement to me means that if I call GetObject(, AcadApplication)
then
> that will return a running instance of acad if one exists, (otherwise it
> will raise an error.)
> so far so good....but not what I'm trying to acomplish....
>
> > You're probably thinking that if no dwg with that name is open, then it
> > would error.
>
> hmmm...don't understand where you got that idea....
> no, if I call GetObject(sDwg), and acadInstance1 is running, and sDwg is
not
> open, it doesn't error, acadInstance1 opens the dwg. - that part is fine
>
> If I call GetObject(sDwg), and acadInstance1 is running, and sdwg is open
in
> that instance, it returns the sdwg. - that part is fine
>
> If I call GetObject(sDwg), and there is no acad session running, it opens
> acad and opens the dwg - that part is fine
>
> If I call GetObject(sDwg), and multiple AcadInstances(1 to 1+X) are
running,
> and sdwg is open in AcadInstance(>1), AcadInstance1 opens sdwg as ReadOnly
> and that is the document object returned. - *that is the problem I'm
trying
> to solve.*
>
> > The behavior to get the currently active type is only available
> > if you leave the path blank.
>
> hmmm.....that doesn't seem to be the case or I don't understand that
> statement.
> If one or more acad is running (currently active type) and I call
> GetObject(sDwg), the first instance of acad will open sDwg and return the
> document object.
> Oh, maybe that's what you mean...instead of returning the class
application
> it returns the class document...is that what you mean??? but that's no
> problem cause you then just get the application object from the document
> object (as you know) so I'm not sure what that statement refers to
> exactly...
>
>
> > In my test, with acad not open, it opened acad
> > and then the dwg.
>
> Right, that part works fine!
> If the dwg is not open or acad is not open, no problem.
> If the dwg is not open and acad is open, also no problem
> If acad is open (more than one) and the dwg is also open and the dwg is
not
> in acadInstance(1)...***problem***
>
> >It works like ShellExecuteEx. I don't see a way (at least
> > with this function) to test if the dwg is already open.
>
> *That's* the key to my problem (as I see it). I was hoping you had an
> answer for how to do that.(obviously not with *this* function since it's
not
> working in that case...but with some *other* function or some addition or
> change to this function!)
>
> As I see it, this is what I want to be able to do, but dont' know how:
> Check all running instances of acad (as if there were a collection of
> running instances)
>
> On Error Resume Next
> For Each RunningAcad in RunningAcads
> Set oDoc = RunningAcad.Documents.Item(sDwg)
> If Not Err Then
> ...sDwg is open....Use(RunningAcad)
> Exit For
> End if
> Next RunningAcad
>
> That's what I'm trying to do and cant find a way to.
> Is there a way with some Api call???
>
> >If it opens
> > read-only, you could assume that it was. :-)
>
> Yes, but then there's no way to get the document object that is *not* read
> only...so thats the problem. GetObject will only return
> RunningInstance#1....how to access RunningInstance1+x is what I'm looking
> for...
>
> Do you know a solution to that problem? or am I trying to do the
> impossible.?
>
> Again, Thank you very much for your thoughts and ideas. You are always an
> invaluable treasure house of knowlege and insight and I appreciate you
> taking your time with my trifling questions! Hope I'm not being too much
of
> a pest!...well, yeah I know I *am*...but I hope your forbearance and
> infinite patience will overlook that fact
> :-)
>
> Mark
>
>