.NET

Reply
*Russ Green
Message 1 of 15 (280 Views)

several vb.net issues

280 Views, 14 Replies
01-04-2006 12:33 AM
Basically I'm building a Batch Script processor and my code loops through
file names in a listview. It all seems to work failry well but I've now
noticed that the dwg's open in read only mode. Very odd. My code is below.

Another question is can autocad accept multiple commands at once. Do I force
my app to wait for autocad to complete the commands I send before sending
more commands? i.e. I want to wait for the scripts to finish running before
my app tries to save the drawing.

TIA

Russ

CODE:::

For i As Integer = 0 To Me.ListView1.Items.Count - 1
'open the file
Me.sbpText.Text = "Opening file..."
file =
ApplicationServices.Application.DocumentManager.Open(Me.ListView1.Items.Item(i).Text,
False)

'process the script
Me.sbpText.Text = "Running script..."

'set filedia to 0
ApplicationServices.Application.SetSystemVariable("filedia", 0)
'file.SendStringToExecute("filedia ", True, False, True)
'file.SendStringToExecute("0 ", True, False, True)

'load the script
file.SendStringToExecute("script ", True, False, True)
file.SendStringToExecute("""" & Me.txtScript.Text & """" & vbCr,
True, False, True)

'set filedia to 1
ApplicationServices.Application.SetSystemVariable("filedia", 1)
'file.SendStringToExecute("filedia ", True, False, True)
'file.SendStringToExecute("1 ", True, False, True)

If file.IsReadOnly = True Then
MsgBox("file is readonly", MsgBoxStyle.Critical)
End If

'close the file
Me.sbpText.Text = "Saving & closing file..."

Try
file.CloseAndSave(Me.ListView1.Items.Item(i).Text)
Catch ex As Exception
MsgBox(ex.Source & " : " & ex.Message)
End Try

'advance the progress bar
spb.ProgressBar.Value = spb.ProgressBar.Value + 1
Next
*Russ Green
Message 2 of 15 (280 Views)

Re: several vb.net issues

01-05-2006 12:11 AM in reply to: *Russ Green
I'm getting a little confused here guys. I was getting frustrated trying to
get my dll working correctly so I wrote an exe using Interop. Gues
what....it works.

When I tried to go back to my DLL with almost the same code, no joy.
FILEDIA gets set to 0 OK (I also wrap the looping code in a try catch
finally that sets FILEDIA back to 1). I know from stepping through the code
that everyline is processed but for some reason AutoCAD is not processing
the script and the modified date of DWG's I process doesn't change.

Any ideas?

Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Interop.Common

Public WithEvents AcadApp As Autodesk.AutoCAD.Interop.AcadApplication
Dim AcadDoc As Autodesk.AutoCAD.Interop.AcadDocument

Sub ProcessDwg(ByVal ThisDwg As String)
'open the file
AcadDoc.Application.Documents.Open(ThisDwg)
AcadDoc = AcadApp.ActiveDocument
'AcadApp.ZoomExtents()

'process the script
AcadDoc.SetVariable("filedia", 0)

