.NET

Reply
Active Contributor
MGOMKD
Posts: 32
Registered: ‎06-23-2011
Message 1 of 5 (147 Views)

Instance Forms in several drawings

147 Views, 4 Replies
04-24-2012 01:49 AM

Hi All,

 

I'had just met another matter for my Add-on. I noticed that when I instance a new drawing, while a first one is opened, when I load a new Form, this one keep all first drawing's properties. What could happen? 

 

For example, I would like to add the layer list on a ComboBox.

 

My source:

 

Private Sub LayerBox_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        '***************************'
        '* Initialisation LayerBox *'
        '***************************'       
              
        Using acTrans = acCurDb.TransactionManager.StartTransaction()
            acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId, OpenMode.ForRead)
            For Each acObjId As ObjectId In acLyrTbl
                acLyrTblRec = acTrans.GetObject(acObjId, OpenMode.ForRead)
                ComboBox1.Items.Add(acLyrTblRec.Name)
            Next acObjId
        End Using        

    End Sub

 This source works, but if i instance a new form on a new drawing, the first drawing's layer list is kept and the new layer list on the second drawing is ignored!

 

Any ideas?

*Expert Elite*
Alfred.NESWADBA
Posts: 8,865
Registered: ‎06-29-2007
Message 2 of 5 (141 Views)

Re: Instance Forms in several drawings

04-24-2012 02:54 AM in reply to: MGOMKD

Hi,

 

>> but if i instance a new form on a new drawing

then you have to set your variable acCurDb to this other drawing before getting the list of layers.

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Active Contributor
MGOMKD
Posts: 32
Registered: ‎06-23-2011
Message 3 of 5 (137 Views)

Re: Instance Forms in several drawings

04-24-2012 03:34 AM in reply to: Alfred.NESWADBA

Hi alfred,

 

How can i set my variable acCurDb to each drawing

 

I set my variables like that (as it's explained on autoCAD Developper's Guide)

 

 Public acDoc As Document = Application.DocumentManager.MdiActiveDocument
 Public acCurDb As Database = acDoc.Database

 

Thank You

 

 

*Expert Elite*
Alfred.NESWADBA
Posts: 8,865
Registered: ‎06-29-2007
Message 4 of 5 (135 Views)

Re: Instance Forms in several drawings

04-24-2012 03:37 AM in reply to: MGOMKD

Hi,

 

you have the DocumentCollection within the ApplicationServices.Application, that is a list of all opened Documents, run through this list and you have all Documents.

 

Next step is then to watch events for Opening/Activating/Closing Documents as you have then to update your list.

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Active Contributor
MGOMKD
Posts: 32
Registered: ‎06-23-2011
Message 5 of 5 (123 Views)

Re: Instance Forms in several drawings

04-24-2012 06:17 AM in reply to: Alfred.NESWADBA

Hi alfred,

 

I've found the source and it works! Thanks you.

 

In starter Sub just add an Event Argument to detect document activation.

 

Private Sub LayerBox_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        AddHandler Application.DocumentManager.DocumentActivated, AddressOf docColDocAct

End Sub

 Then, when a document is activated the Event Argument refers to docColDocAct which reset acCurDb variable with the current document activated and return it to private Sub LayerBox_Load.

Public Sub docColDocAct(ByVal senderObj As Object, ByVal docColDocActEvtArgs As DocumentCollectionEventArgs)

        acCurDb = docColDocActEvtArgs.Document.Database

End Sub

 

Thank you alfred

 

 

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