Close Method

Close Method

Anonymous
Not applicable
758 Views
13 Replies
Message 1 of 14

Close Method

Anonymous
Not applicable
The close medhod stops the execution of my VBA program.

I am in a drawing and run a VBA program. The program opens up an existing drawing extracts out some block information, closes the drawing then attempts to use the information in the current drawing. Yesterday it would not work then it started working for some unknow reason. Now today it doesn't work. The code works fine if I comment out the close command.

What am I doing wrong.

Wayne Lefferd
0 Likes
759 Views
13 Replies
Replies (13)
Message 2 of 14

Anonymous
Not applicable
Wayne:

What version of AutoCAD are you using? 
What is the value of your SDI variable?  (This determines if you can
have multiple drawings open.) If you could post your code it might help diagnose
the problem.

 

Thanks,

Andy Roe

 



style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">The
close medhod stops the execution of my VBA program.

I am in a drawing and run a VBA program. The program opens up an existing
drawing extracts out some block information, closes the drawing then attempts
to use the information in the current drawing. Yesterday it would not work
then it started working for some unknow reason. Now today it doesn't work. The
code works fine if I comment out the close command.

What am I doing wrong.

Wayne Lefferd

0 Likes
Message 3 of 14

Anonymous
Not applicable
If you have no document open after you execute the Close
method

then that is your problem. You will not be able
to interact with AutoCAD

without a Document object.

 

Joe

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
The
close medhod stops the execution of my VBA program.

I am in a drawing and run a VBA program. The program opens up an existing
drawing extracts out some block information, closes the drawing then attempts
to use the information in the current drawing. Yesterday it would not work
then it started working for some unknow reason. Now today it doesn't work. The
code works fine if I comment out the close command.

What am I doing wrong.

Wayne Lefferd

0 Likes
Message 4 of 14

Anonymous
Not applicable
This is a copy of most of the code. I have added as many comments as I can so someone might beable to follow it. there are 2 or 3 functions that are called that are in dll's and are not here.

Wayne Lefferd



Sub aaa()
Dim xxx As Variant
Dim Cnt As Integer
Dim XrefName As Variant


XrefName = wl.Get_XrefName 'returns an array of xref names in the drawing this function is in a dll and not here
xxx = Image_List_From_Xref(XrefName(0)) 'returns an array of the block names in the drawing that is xref in the drawing
' the program is not continuming beyond this point
If VarType(xxx) > 8000 Then 'check to see if the above function retruned an array or not
xxx(21, 0) = xxx(21, 0) ' the rest of this is just checking to see what was returned
xxx(21, 1) = xxx(21, 1)
xxx(21, 2)(0) = xxx(21, 2)(0)
xxx(21, 3) = xxx(21, 3)
xxx(1, 0) = xxx(1, 0)
Cnt = UBound(xxx)
Cnt = Cnt
End If
End Sub


Function Image_List_From_Xref(ByVal XrefName As String)
Dim ent As AcadEntity
Dim SSet1 As AcadSelectionSet
Dim TempSortedList As Variant
Dim TempArray() As Variant
Dim Cnt As Integer
Dim Image_Name As String
Dim TempUnSortedList As Variant

ThisDrawing.Application.Documents.Open XrefName + ".dwg", True ' opens the xref drawing in read only mode

TempUnSortedList = ImageBlock_List 'returns a list of the blocks in an unsorted older

If VarType(TempUnSortedList) > 8000 Then ' if there are no image blocks the function will return 0
TempSortedList = wl.ArraySorter(TempUnSortedList) 'sorts the array of block names. this function is in a dll and not here
ReDim TempArray(UBound(TempSortedList), 3) ' sets up a two dim array the length of the block list

For Cnt = 0 To UBound(TempSortedList) 'goes theough the sorted block name list looking for additional info about the blocks
Image_Name = TempSortedList(Cnt) 'gets an single block name to get info on
Set SSet1 = wl.Make_Selection_Set_All(0, "INSERT", 2, Image_Name) ' sets up a selection set for all inserted items with a certain named block
If SSet1.Count > 0 Then 'makes sure it found at least one block with the correct name
For Each ent In SSet1 'pulling off data from block
TempArray(Cnt, 0) = ent.Name
TempArray(Cnt, 1) = ent.Name
TempArray(Cnt, 2) = ent.insertionPoint
TempArray(Cnt, 3) = ent.XScaleFactor
Next ent
End If
Next Cnt
Image_List_From_Xref = TempArray 'sets up to return array if it has any information
Else
Image_List_From_Xref = 0 ' set up to return 0 if it found nothing
End If
ThisDrawing.Close , False 'closes the drawing and does not save, must have false because drawing opened in read only mode
' it works fine (except for closing the drawing) if I comment out this line
End Function