AcadDoc.SendCommand("script" & vbCr & """" & Me.txtScriptFile.Text &
"""" & vbCr)

AcadDoc.SetVariable("filedia", 1)

'close the file
AcadDoc.Close(Me.chkSaveDWG.Checked, ThisDwg)
End Sub


Imports acadApp = Autodesk.AutoCAD.ApplicationServices.Application
Imports acadDoc = Autodesk.AutoCAD.ApplicationServices.Document

Dim file As acadDoc

Sub ProcessDwg(ByVal ThisDwg As String)

acadApp.DocumentManager.Open(ThisDwg)
file = acadApp.DocumentManager.MdiActiveDocument
'AcadApp.ZoomExtents()

'process the script
acadApp.SetSystemVariable("filedia", 0)

file.SendStringToExecute("script" & vbCr & """" & Me.txtScript.Text
& """" & vbCr, False, False, False)

acadApp.SetSystemVariable("filedia", 1)

'close the file
file.CloseAndSave(ThisDwg)
End Sub
Distinguished Contributor
NathTay
Posts: 1,691
Registered: ‎12-15-2003
Message 3 of 15 (280 Views)

Re: several vb.net issues

01-05-2006 01:56 PM in reply to: *Russ Green
Try.

Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Interop.Common

Public WithEvents AcadApp As Autodesk.AutoCAD.Interop.AcadApplication
Dim AcadDoc As Autodesk.AutoCAD.Interop.AcadDocument

Sub ProcessDwg(ByVal ThisDwg As String)
'open the file
AcadDoc = AcadApp.Documents.Open(ThisDwg)
'AcadApp.ZoomExtents()

'process the script
AcadDoc.SetVariable("filedia", 0)

AcadDoc.SendCommand("script" & vbCr & """" & Me.txtScriptFile.Text &
"""" & vbCr)

Do Until AcadApp.GetAcadState.IsQuiescent = True
Loop

AcadDoc.SetVariable("filedia", 1)

'close the file
AcadDoc.Close(Me.chkSaveDWG.Checked, ThisDwg)
End Sub
*Russ Green
Message 4 of 15 (280 Views)

Re: several vb.net issues

01-05-2006 04:22 PM in reply to: *Russ Green
thanks but that seems not to be working either.

wrote in message news:5051790@discussion.autodesk.com...
Try.

Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Interop.Common

Public WithEvents AcadApp As Autodesk.AutoCAD.Interop.AcadApplication
Dim AcadDoc As Autodesk.AutoCAD.Interop.AcadDocument

Sub ProcessDwg(ByVal ThisDwg As String)
'open the file
AcadDoc = AcadApp.Documents.Open(ThisDwg)
'AcadApp.ZoomExtents()

'process the script
AcadDoc.SetVariable("filedia", 0)

AcadDoc.SendCommand("script" & vbCr & """" & Me.txtScriptFile.Text &
"""" & vbCr)

Do Until AcadApp.GetAcadState.IsQuiescent = True
Loop

AcadDoc.SetVariable("filedia", 1)

'close the file
AcadDoc.Close(Me.chkSaveDWG.Checked, ThisDwg)
End Sub
*Russ Green
Message 5 of 15 (280 Views)

Re: several vb.net issues

01-05-2006 04:26 PM in reply to: *Russ Green
project attached if anyone would be so kind as to take a look
Distinguished Contributor
cgay
Posts: 125
Registered: ‎08-02-2005
Message 6 of 15 (280 Views)

Re: several vb.net issues

01-08-2006 03:17 PM in reply to: *Russ Green
Russ,

I reworked some stuff in your example. Take a look.

C

Let me know if this works for you. It worked with your included samples on my system.

Message was edited by: CougerAC
*Russ Green
Message 7 of 15 (280 Views)

Re: several vb.net issues

01-15-2006 04:39 PM in reply to: *Russ Green
thanks for that and sorry for not replying sooner but I've been out of the
country. Some interesting and useful pointers in your comments but stiull
my script does not execute on my drawings.

Russ

wrote in message news:5053590@discussion.autodesk.com...
Russ,

I reworked some stuff in your example. Take a look.

C

Let me know if this works for you. It worked with your included samples on
my system.

Message was edited by: CougerAC
Distinguished Contributor
cgay
Posts: 125
Registered: ‎08-02-2005
Message 8 of 15 (280 Views)

Re: several vb.net issues

01-16-2006 06:58 AM in reply to: *Russ Green
Russ,

Did the script run at all? It appears on closer inspection that the script is running, but there are errors in the script that prevent it from running successfully. Also, the script relies on the AutoCAD document satisfying some requirements. If these requirements are not met, the script cannot continue. For instance, if you try to load a drawing that doesn't contain any drawn objects, but contains unreferenced blocks that you want purged, the script will never execute the purge commands because the commands before try to select all objects, which when none are found, continues to prompt for a selection. You need to issue a cancel in the script before running the next command or else the script will not complete.

You say that the scripts aren't running. Does that mean "At all?".
Are their error messages?
Can you write a simpler script that inserts a circle or something at say point 0,0? Does this work for all documents?

Also, your script relies on a LISP file being loaded. So what happens if that LISP file is not found?

Try to issue the commands yourself and see if it follows the script exactly. I have not been able to successfully do this.

If you don't need the flexibility of changing the script file, consider adding code to the project that does what you want. You may find that you need to used both managed objects and Interop to get the job done, but you will be able to cope with errors, i.e. no objects to select, so skip operations that need selected objects.

Good Luck,
C
*Russ Green
Message 9 of 15 (280 Views)

Re: several vb.net issues

01-16-2006 11:45 AM in reply to: *Russ Green
thanks,

I can't exactly tell if the script is running or not but the drawing doesn't
look like it should when complete. i've tried running the script files from
tools>run script... and the scripts run without error.

i tried commenting out the file.closeandsave line and run the dll again.
basically, the drawings appear to be opening as read only. i think now that
the scripts probably are running but the files aren't saving, either with
the qsave in the script or with the file.closeandsave line in the code.

russ


wrote in message news:5060035@discussion.autodesk.com...
Russ,

Did the script run at all? It appears on closer inspection that the script
is running, but there are errors in the script that prevent it from running
successfully. Also, the script relies on the AutoCAD document satisfying
some requirements. If these requirements are not met, the script cannot
continue. For instance, if you try to load a drawing that doesn't contain
any drawn objects, but contains unreferenced blocks that you want purged,
the script will never execute the purge commands because the commands before
try to select all objects, which when none are found, continues to prompt
for a selection. You need to issue a cancel in the script before running the
next command or else the script will not complete.

You say that the scripts aren't running. Does that mean "At all?".
Are their error messages?
Can you write a simpler script that inserts a circle or something at say
point 0,0? Does this work for all documents?

Also, your script relies on a LISP file being loaded. So what happens if
that LISP file is not found?

Try to issue the commands yourself and see if it follows the script exactly.
I have not been able to successfully do this.

If you don't need the flexibility of changing the script file, consider
adding code to the project that does what you want. You may find that you
need to used both managed objects and Interop to get the job done, but you
will be able to cope with errors, i.e. no objects to select, so skip
operations that need selected objects.

Good Luck,
C
Distinguished Contributor
cgay
Posts: 125
Registered: ‎08-02-2005
Message 10 of 15 (280 Views)

Re: several vb.net issues

01-16-2006 01:59 PM in reply to: *Russ Green
Russ,
Just a stupid question on my part, are the Drawings marked as "Read Only" in explorer? I just can't duplicate what you are seeing on my end. After I made the changes to your original code that is. I did see this happen, but that was with your original code, and I chalked it up to running in the document context instead of the application context. Can you try some blank drawings and a script to draw a circle just to be sure?

C

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community