Jump to content

Open & Close a drawing in VB.net


muck

Recommended Posts

I was thinking some like this.

 

Public Sub CloseDWG1()
    Dim doc As Autodesk.AutoCAD.ApplicationServices.DocumentExten sion '
    doc.CloseAndDiscard()
End Sub 

 

What happens when you call CloseDWG1() method? :unsure:

 

 

 

Here's a hint... CloseAndDiscard() is an Extension Method to the Document Class.

Link to comment
Share on other sites

  • Replies 41
  • Created
  • Last Reply

Top Posters In This Topic

  • muck

    22

  • BlackBox

    15

  • BIGAL

    2

  • SLW210

    1

Top Posters In This Topic

Posted Images

Blackbox, I looked your video link last night and notice that it is in C sharp.

To answer your questions

 

I don't know about extension methods are so I can't answer your question.

I searched "Close and Discard" in the object browser and got the attached result.

You said the the object browser is my friend. Ok how do I interpert my friend.

So how do I interpret and produce the code I want from the result I have in he attached

file?

 

Thank you,

SaveDiscardObjBr.jpg

Link to comment
Share on other sites

The code I now have is

Public Sub CloseDWG()
           Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
           Dim acDocs As DocumentCollection = Application.DocumentManager
           'Dim acdoce As DocumentExtension
           'Dim acdoc As Application.DocumentManager.MdiActiveDocument
           'acDocs.MdiActiveDocument
           DocumentExtension.CloseAndDiscard(acDocs.MdiActiveDocument)
       End Sub

Seems to work

Link to comment
Share on other sites

The code I now have is

Public Sub CloseDWG()
           Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
           Dim acDocs As DocumentCollection = Application.DocumentManager
           'Dim acdoce As DocumentExtension
           'Dim acdoc As Application.DocumentManager.MdiActiveDocument
           'acDocs.MdiActiveDocument
           DocumentExtension.CloseAndDiscard(acDocs.MdiActiveDocument)
       End Sub

Seems to work

 

That may work fine for you... But again, CloseAndDiscard() is an Extension Method to the Document Class:

 

Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.ApplicationServices.DocumentExtension
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.Runtime

Imports System

<Assembly: CommandClass(GetType(FOO.BAR))> 
Namespace FOO

   Public Class BAR

       <CommandMethod("BAZ")> _
       Public Sub Baz()
           Dim doc As Document = Application.DocumentManager.MdiActiveDocument
           doc.CloseAndDiscard()

       End Sub

   End Class

End Namespace

Link to comment
Share on other sites

I used your C sharp Code and VB intellisence to figure out my code but you said VB object browser is my friend.

Is there any good beginner documents on learning AutoCAD VB.net object browser?

 

This stuff seems somewhat overwhelming. I need a practical VB.net information for the AutoCAD user so I can start learning

and sorting out this stuff.

 

Thank you,

Link to comment
Share on other sites

I took put DocumentExtension.CloseAndDiscard(acDocMgr.MdiActiveDocument) in a drawing open/close

program loop.

 

I get the error:

"Check the Error Code property of the exception to determine HR Result returned by Com object"

 

This error occurs when my program gets to the statement

DocumentExtension.CloseAndDiscard(acDocMgr.MdiActiveDocument)

 

What is that error about and how do I solve this one?

 

Thank you,

Link to comment
Share on other sites

I used your C sharp Code and VB intellisence to figure out my code but you said VB object browser is my friend.

Is there any good beginner documents on learning AutoCAD VB.net object browser?

 

I say that Object Browser (OB) is your friend, because it is the key to your understanding the Object Model (and the Framework generally). It is impossible to memorize everything that the Framework provides, such as each-and-every-single-possible Overload, etc.

 

Put simply, anything that can take a partial string and query the entirety of the Framework, and all assembly references for you, is most definitely your friend.

 

Intellisense is a cornerstone of .NET development, as you can see in what feels like real-time what Properties, Methods, and Events are exposed to a given Type. This is useful in determining exactly what is (or sometimes what is not) available to the Type you're working at that moment.

 

 

 

This stuff seems somewhat overwhelming. I need a practical VB.net information for the AutoCAD user so I can start learning

