Rhino 6 C++ Conduit


#1

Hi,

while transitioning to Rhino 6, there are two more obstacles to overcome, one is working with Dialogs now that we are MFC independent and the other is Conduit…we will leave the first one for later, and I have a question for Conduit. If I do everything as I did before:

1.Create my Conduit class derived from CRhinoDisplayConduit (I have to do this manually btw…VS Class Wizzard “cannot find base class CRhinoDisplayConduit”)…and then I change the constructor to

CConduitPreview::CConduitPreview()
	:CRhinoDisplayConduit(CSupportChannels::SC_PREDRAWOBJECTS|CSupportChannels::SC_CALCBOUNDINGBOX)
{
}
  1. Override the ExecConduit function…
bool CConduitPreview::ExecConduit(CRhinoDisplayPipeline& dp, UINT nChannel, bool& bTerminate)
{

	switch (nChannel)
	{		
	   case CSupportChannels::SC_CALCBOUNDINGBOX:
	   {
		m_pChannelAttrs->m_BoundingBox.Union(pts.BoundingBox());
		break; 
	   }

	case CSupportChannels::SC_PREDRAWOBJECTS:
	{
		for(int i=0; i<pts.Count();i++)
			dp.DrawPoint(pts[i], 5, RPS_CONTROL_POINT, RGB(0, 255, 0));				

	} 

	}

	 //ALWAYS RETURN TRUE*************************
	return true;
}
  1. And I used the doc serial number when I called it
CConduitPreview preview;

if (!preview.IsEnabled(mydoc->RuntimeSerialNumber()))
		preview.Enable(mydoc->RuntimeSerialNumber());

I see those couple of points in the pts array blink for a moment and immediately disappear…What is the catch? Also couple of times when I tested the code, and I zoomed in and out Rhino actually crashed…but lets assume that was an accident or that the problem was somewhere else for now…what should I do so that the points stay in the loop like they did before?

Thanks


(Dale Fugier) #2

Hi @dimcic,

What you describe sounds correct. But without the actual source, I can only speculate what is going on.

See if the attached sample is of any help.

cmdTestDimcic.cpp (2.3 KB)

– Dale


#3

Hm…I made a new project…and put only the code that you provided (so no need to send you the copy of it)…and it worked… BUT :slightly_smiling_face:

I realized I could see the points only because of the CRhiGetString command prompt…I deleted conduit.Disable() and conduit.m_doc.Regen(). but still, the moment I pressed ENTER the points disappeared… You can try it yourself…In your example, if you just deleted everything bellow CRhinoGetString the points will appear only for a moment and immediately disappear…

This was not the case before…nor is it logical in my opinion…the moment I Enable the conduit it should show everything inside it, in the ExecConduit loop, until I disable it…right? GetString should not enter the equation in any way…

Greetings ,
Milos


(Dale Fugier) #4

Hi @dimcic,

The only thing I can think of is that your conduit object is going out of scope. If you want to persist, make sure to stick on something that won’t go away.

– Dale


#5

Thanks Dale,

as often is the case, the simplest solution was the right one. The moment I set the conduit to be a global variable it all went fine…initializing it inside the command was a mistake…I guess the moment the RunCommand was done, the conduit went out of scope…thanks again.


(Dale Fugier) #6

I really despise globals. Perhaps you should do something like the attached?

cmdTestDimcic.cpp (3.3 KB)

– Dale