AnsweredAssumed Answered

How get the Sketch Using SelectById2?

Question asked by Joshua Jiang on Jun 28, 2015
Latest reply on Jul 1, 2015 by Joshua Jiang

I want to write a small programme that can automatically draws the part. The problem now is that I don't know how to use Holewizard to add several holes at one time.

I try to preselect a point on the face, then use holewizard to create a hole, then edit the sketch and add the rest of the hole.(I wonder if there is a better way to do this.)

Suppose I have a part file below.The arrow is the only point in the Sketch3.

pic.bmp

The following is my code (I use Vs2008 C++  to develop sw2012):

CoInitialize(NULL); // initialize COM
CComPtr<ISldWorks> swApp;
HRESULT hres = swApp.CoCreateInstance(__uuidof(SldWorks), NULL, CLSCTX_LOCAL_SERVER);//CLSCTX_LOCAL_SERVER
swApp->put_Visible(VARIANT_TRUE);
swApp->put_UserControl(VARIANT_TRUE);
{
CComPtr<IModelDoc2> swDoc=NULL;
CComPtr<IModelDocExtension> swDocExt=NULL;
CComPtr<IFeatureManager> swFeatMgr=NULL;
CComPtr<ISketchManager> swSketchMgr=NULL;
VARIANT_BOOL bRetbool;
swApp->get_IActiveDoc2(&swDoc);
swDoc->get_Extension(&swDocExt);
swDoc->get_FeatureManager(&swFeatMgr);
swDoc->get_SketchManager(&swSketchMgr);
hres = swDocExt->SelectByID2(L"Sketch3",L"SKETCH",0.0,0.0,0.0,VARIANT_FALSE,0,NULL,swSelectOptionDefault,&bRetbool);

// This doesn't work. Cause it's invisible? Or I made other mistakes? Even if I specify the type argument as "SKETCH".,finally

the Origin Point is selected. 

swDoc->EditSketch();

//hres = swDocExt->SelectByID2(L"Point1@Sketch3",L"EXTSKETCHPOINT",1.13,1.25,0.0,VARIANT_FALSE,0,NULL,swSelectOptionDefault,&bRetbool);
//This sentence may work if I manually show the hiding Sketch3. But I don't think it's a good way.

 

 

Thanks for any suggestion in advance!

Outcomes