.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Xref and UCS

47 REPLIES 47
Reply
Message 1 of 48
Anonymous
810 Views, 47 Replies

Xref and UCS

Hi,

I'm new to .NET. I had been trying to create a dll to change the UCS and Layer when the user types XREF in the command line. I don't know how to go about it. I just tried the code below, but it is not working. Can anybody help me?

Imports System
Imports System.Runtime.InteropServices
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices

Imports acadApp = Autodesk.AutoCAD.ApplicationServices.Application

Public Class UCS
Public Sub XrefCommand()
If acadApp.DocumentManager.MdiActiveDocument.CommandInProgress = "XREF" Then
MsgBox("Done!")
End If
End Sub
End Class

Thanks Message was edited by: cadprog
47 REPLIES 47
Message 41 of 48
Anonymous
in reply to: Anonymous

wrote in message news:5743665@discussion.autodesk.com...

>> I notice that each time you reply, you refuse acknowledge this:

>> "If you created a variable in C# that always held a reference
>> to the active document, you could wire up one event to that
>> variable and be done with it."

Because that's not possible in C#, that's why.

>> Must I explain how to keep that variable up to date with
>> the active document or do you get it yet?"

I just gone done explaining to you why only an rank-amateur
would do it that way.

What's wrong with you?

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com
Message 42 of 48
Anonymous
in reply to: Anonymous

jspark wrote:

>> That example was hand typed, not copied from my project.

That's a bunch of crap.

Go back and read your own self-contradicting words.

You already admitted that you didn't even know how
any instances of your class were being created, and
you weren't creating one yourself.

The only way that an instance of your class could be
created is if AutoCAD did it, because your command
method was not shared.

feel free to reply if you want, but I don't bother with
weasels, and I certainly don't offer them help.

You could always change your username here and start
over again, but given your tendency to not have the
guts to admit your own flaws or faults, I think you'll be
easy to recognize.

Hah! Typical VB 'programmer'....

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com
Message 43 of 48
cadMeUp
in reply to: Anonymous

In this case you only need to handle at least the 'DocumentCreated' event. It needs to be wired up in the app's IExtensionApplication Initialize() method. You iterate through all of the open doc's and add the 'CommandWillStart' handler to each open doc. In the 'DocumentCreated' handler you wire up the 'CommandWillStart' event to the passed in 'Document' object. When the 'CommandWillStart' handler executes you just grab the MdiActiveDocument. Why would you need a variable to always keep track of the current document?

I don't see any need to watch for the 'DocumentBecameCurrent' event since the 'DocumentCreated' handler already adds a 'CommandWillStart' event, to each document that gets opened, to watch for.

Why use a variable to keep track of the current document when you only really need it in the 'CommandWillStart' handler? when you call the property 'AcadApp.DocumentManager.MdiActiveDocument' you are getting the current document so just call that and not some variable. The application already provides that.

Could you post some code that shows how you would do go about doing that?
Message 44 of 48
jspark
in reply to: Anonymous

Umm, no, you did not explain why only an amateur would do it that way. There is no "garbage code generated"... I'm talking about doing it in C# with the same approach. Keep an updated reference to the active document, and wire a handler to that reference. Even if you have to rewire the event when the reference changes (I doubt you do), it's way better then your approach. What is wrong with YOU? lol. You still don't get it, or you're just playing stupid.

Change my name? lol. If this is the kind of help you offer, and the manner that you offer it, no thanks! lol. Everyone in this NG is right about you bud. I'm done with ya.
Message 45 of 48
cadMeUp
in reply to: Anonymous

With this method whenever you make another document acitve you are having to add and remove events continuously. If you are only dealing with a couple of documents that don't switch activation very often then it may not be that bad.

With 'DocumentCreated' you are only having to add a handler once not every time the document becomes active.

You are executing code needlessly when using 'DocumentBecameCurrent'. You are also having to handle 'DocumentToBeDeactivated' and remove the handler in the de-activating doc. It doesn't make any sense in this case.
Message 46 of 48
NathTay
in reply to: Anonymous

You can simply add the handler as new documents are created. Which means you do not have to keep track of the active document. So it is no more difficult. It is certainly not overkill and as Tony has explained well it does not create overhead.

Regards - Nathan
Message 47 of 48
Anonymous
in reply to: Anonymous

Hi Larry,

Thanks a bunch for the reply and the code snippet. Sorry for the delay in reply. I decided to switch to C#. Hence it took me some time to get used to it.
I would like to know how to get back to the original settings of the drawing after xref command ends.

Thanks
Message 48 of 48
cadMeUp
in reply to: Anonymous

When your command starts:

>> Editor editor = AcadApp.DocumentManager.MdiActiveDocument.Editor;
>> Database db = AcadApp.DocumentManager.MdiActiveDocument.Database;
>> TransMan transMgr = db.TransactionManager;

// Get and store the current layer string
string savedCurLayer = (string)AcadApp.GetSystemVariable("CLAYER");

// Get and store the current ucs
Matrix3d savedUCS = editor.CurrentUserCoordinateSystem;


Then at the end of your command:

// Make the original layer active again:
AcadApp.SetSystemVariable("CLAYER", savedCurLayer);

// Restore the UCS:
editor.CurrentUserCoordinateSystem = Matrix3d.Identity;
editor.CurrentUserCoordinateSystem = savedUCS;

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost