Jump to content

Recommended Posts

Posted

Hello: I have an application written in 2005 .net with autocad api

and after the user enters a command, the code instructs to

open a template off the server. Here's the code to open it:

 

[size=2]dbTemplate.ReadDwgFile(sBOM_EstimatePath & [/size][size=2][color=#a31515][size=2][color=#a31515]"CO_TEMPLATE_1Estimate.dwt"[/color][/size][/color][/size][size=2], System.IO.FileShare.Read, [/size][size=2][color=#0000ff][size=2][color=#0000ff]True[/color][/size][/color][/size][size=2], [/size][size=2][color=#0000ff][size=2][color=#0000ff]Nothing[/color][/size][/color][/size][size=2])
[/size]

 

where as the path (sBOM_EstimatePath) is located off the server.

At any rate, this code has always worked with no problems...until recently.

 

Recently, there is on user who is not receiving recent changes made to this template (CO_TEMPLATE_1Estimate.dwt).

I ran a series of tests - one of them was changing the path to the user's local drive. When I did this, and placed the template in this path, the user got the template with all it's recent changes.

Why won't it pull the most recent template from the server? When I debug, I see it's getting the correct path. If it's not pulling the template from there, where is it getting this template from?

Perhaps there's some cashing issue...that I must clear?

any thought will help...

Thanks,

Proctor

Posted

Try

Imports System.IO

---------------------

 

Dim fullPath as string=Path.Combine(sBOM_EstimatePath, "CO_TEMPLATE_1Estimate.dwt")

and also in the tools ->options->files tab

search for File template location

or you can receive its main directory by system variable

"ROAMABLEROOTPREFIX"

 

Not sure about A2005 though

Posted

Hi fixo: thank you for your suggestions. I have implemented code you suggested and am waiting to test it out on the user's machine ....

I'll reply back here once i'm able to test it out.

 

thank you again,

Proctor

Posted

fixo: I was able to test out the code but it didn't work :(

 

here's what I used:

Imports System.IO

[size=2][/size][size=2][color=#0000ff][size=2][color=#0000ff]Dim[/color][/size][/color][/size][size=2] fullpath [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2] [/size][size=2][color=#0000ff][size=2][color=#0000ff]String[/color][/size][/color][/size][size=2] = path.comine(sBOM_EstimatePath & [/size][size=2][color=#a31515][size=2][color=#a31515]"CO_TEMPLATE_1Estimate.dwt"[/color][/size][/color][/size][size=2])
dbTemplate.ReadDwgFile(fullpath, System.IO.FileShare.Read, [/size][size=2][color=#0000ff][size=2][color=#0000ff]True[/color][/size][/color][/size][size=2], [/size][size=2][color=#0000ff][size=2][color=#0000ff]Nothing[/color][/size][/color][/size][size=2])
[/size]

 

I looked at the path under tools->options->files for the file template location...it's a local location. Do you think i should remove all files at this location and then try it again?

 

thanks again,

Proctor

Posted (edited)

No, no, it's just for info

Keep your template in its own folder

 

Try this code,command flags Session is Important

      <CommandMethod("openDwt", CommandFlags.Session)> _
       Public Sub OpenDwt()
           Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
           Dim newpath As String = ""
           Using docloc As DocumentLock = doc.LockDocument
               Using dbTemplate As New Database(True, False)
                   Dim sBOM_EstimatePath As String = "C:\Test\" '<-- change template folder here
                   Dim fullpath As String = Path.Combine(sBOM_EstimatePath, "CO_TEMPLATE_1Estimate.dwt")
                   dbTemplate.ReadDwgFile(fullpath, System.IO.FileShare.None, False, Nothing)
                   newpath = Path.Combine(sBOM_EstimatePath, "WorkingDrawing.dwg")
                   dbTemplate.SaveAs(newpath, DwgVersion.Current)
                   dbTemplate.Dispose()
               End Using
           End Using
           'check if we're saved this template as dwg file:
           If File.Exists(newpath) Then
               MsgBox(String.Format("Drawing ""{0}"" created from template", newpath), MsgBoxStyle.Information)
           Else
               MsgBox("Problem with creating drawing", MsgBoxStyle.Exclamation)
           End If
       End Sub

Edited by fixo
code added
Posted

Hi Fixo...thank you again for the code and also your help.

 

I tried your code:

 

[size=2]<CommandMethod([/size][size=2][color=#a31515][size=2][color=#a31515]"openDwt"[/color][/size][/color][/size][size=2], CommandFlags.Session)> _[/size]
[size=2][color=#0000ff][size=2][color=#0000ff]Public[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Sub[/color][/size][/color][/size][size=2] OpenDwt()[/size]
[size=2][color=#0000ff][size=2][color=#0000ff]Dim[/color][/size][/color][/size][size=2] doc [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2] Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument[/size]
[size=2][color=#0000ff][size=2][color=#0000ff]Dim[/color][/size][/color][/size][size=2] newpath [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]String[/color][/size][/color][/size][size=2] = [/size][size=2][color=#a31515][size=2][color=#a31515]""[/color][/size]
[/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Using[/color][/size][/color][/size][size=2] docloc [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2] DocumentLock = doc.LockDocument[/size]
[size=2][color=#0000ff][size=2][color=#0000ff]Using[/color][/size][/color][/size][size=2] dbTemplate [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]New[/color][/size][/color][/size][size=2] Database([/size][size=2][color=#0000ff][size=2][color=#0000ff]True[/color][/size][/color][/size][size=2], [/size][size=2][color=#0000ff][size=2][color=#0000ff]False[/color][/size][/color][/size][size=2])[/size]
[size=2][color=#0000ff][size=2][color=#0000ff]Dim[/color][/size][/color][/size][size=2] sBOM_EstimatePath [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]String[/color][/size][/color][/size][size=2] = [/size][size=2][color=#a31515][size=2][color=#a31515]"http://ourCompanyWebsite.com/SloanLEDEstimator/"[/color][/size][/color][/size][size=2][color=#008000][size=2][color=#008000]'<-- change template folder here[/color][/size]
[/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Dim[/color][/size][/color][/size][size=2] fullpath [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]String[/color][/size][/color][/size][size=2] = Path.Combine(sBOM_EstimatePath, [/size][size=2][color=#a31515][size=2][color=#a31515]"CO_TEMPLATE_1Estimate.dwt"[/color][/size][/color][/size][size=2])[/size]
[size=2]dbTemplate.ReadDwgFile(fullpath, System.IO.FileShare.None, [/size][size=2][color=#0000ff][size=2][color=#0000ff]False[/color][/size][/color][/size][size=2], [/size][size=2][color=#0000ff][size=2][color=#0000ff]Nothing[/color][/size][/color][/size][size=2])[/size]
[size=2]newpath = Path.Combine(sBOM_EstimatePath, [/size][size=2][color=#a31515][size=2][color=#a31515]"WorkingDrawing.dwg"[/color][/size][/color][/size][size=2])[/size]

[size=2]'errors out on this line: [/size]
[size=2][color=purple]dbTemplate.SaveAs(newpath, DwgVersion.Current)[/color][/size]

[size=2]dbTemplate.Dispose()[/size]
[size=2][color=#0000ff][size=2][color=#0000ff]End[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Using[/color][/size]
[/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]End[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Using[/color][/size]
[/color][/size][size=2][color=#008000][size=2][color=#008000]'check if we're saved this template as dwg file:[/color][/size]
[/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]If[/color][/size][/color][/size][size=2] File.Exists(newpath) [/size][size=2][color=#0000ff][size=2][color=#0000ff]Then[/color][/size]
[/color][/size][size=2]MsgBox([/size][size=2][color=#0000ff][size=2][color=#0000ff]String[/color][/size][/color][/size][size=2].Format([/size][size=2][color=#a31515][size=2][color=#a31515]"Drawing ""{0}"" created from template"[/color][/size][/color][/size][size=2], newpath), MsgBoxStyle.Information)[/size]
[size=2][color=#0000ff][size=2][color=#0000ff]Else[/color][/size]
[/color][/size][size=2]MsgBox([/size][size=2][color=#a31515][size=2][color=#a31515]"Problem with creating drawing"[/color][/size][/color][/size][size=2], MsgBoxStyle.Exclamation)[/size]
[size=2][color=#0000ff][size=2][color=#0000ff]End[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]If[/color][/size]
[/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]End[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Sub[/color][/size]
[/color][/size]

 

however, it errors out on the purple line noted above. perhaps it has something to do with the fact that I'm pulling the template from a web server?

 

here's the error msg i'm getting when it hits this line:

 

Autodesk.AutoCAD.Runtime.Exception was unhandled by user code

Message="eInetHttpBadMethod"

Source="acdbmgd"

StackTrace:

at Autodesk.AutoCAD.DatabaseServices.Database.SaveAs(String fileName, DwgVersion version)

at SloanLEDEstimator.Product.OpenDwt() in C:\Inetpub\wwwroot\SloanLEDEstimator\SloanLEDEstimator\Product.vb:line 1341

at Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorker(MethodInfo mi, Object commandObject, Boolean bLispFunction)

at Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorkerWithExceptionFilter(MethodInfo mi, Object commandObject, Boolean bLispFunction)

at Autodesk.AutoCAD.Runtime.PerDocumentCommandClass.Invoke(MethodInfo mi, Boolean bLispFunction)

at Autodesk.AutoCAD.Runtime.CommandClass.CommandThunk.Invoke()

 

What do you think is the problem?

 

Thanks,

Proctor

Posted

Sorry I have never worked with net stored drawings

:(

Posted

Thank you for your help anyway....I appreciate your time.....I'll post on autodesk and see if I can find the solution.

 

Proctor

Posted

Would be this help:

 
dim fullpath=HostApplicationServices.Current.GetUrl(sBOM_EstimatePath).AbsolutePath

Not tested..

Posted

let me give it a try......i'll let you know if it helps.

 

thank you!

 

Proctor

Posted

Hi Fixo: Unfortunately...it errors out on that line. I get an unhancled access reading violation.

 

I'm going to try a few things on the user's machine today. I'm going to do a search on her machine for the template to see where else it could be pulling it up from since i know it's not getting the most current template off the web server.

 

Also, from the browser, i'm going to see if i can open the drawing template from the user's machine.

 

maybe that will help me to trouble shoot a bit more. i'll let you know what i find.

 

thanks again...

 

Proctor

Posted

What's the most baffeling to me about this situation is that ...when the code runs on this user's machine, it doesn’t complain at all; and it does pull up a template that very similar; however, it’s an old template…and not the current one that’s in the web server at this location….where is it getting this template from? Do you know how can I find out? Maybe if I could find it and get rid of it it would resolve the issue?

I ran the url in the browser from the users machine and it pulls up the template so I don't think it's any permissions issue.

Thank you again,

Proctor

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...