Function ImageBlock_List()
Dim Block_Names() As String
Dim ent As AcadEntity
Dim SSet1 As AcadSelectionSet
Dim Cnt As Integer
Set SSet1 = wl.Make_Selection_Set_All(0, "INSERT", 2, "Image_*") ' returns a selection set for all inserts in drawing with names starting with "Image_*"

If SSet1.Count > 0 Then ' stops if it found no matches
ReDim Block_Names(SSet1.Count - 1)
For Each ent In SSet1 ' getting name off blocks
Block_Names(Cnt) = ent.Name ' puts names in array
Cnt = Cnt + 1
Next ent
End If

ImageBlock_List = wl.ArraySorter(Block_Names) 'returns sorted array of block names. function not here its in dll


End Function
0 Likes
Message 5 of 14

Anonymous
Not applicable
The document that I had originally opened is never closed. When the program stops that drawing is on the screen.

Wayne
0 Likes
Message 6 of 14

Anonymous
Not applicable
What exactly are you getting for feedback from
AutoCAD?

 

Joe


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
This
is a copy of most of the code. I have added as many comments as I can so
someone might beable to follow it. there are 2 or 3 functions that are called
that are in dll's and are not here.

Wayne Lefferd



Sub aaa()
Dim xxx As Variant
Dim Cnt As Integer
Dim XrefName As
Variant


XrefName = wl.Get_XrefName 'returns an array of xref names in the drawing
this function is in a dll and not here
xxx =
Image_List_From_Xref(XrefName(0)) 'returns an array of the block names in the
drawing that is xref in the drawing

                                   '
the program is not continuming beyond this point
If VarType(xxx) > 8000
Then 'check to see if the above function retruned an array or not
xxx(21,
0) = xxx(21, 0) ' the rest of this is just checking to see what was returned

xxx(21, 1) = xxx(21, 1)
xxx(21, 2)(0) = xxx(21, 2)(0)
xxx(21, 3) =
xxx(21, 3)
xxx(1, 0) = xxx(1, 0)
Cnt = UBound(xxx)
Cnt = Cnt

End If
End Sub


Function Image_List_From_Xref(ByVal XrefName As String)
Dim ent As
AcadEntity
Dim SSet1 As AcadSelectionSet
Dim TempSortedList As Variant

Dim TempArray() As Variant
Dim Cnt As Integer
Dim Image_Name As
String
Dim TempUnSortedList As Variant

ThisDrawing.Application.Documents.Open XrefName + ".dwg", True ' opens the
xref drawing in read only mode

TempUnSortedList = ImageBlock_List 'returns a list of the blocks in an
unsorted older

If VarType(TempUnSortedList) > 8000 Then ' if there are no image blocks
the function will return 0

        TempSortedList =
wl.ArraySorter(TempUnSortedList) 'sorts the array of block names. this
function is in a dll and not here

        ReDim
TempArray(UBound(TempSortedList), 3) ' sets up a two dim array the length of
the block list

For Cnt = 0 To UBound(TempSortedList) 'goes theough the sorted block name
list looking for additional info about the blocks

            Image_Name
= TempSortedList(Cnt) 'gets an single block name to get info on

            Set
SSet1 = wl.Make_Selection_Set_All(0, "INSERT", 2, Image_Name) ' sets up a
selection set for all inserted items with a certain named block

            If
SSet1.Count > 0 Then 'makes sure it found at least one block with the
correct name

                For
Each ent In SSet1 'pulling off data from block

                    TempArray(Cnt,
0) = ent.Name

                    TempArray(Cnt,
1) = ent.Name

                    TempArray(Cnt,
2) = ent.insertionPoint

                    TempArray(Cnt,
3) = ent.XScaleFactor

                Next
ent

            End
If
        Next Cnt

        Image_List_From_Xref =
TempArray 'sets up to return array if it has any information

    Else

        Image_List_From_Xref = 0 '
set up to return 0 if it found nothing
End If
ThisDrawing.Close ,
False 'closes the drawing and does not save, must have false because drawing
opened in read only mode

                                    '
it works fine (except for closing the drawing) if I comment out this line

End Function




Function ImageBlock_List()
Dim Block_Names() As String
Dim ent As
AcadEntity
Dim SSet1 As AcadSelectionSet
Dim Cnt As Integer
Set
SSet1 = wl.Make_Selection_Set_All(0, "INSERT", 2, "Image_*") ' returns a
selection set for all inserts in drawing with names starting with "Image_*"

If SSet1.Count > 0 Then ' stops if it found no matches

    ReDim Block_Names(SSet1.Count - 1)

    For Each ent In SSet1 ' getting name off blocks

              Block_Names(Cnt)
= ent.Name ' puts names in array

              Cnt
= Cnt + 1
    Next ent
End If

ImageBlock_List = wl.ArraySorter(Block_Names) 'returns sorted array of
block names. function not here its in dll


End Function

0 Likes
Message 7 of 14

