Hi
I am trying to shade an object imported form step. I have problem with that. I tried this also in C# data flow example.
I have added only three lines to InitModelInfo():
private void InitModelInfo():
{
m_iModel - afxKernCAdnet1.GetModel();
ISection isect = m_iModel.GetSection(0);
IMesh imesh = (IMesh) isect;
IMeshShading shading = (IMeshShading)imesh;
}
After I open linkrods.step from the installed models folder I get an exception on the IMesh imesh = (IMesh) isect; line:
An Unhandled exception of type 'System.InvalidCastException' occured in DataFlow.exe
Additional information: unable to cast COM object of type 'System__ComObject' to interface type 'KernCADnet.IMesh'. This operation failed because the QueryInterface call on the COM component for the interface with ID {14DCB303-935A-4162-ADB7-BA5FoA5E6517}' failed due to th efololwing errror: No such interface supported {exception {E_NOINTERFACE} }
Any ideas?
Thanks in advance
Michael
Shading problem
Re: Shading problem
Hi Michael
The problem is that objects imported from STEP are pure parametric object. They do not actually have a mesh and cannot be shaded directly. To do what you need you need to convert it to KernelCAD’s MeshSection first. In C# it would look like:
ISection iSectImported = …
IObject_KC iObj = (IObject_KC) iSectImported;
IObject_KC iObjConverted = iObj .Convert((int) EObjectType. eObjTypeMeshSection);
ISection iSectMesh = (ISection) iObjConverted;
IMeshShading_KC shader = (IMeshShading_KC) iSectMesh;
You can keep the old object too and switch their visibility and regenerate the mesh if geometry of the initial object was modified
Regards
Gerard
The problem is that objects imported from STEP are pure parametric object. They do not actually have a mesh and cannot be shaded directly. To do what you need you need to convert it to KernelCAD’s MeshSection first. In C# it would look like:
ISection iSectImported = …
IObject_KC iObj = (IObject_KC) iSectImported;
IObject_KC iObjConverted = iObj .Convert((int) EObjectType. eObjTypeMeshSection);
ISection iSectMesh = (ISection) iObjConverted;
IMeshShading_KC shader = (IMeshShading_KC) iSectMesh;
You can keep the old object too and switch their visibility and regenerate the mesh if geometry of the initial object was modified
Regards
Gerard