Can't change line type


#1

Hi All,

I’m trying to change the line type of a NurbsCurve, but I do not succeed.

So I make test:

	ON_3dPoint pt1(0.0,5.0,0.0);
	ON_3dPoint pt2(10.0,15.0,0.0);
	ON_Line line(pt1,pt2);
	ON_3dmObjectAttributes *attributes = new ON_3dmObjectAttributes();
	attributes ->SetLinetypeSource(ON::linetype_from_object);
	attributes ->m_linetype_index = 3;
	CRhinoObject *obj = p_doc->AddCurveObject(line, attributes );

But this failed too. The line is added to document, but the line type still remain continuos even if I change the m_linetype_index.

Does anyone have an idea how to make it works?

Thanks in advance,

Marco


(Dale Fugier) #2

Instead of doing this:

ON_3dmObjectAttributes *attributes = new ON_3dmObjectAttributes();

Do this:

CRhinoObjectAttributes attributes;
context.m_doc.GetDefaultObjectAttributes( attributes );
// ...
context.m_doc.AddCurveObject( line, &attributes );

Also, CRhinoDoc::AddCurveObject make a copy of the attributes. Thus, your code was leaking memory. The latter way won’t.

And, if you need another sample, see the following:

https://github.com/mcneel/Rhino5Samples_CPP/blob/master/SampleCommands/cmdSampleCurveLinetype.cpp


(Rajaa Issa) #3

The linetype table starts empty. You will need to initialize it first:

CRhinoLinetypeTable& linetype_table = context.m_doc.m_linetype_table;
linetype_table.InitDefaultLinetypes();

I also think the Dashed index = 1 in the table. You can use the following to find the right index:
index = linetype_table.FindLinetype(L"Dashed");


#4

Hi Dale and Rajaa,

I followed your suggestions and now it works fine.

Thanks a lot!

PS: rajaa the FindLinetype function returns always -1, maybe I pass the wrong name. I try to pass “Dashed” and Tratteggiata ( it means Dashed in italian) but the result it’s always the same. Maybe I’m wrong something.

Regards,

Marco


#5

Sorry dont know C++ but maybe VB.net helps you more then enough :wink:

Works for vb.net though

Dim LineType As Integer = doc.Linetypes.Find("Dashed", False)

Maybe draw a line in rhino. Check properties > linetype. Is there a “Dashed” there?

Btw. it is Lower/higher sensitive.

Else try looping through all Doc.Linetypes and msgbox their names :wink:

For Each Line In doc.Linetypes
MsgBox(Line.Name)
Next

And see what for result you get.