Anonymous
Not applicable
My SDI is set to have multiple drawings open and I am useing autocad 2000. Would you happen to know if any of the VBA functions such as Purge or Explode have been fixed in 2002 or does all the functions work the same.
I put my code in another reply. I commented it as much as I could because the best of code is hard to follow and mine is not the best code.

Wayne
0 Likes
Message 8 of 14

Anonymous
Not applicable
It just stops no errors on comments on nothing. The program does not hang it just quits.
0 Likes
Message 9 of 14

Anonymous
Not applicable
I guess I should of said AutoCad is still running my VBA program just stops.
0 Likes
Message 10 of 14

Anonymous
Not applicable
What are you expecting it to do after the .Close
method?

 

Where is the code for that?

 

Joe


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
I
guess I should of said AutoCad is still running my VBA program just
stops.
0 Likes
Message 11 of 14

Anonymous
Not applicable
In the sub aaa there is a line
xxx = Image_List_From_Xref(XrefName(0))
That function has the close method in it and should return
a multi dim array.

the line below that
If VarType(xxx) > 8000 Then
check to see if it returned an array or not
the lines below that are just reading the array if it returned one.

What I am doing to see it it is working is in the VBA editor
putting one of the brown dots in the margin which stops the execution of the code at that spot and lets you read the variables before it in that sub or function it was stopped in. If the line I choose to stop on is not run it does not stop. I should be able to stop on the line
If VarType(xxx) > 8000 Then
because should run the If statement wether or not an array was returned. But the program goes right past the statement and terminates which makes me thing it has terminated before that. If I comment out the close statement it works fine except for not closeing the drawing.

Wayne
0 Likes
Message 12 of 14

Anonymous
Not applicable
My suggestion would be to open the DWG file outside
of the AutoCAD editor using the AxDbDocument object. (You need to register
AXDB15.DLL on your machine.)

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
In
the sub aaa there is a line
xxx = Image_List_From_Xref(XrefName(0))

That function has the close method in it and should return
a multi dim
array.

the line below that
If VarType(xxx) > 8000 Then
check to see if
it returned an array or not
the lines below that are just reading the
array if it returned one.

What I am doing to see it it is working is in the VBA editor
putting
one of the brown dots in the margin which stops the execution of the code at
that spot and lets you read the variables before it in that sub or function it
was stopped in. If the line I choose to stop on is not run it does not stop. I
should be able to stop on the line
If VarType(xxx) > 8000 Then

because should run the If statement wether or not an array was returned.
But the program goes right past the statement and terminates which makes me
thing it has terminated before that. If I comment out the close statement it
works fine except for not closeing the drawing.

Wayne

0 Likes
Message 13 of 14

Anonymous
Not applicable
Wayne:

I took a look at your code, but it's difficult
to diagnose what's going on if you have additional DLLs that aren't included in
your posting.  If you'd rather not post that code, you can email the DLLs
and I could take a look.

 

Regards,

Andy Roe



style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
My
SDI is set to have multiple drawings open and I am useing autocad 2000. Would
you happen to know if any of the VBA functions such as Purge or Explode have
been fixed in 2002 or does all the functions work the same.
I put my code
in another reply. I commented it as much as I could because the best of code
is hard to follow and mine is not the best code.

Wayne

0 Likes
Message 14 of 14

Anonymous
Not applicable
Howdy,


Ok, here is your problem. You need to have code like the following to open
your drawing and assign your drawing to a variable.


'Assign the AcadDocument object to a variable. This will hold the drawing
that is currently being opened
Dim NewDWG as AcadDocument

'To open a dwg
Set NewDWG=application.documents.open (
here>)
'set this to ensure that the newly opened drawing is active and given the
focus
newdwg.activate

'to close the dwg without closing AutoCAD
NewDWG.close



"Jorge Lopez" wrote in message
news:3FAEE427B568B17D74869AE6DA620469@in.WebX.maYIadrTaRb...
My suggestion would be to open the DWG file outside of the AutoCAD editor
using the AxDbDocument object. (You need to register AXDB15.DLL on your
machine.)

"wlefferd" wrote in message
news:f06417c.9@WebX.maYIadrTaRb...
In the sub aaa there is a line
xxx = Image_List_From_Xref(XrefName(0))
That function has the close method in it and should return
a multi dim array.
the line below that
If VarType(xxx) > 8000 Then
check to see if it returned an array or not
the lines below that are just reading the array if it returned one.
What I am doing to see it it is working is in the VBA editor
putting one of the brown dots in the margin which stops the execution of the
code at that spot and lets you read the variables before it in that sub or
function it was stopped in. If the line I choose to stop on is not run it
does not stop. I should be able to stop on the line
If VarType(xxx) > 8000 Then
because should run the If statement wether or not an array was returned. But
the program goes right past the statement and terminates which makes me
thing it has terminated before that. If I comment out the close statement it
works fine except for not closeing the drawing.
Wayne
0 Likes