and sorting out this stuff.

 

Being completely honest, as someone who's still very much a student of .NET development... It _is_ overwhelming... At first.

 

There's a reason why quality .NET development books frequently near +/- 2,000 page size, and a beginner is often reasonably informed that it will take them a year to become adept at .NET development concepts, IDE, and debugging. It's a challenge, that is often rewarding, and is incredibly powerful as compared to other lower level languages, but easy is not an adjective I'd every use to describe .NET development.

 

Regurgitating the advice that was given me a year or two ago... Start teaching yourself how to develop for Windows, Forms, WPF, perhaps even a dabble in VSTO, and browser applications... Then, come back and start digging through AutoCAD's .NET API, which is a beast unto itself.

 

Moving forward, in whichever direction you decide to go, just identify something that interests you (something fun if possible), and start reading everything you can on the topic of how to develop that. Code, and code, and code some more. Break it, and figure out what's wrong, and then learn how to fix it... It's the only way you're going to become proficient... And after you've seen some of the benefits of having done so, you'll be glad you did.

 

HTH :beer:

Link to comment
Share on other sites

I took put DocumentExtension.CloseAndDiscard(acDocMgr.MdiActiveDocument) in a drawing open/close program loop.

 

I get the error:

"Check the Error Code property of the exception to determine HR Result returned by Com object"

 

This error occurs when my program gets to the statement

DocumentExtension.CloseAndDiscard(acDocMgr.MdiActiveDocument)

 

What is that error about and how do I solve this one?

 

.NET Development rule #82376 - Read up on Try, Catch, Finally.

Link to comment
Share on other sites

Where are you calling close and are in application context?

Which can be set with CommandFlags.Session attribute

<CommandMethod("Command", CommandFlags.Session)> 

 

The code needs to be ran in the context of the application instead of the document as default.

 

If ran in the document context the method used to close the document is trying to run inside a document that you just made no longer exist.

Link to comment
Share on other sites

Where are you calling close and are in application context?

Which can be set with CommandFlags.Session attribute

<CommandMethod("Command", CommandFlags.Session)> 

 

The code needs to be ran in the context of the application instead of the document as default.

 

If ran in the document context the method used to close the document is trying to run inside a document that you just made no longer exist.

 

Well explained, as always, Jeff. :beer:

Link to comment
Share on other sites

My code has changed. Now I am try to save the drawing(s) in a loop.

in the attached code I am having problems saving my file with

the statement

acDoc.Database.SaveAs(strFileName, True, DwgVersion.Current, _

acDoc.Database.SecurityParameters)

 

I get file write errors.

Code is include in attachment. For some reason this thread will not allow me to

drag code text on the # icon to place code tags in thread.

OpenSaveCloseLoop.txt

Link to comment
Share on other sites

The code works off of my data drive. It did not work off of my C drive because win 7 does

not give me permission to use my C drive.

Thank you,

Link to comment
Share on other sites

How find out what error message mean during debug run sessions?.

 

For example I added a page setup routine to my loop programs and got the error "EnotFromtheDocument"

What is that mean and how do I look that errors up other that using google?

 

Does Autodesk document these errors?

 

Thank you,

Link to comment
Share on other sites

In quick reply why does the thread not allow me to drag my code onto #icon to post it? Code is in shown in attachment.

 

I've never heard of someone doing that... Just hit the "#" code button, and paste your code between the code tags.

 

Since we're briefly discussing post formatting; why are all of your posts manually broken into certain lengths, instead of normal sentencing?

 

Cheers

Link to comment
Share on other sites

It seems like Net might be a little overwheming for the AutoCAD operator that just wants quick routines

to get something done. Maybe VBA & lisp is a better fit but I want to stay in the programming

main stream with AutoCAD. The fact that AutoDesk plans to drop VBA is another reason to

keep plugging at this. I guess the main thing to do is keep plugging and don't give up.

 

I think the biggest gain I made last week was to convince my company's network administrator

to put the VS Express on my machine at work. Now I have excess to vb.net and AutoCAD at my workstation.

 

Thank you,

Link to comment
Share on other sites

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...