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

IExtensionApplication.Initialize issue

5 REPLIES 5
Reply
Message 1 of 6
dancalgary
2286 Views, 5 Replies

IExtensionApplication.Initialize issue

I have the following code running everytime I am making a windows active

It is loading a form (formaCSF) that display the global coordinate system( autocad map ) and other variables
It is working fine.
I want to add to it an sub that will run everytime a document is closed or autocad is closed or is loosing the focus(by opening another drawing or switching with control+tab)
I don't know how to do it.
Can somebody point me in the right direction?
Thanks a lot


Public Class AutoLoad


Implements Autodesk.AutoCAD.Runtime.IExtensionApplication

Public Sub Initialize() Implements IExtensionApplication.Initialize

AddHandler Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.DocumentBecameCurrent, AddressOf Global1

End Sub

Public Sub Terminate() Implements IExtensionApplication.Terminate
End Sub

Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub

Public Sub Global1()

Try
MsgBox(Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Name)
Dim i As Integer = 0

Dim frm As Forma_CSF

Dim CSF As Double

Dim Inaltimea1 As Integer

Dim Proiectia1 As String

For Each frm In System.Windows.Forms.Application.OpenForms

i = i + 1

Next

Dim Current1 As Autodesk.Gis.Map.MapApplication
Current1 = Autodesk.Gis.Map.HostMapApplicationServices.Application

Dim Proiect1 As Autodesk.Gis.Map.Project.ProjectModel
Proiect1 = Current1.ActiveProject

Proiectia1 = Proiect1.Projection.ToString

If Proiectia1 = "" Then
Proiectia1 = "NO CoordSys"

End If

CSF = Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("USERR1")
If CSF = 0 Then CSF = 1

Inaltimea1 = Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("USERI1")
Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("FILEDIA", 1)
Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("PLINETYPE", 2)
Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("GEOMARKERVISIBILITY", 0)
Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("EDGEMODE", 1)

Select Case i

Case 0

Dim Forma1 As New Forma_CSF

Forma1.Label1.Text = Proiectia1
Forma1.Label2.Text = "C.S.F. = " & CSF.ToString
Forma1.Label3.Text = "Scale = 1:" & Inaltimea1.ToString
Autodesk.AutoCAD.ApplicationServices.Application.ShowModelessDialog(Forma1)

Case 1

For Each frm In System.Windows.Forms.Application.OpenForms
frm.Label1.Text = Proiectia1
frm.Label2.Text = "C.S.F. = " & CSF.ToString
frm.Label3.Text = "Scale = 1:" & Inaltimea1.ToString
Exit For

Next
Case Else
Exit Sub

End Select


Catch Ex As Exception
MsgBox(Ex.Message)



End Try

End Sub

End Class
5 REPLIES 5
Message 2 of 6
Anonymous
in reply to: dancalgary

Throw that code away and start over.

Show only one form, and each time the user switches documents, update that
form to show the data related to the newly activated document.

The code you posted will not and cannot work, and no one here is going to be
willing to untangle that mess to the extent needed to tell what's wrong with
it.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6285729@discussion.autodesk.com...
I have the following code running everytime I am making a windows active

It is loading a form (formaCSF) that display the global coordinate system(
autocad map ) and other variables
It is working fine.
I want to add to it an sub that will run everytime a document is closed or
autocad is closed or is loosing the focus(by opening another drawing or
switching with control+tab)
I don't know how to do it.
Can somebody point me in the right direction?
Thanks a lot


Public Class AutoLoad


Implements Autodesk.AutoCAD.Runtime.IExtensionApplication

Public Sub Initialize() Implements IExtensionApplication.Initialize

AddHandler
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.DocumentBecameCurrent,
AddressOf Global1

End Sub

Public Sub Terminate() Implements IExtensionApplication.Terminate
End Sub

Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub

Public Sub Global1()

Try
MsgBox(Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Name)
Dim i As Integer = 0

Dim frm As Forma_CSF

Dim CSF As Double

Dim Inaltimea1 As Integer

Dim Proiectia1 As String

For Each frm In System.Windows.Forms.Application.OpenForms

i = i + 1

Next

Dim Current1 As Autodesk.Gis.Map.MapApplication
Current1 =
Autodesk.Gis.Map.HostMapApplicationServices.Application

Dim Proiect1 As Autodesk.Gis.Map.Project.ProjectModel
Proiect1 = Current1.ActiveProject

Proiectia1 = Proiect1.Projection.ToString

If Proiectia1 = "" Then
Proiectia1 = "NO CoordSys"

End If

CSF =
Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("USERR1")
If CSF = 0 Then CSF = 1

Inaltimea1 =
Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("USERI1")
Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("FILEDIA",
1)
Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("PLINETYPE",
2)
Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("GEOMARKERVISIBILITY",
0)
Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("EDGEMODE",
1)

Select Case i

Case 0

Dim Forma1 As New Forma_CSF

Forma1.Label1.Text = Proiectia1
Forma1.Label2.Text = "C.S.F. = " & CSF.ToString
Forma1.Label3.Text = "Scale = 1:" & Inaltimea1.ToString
Autodesk.AutoCAD.ApplicationServices.Application.ShowModelessDialog(Forma1)

Case 1

For Each frm In
System.Windows.Forms.Application.OpenForms
frm.Label1.Text = Proiectia1
frm.Label2.Text = "C.S.F. = " & CSF.ToString
frm.Label3.Text = "Scale = 1:" & Inaltimea1.ToString
Exit For

Next
Case Else
Exit Sub

End Select


Catch Ex As Exception
MsgBox(Ex.Message)



End Try

End Sub

End Class
Message 3 of 6
dancalgary
in reply to: dancalgary

Tony looks very easy but I don't know where to load the form.
What event is fired when autocad is started and not fired again when you activate a drawing?
and if you close all drawings but you leave autocad open where to put form.close?


Thanks
Message 4 of 6
Anonymous
in reply to: dancalgary

{quote}

What event is fired when autocad is started and not fired again when you
activate a drawing

{quote}

IExtensionApplication.Initialize is called when your extension loads, and is
never called again. It's not an event, but serves the same purpose. AutoCAD
is telling your extension that it has been loaded, so it can do what it
needs to do.

{quote}

and if you close all drawings but you leave autocad open where to put
form.close

{quote}

The DocumentManager's DocumentCreated and DocumentToBeDestroyed events fire
when a new document is added to/removed from the collection of open
documents, respectively.

When DocumentCreated is fired and the number of open documents == 1 that
means AutoCAD is exiting 'zero-document state'.

When DocumentToBeDestroyed fires and the number of open documents == 1, it
means AutoCAD is about to enter 'zero-document state'.

'Zero-document state' is when there are no open documents.

You just handle those events and look at the DocumentManager's Count
property to figure out what's going on, and act accordingly.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6285801@discussion.autodesk.com...
Tony looks very easy but I don't know where to load the form.
What event is fired when autocad is started and not fired again when you
activate a drawing?
and if you close all drawings but you leave autocad open where to put
form.close?


Thanks
Message 5 of 6
dancalgary
in reply to: dancalgary

Thanks a lot Tony for your help.
I have another question.
I am working for a land surveying company that is willing to invest in me.
My e-mail is dan.popescu@swg.ca
I have observed that you know a lot about autocad.net objects. I have bought "Vb.net training for autocad 2007 and 2008" by Jerry Winters
I couldn't find any other documentation about these objects.
Do you know if there is more available documentation? From where did you learned about this? There is a possibility for me to buy something or to take a course?

Thanks again
Message 6 of 6
Anonymous
in reply to: dancalgary

Autodesk offers API training.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6287126@discussion.autodesk.com...
Thanks a lot Tony for your help.
I have another question.
I am working for a land surveying company that is willing to invest in me.
My e-mail is dan.popescu@swg.ca
I have observed that you know a lot about autocad.net objects. I have bought
"Vb.net training for autocad 2007 and 2008" by Jerry Winters
I couldn't find any other documentation about these objects.
Do you know if there is more available documentation? From where did you
learned about this? There is a possibility for me to buy something or to
take a course?

Thanks again

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