Message 1 of 7
AddForSolid() In C++

Not applicable
03-18-2013
07:58 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi there,
I am trying to creating an extrusion with a sketch containing multiple circles. However, the AddForSolid() Method is not working properly, returning non-NOERROR is C++.
Below is the code that I used to create a sketch(which is succeeded) and then try to create a extrusion (in my case cutting).
ApplicationPtr pInvApp; pInvApp.GetActiveObject("Inventor.Application"); DocumentPtr pItem; pItem = pInvApp->GetActiveDocument(); PartDocumentPtr pDoc; if(pItem->GetDocumentType() == kPartDocumentObject) pDoc = pItem; SelectSetPtr selectedItem; selectedItem = pDoc->GetSelectSet(); FacePtr face; //printf("\n*************Face Selection***************\n"); face = selectedItem->GetItem(1); if(face->GetType() == kFaceObject) printf("You have selected a face\n"); WorkPlanePtr pWorkPlane; tagVARIANT offset; offset.vt = sizeof(long); offset.lVal = 0; if(pDoc->ComponentDefinition->WorkPlanes->AddByPlaneAndOffset(face, offset, 0, &pWorkPlane) == NOERROR) printf("Succeeded to set the workplane!\n"); //Create a sketch based on the work plane just selected and set the transient geometry PlanarSketchPtr pSketch; if(pDoc->ComponentDefinition->Sketches->Add(pWorkPlane, false, &pSketch) == NOERROR) printf("Suceeded to set the sketch!\n"); TransientGeometryPtr pTG; pTG = pInvApp->GetTransientGeometry(); PartComponentDefinitionPtr pCompDef; pCompDef = pDoc->GetComponentDefinition(); Point2dPtr point; int i, j; int m = 2; int n = 2; for(i = 0; i < m; i++) { for(j = 0; j < n; j++) { pInvApp->TransientGeometry->CreatePoint2d(i*0.3, j*0.3, &point); //Sketch a circle using the point defined and the radius SketchCirclePtr pCircle; pSketch->SketchCircles->AddByCenterRadius(point, 0.1, &pCircle); //printf("%ld\n",pSketch->SketchEntities->GetCount()); } } //Create new profile ProfilePtr pProfile; tagVARIANT profilePathSegments; tagVARIANT reserved; //Fail to create profile if(pSketch->Profiles->AddForSolid(false, profilePathSegments, reserved, &pProfile) != NOERROR) { printf("Fail to create profile!(AddForSolid)\n"); return E_FAIL; } //Create a new Extrution definition method ExtrudeDefinitionPtr pExtrudeDef; if(pCompDef->Features->ExtrudeFeatures->CreateExtrudeDefinition(pProfile, kCutOperation, &pExtrudeDef) != NOERROR) { printf("Fail to create extrude definition\n!"); return E_FAIL; } VARIANT distance; distance.vt = sizeof(double); distance.dblVal = 1.0; if(pExtrudeDef->SetDistanceExtent(distance, kSymmetricExtentDirection) != NOERROR) printf("Set Extrude Extent Fail\n"); else printf("Extrution Feature Set!\n"); //Do the extrusion ExtrudeFeaturePtr pExtrude; pCompDef->Features->ExtrudeFeatures->Add(pExtrudeDef, &pExtrude); return 0; }