Access to the DisplayConduit from outside of Command inherited Class


#1

Hi guys,

First of all - would like to wish you all the best in 2014!

As stated in the topic itself - I have faced one question as to the access to the DisplayConduit.

Basically, in all examples I have seen, it is shown that new Conduit is called locally from RunCommand function.
(ex. Dim conduit = New DrawBlueMeshConduit(mesh__1))

In my plugin I have separate class for Windows Form, where I would like to control my conduit (ex. switch on/off) when clicking the predefined button or raising some other event.

How and where should I register my conduit that it would be visible throughout the project, which means that would be also accessible from any other custom class, like Windows Form Class in my case?
Same question goes for RhinoDoc as I need to use Redraw function after applying change in conduit behavior.
(ex. doc.Views.Redraw() in RunCommand Funtion)

Thank you in advance,
Dmitriy


(Menno Deij - van Rijswijk) #2

Conduits need no registration with Rhino (like visual analysis modes and panels do for example). Once created they are active if within scope (i.e. not garbage-collected). You need to set Enabled to true to switch a conduit on though - when it is created it is switched off by default.

I guess the easiest way is to make the conduit a public property on your WinForm class. As for the reference to RhinoDoc - this can be dealt with in the same way. Once you have a reference, for example from a command or through RhinoDoc.ActiveDoc, you can store that reference as a public property on your WinForm class.


#3

Hi Menno,

Thank you for the prompt reply.

If I understood you correctly it can look like this:

In the Form Class:

Public Property MyConduit() As DrawLinesConduit
      Get
        Return m_conduit
      End Get
      Set(value As DrawLinesConduit)
        m_conduit = value
      End Set
End Property

Private m_conduit As DrawLinesConduit
Private ReadOnly m_doc As Rhino.RhinoDoc = Rhino.RhinoDoc.ActiveDoc

Sub Button1Click(sender As Object, e As EventArgs)
	
    Dim startpt As New Point3d(1,1,0)
    Dim endpt As New Point3d(10,10,0)
    
    Dim lin = New Line(startPt, endPt)
    m_conduit = New DrawLinesConduit(lin)
    m_conduit.Enabled=True
    m_doc.Views.Redraw()
    
End Sub

It works, however I am not sure if this is completely correct.
May be you can crosscheck it?

Thanks in advance,
Dmitriy


(Menno Deij - van Rijswijk) #4

In principle this looks fine. You need to think, however, about what happens when a user opens a new document (Ctrl+O) or starts a new document (Ctrl+N). Then you have an “old” reference to the RhinoDoc.
So, if all you need the document reference for is to issue a Redraw(), I would not keep the reference to the document but just access the current document like this

Private m_conduit As DrawLinesConduit
Sub Button1Click(sender As Object, e As EventArgs)

    Dim startpt As New Point3d(1,1,0)
    Dim endpt As New Point3d(10,10,0)

    Dim lin = New Line(startPt, endPt)
    m_conduit = New DrawLinesConduit(lin)
    m_conduit.Enabled=True
    Rhino.RhinoDoc.ActiveDoc.Views.Redraw()

End Sub

#5

Hey Menno,

Thanks for clarifications.

Kind regards,
Dmitriy


(Steve Baer) #6

Just a little tweak, but very important. The code sample should probably be changed to

...
If m_conduit IsNot Nothing Then
  m_conduit = New DrawLinesConduit(line)
  m_conduit.Enabled = True
End If
...

(Menno Deij - van Rijswijk) #7

Of course, otherwise each click would spawn a new conduit!


#8

Thanks guys, noted.


#9

Hi guys,

Still a bit confused:

when we have conduit defined as Private

Private m_conduit As DrawLinesConduit

it is equal to Nothing until we assign a new conduit.

But if we define in the following way:

If m_conduit IsNot Nothing Then
  m_conduit = New DrawLinesConduit(line)
  m_conduit.Enabled = True
End If

then we cannot initialize any conduit, or?

Thanks in advance,
Dmitriy


(Menno Deij - van Rijswijk) #10

I suppose IsNot should be Is


#11

Then it makes sense.

And of course when we need to disable it we should use smth like this:

   If m_conduit IsNot Nothing Then
	m_conduit.Enabled=false
    	Rhino.RhinoDoc.ActiveDoc.Views.Redraw()
End If

Hope Steve will agree.

Thanks Menno!

Kind regards,
Dmitriy


(Steve Baer) #12

Yep, my mistake when writing the sample