CAD/CAM discussion forum > CAD > Restore ZWCAD window with VBA

Restore ZWCAD window with VBA

Rank: 1

OldForumPost

Newbie

posts: 0

Registered: 2012-1-14

Message 1 of 1

 Restore ZWCAD window with VBA
01-01-1970 08:00 . am | View his/her posts only
Hello
We are testing ZWCAD to replace AutoCad in our office. I have written a lot of code in vba and am trying to convert it. I wrote some code that opens a text file of YXZ co-ordinates and inserts a block with attributes for each point in the file. It was very easy to get it working in ZWCAD.

My problem is that when I close the VBA program window, I am returned to the vba editor. I would like to close the program and remain in ZWCAD.

Thank you
John

Here is the code
Private Sub CommandButton1_Click()
Dim insertionPoint(0 To 2) As Double
Dim BlockObj As ZwcadBlock
Dim blockRefObj As ZwcadBlockReference
Dim varAttributes As Variant
UserForm1.Hide
insertionPoint(0) = 0
insertionPoint(1) = 0
insertionPoint(2) = 0
'insert one block and delete it
Set blockRefObj = ThisDocument.ModelSpace.InsertBlock(insertionPoint, "PT250", 1#, 1#, 1#, 0)
blockRefObj.Delete
'open points file
CommonDialog1.Filter = "Text (*.txt)|*.txt|GRE files (*.gre)|*.gre|All files (*.*)|*.*"
CommonDialog1.DefaultExt = "txt"
CommonDialog1.DialogTitle = "Select File"
CommonDialog1.ShowOpen
Open CommonDialog1.FileName For Input As #1
insert the blocks
Do
Input #1, a$
one% = InStr(1, a$, " ")
n$ = Mid(a$, 1, one% - 1)
a$ = Trim(Mid(a$, one%, Len(a$) - one% + 1))

one% = InStr(1, a$, " ")
y$ = Mid(a$, 1, one%)
a$ = Trim(Mid(a$, one%, Len(a$) - one% + 1))

one% = InStr(1, a$, " ")
x$ = Mid(a$, 1, one% - 1)

z$ = Trim(Mid(a$, one%, Len(a$) - one% + 1))

insertionPoint(0) = Val(y$)
insertionPoint(1) = Val(x$)
insertionPoint(2) = Val(z$)

'Set blockObj = ThisDrawing.Blocks.Add(insertionPoint, "pt250")
Set blockRefObj = ThisDocument.ModelSpace.InsertBlock(insertionPoint, "PT250", 1#, 1#, 1#, 0)
' Get the attributes for the block reference
varAttributes = blockRefObj.GetAttributes
'blockrefobject.
varAttributes(0).TextString = n$
varAttributes(1).TextString = z$

Loop Until EOF(1)
Close
ThisDocument.Application.ZoomExtents
UserForm1.Show
End Sub
See also