C# Inventor api HoleFeature Problem

C# Inventor api HoleFeature Problem

Anonymous
Not applicable
1,491 Views
4 Replies
Message 1 of 5

C# Inventor api HoleFeature Problem

Anonymous
Not applicable

Hi guys,

Here is my c#code

 

private void button2_Click(object sender, EventArgs e)
{
Inventor.Application application = (Inventor.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application");
PartDocument prt = (PartDocument)application.Documents.Add(DocumentTypeEnum.kPartDocumentObject, application.FileManager.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject), true);
prt.UnitsOfMeasure.LengthUnits = UnitsTypeEnum.kMillimeterLengthUnits;
PartComponentDefinition cdef = prt.ComponentDefinition; PlanarSketch sktch = cdef.Sketches.Add(cdef.WorkPlanes["XY Plane"], true); TransientGeometry transgeo = application.TransientGeometry; SketchLine pipe = sktch.SketchLines.AddByTwoPoints(transgeo.CreatePoint2d(0, 0), transgeo.CreatePoint2d(0, 10)); pipe.Centerline = true; SketchEntitiesEnumerator rectanglelines = sktch.SketchLines.AddAsTwoPointRectangle(transgeo.CreatePoint2d(2, 0), transgeo.CreatePoint2d(5, 3)); Profile profile2 = sktch.Profiles.AddForSolid(); RevolveFeature revolve = cdef.Features.RevolveFeatures.AddFull(profile2, pipe, PartFeatureOperationEnum.kJoinOperation); SurfaceBodies bodies = revolve.SurfaceBodies; WorkPlane wp = cdef.WorkPlanes.AddByPlaneAndOffset(bodies[1].Faces[2], 0); PlanarSketch sktch2 = cdef.Sketches.Add(wp, true); SketchPoint point = sktch2.SketchPoints.Add(transgeo.CreatePoint2d(0, 2.5)); sktch2.Shared = true; wp.Shared = true; HoleFeature hf = cdef.Features.HoleFeatures.AddDrilledByThroughAllExtent(point,0.1, PartFeatureExtentDirectionEnum.kPositiveExtentDirection); }

 

i always get "HRESULT: 0x80004005 "

i think i'm doing exactly same in the İnventors' Hole Exapmles;

Thank You for your help.

0 Likes
Accepted solutions (1)
1,492 Views
4 Replies
Replies (4)
Message 2 of 5

Mark.Lancaster
Consultant
Consultant

@Anonymous

 

Welcome to the Autodesk User's Community..

 

Programming questions for Inventor need to be asked in the Inventor Customization Forum https://forums.autodesk.com/t5/inventor-customization/bd-p/120.   I will have you posting relocated there to better suit your needs.

Mark Lancaster


  &  Autodesk Services MarketPlace Provider


Autodesk Inventor Certified Professional & not an Autodesk Employee


Likes is much appreciated if the information I have shared is helpful to you and/or others


Did this resolve your issue? Please accept it "As a Solution" so others may benefit from it.

0 Likes
Message 3 of 5

AlexFielder
Advisor
Advisor

Hi @Anonymous,

 

Comparing your code to the API help page here the only difference I can see is that the sample has the diameter enclosed like this "1cm" whereas yours is just 0.1 without speech marks.

So your code would go from this:

HoleFeature hf = cdef.Features.HoleFeatures.AddDrilledByThroughAllExtent(point,0.1, PartFeatureExtentDirectionEnum.kPositiveExtentDirection);

to this:

HoleFeature hf = cdef.Features.HoleFeatures.AddDrilledByThroughAllExtent(point, "0.1", PartFeatureExtentDirectionEnum.kPositiveExtentDirection);

 let me know if this helps.

 

Thanks,

 

Alex

0 Likes
Message 4 of 5

Anonymous
Not applicable
Accepted solution

Thak you for your reply. 

your solution is not correct. 

i found the solution 

1-Create workpoint on the sketchpoint

2-add workpoint in to the objectcollection

3-create PointHolePlacementDefiniton

4-Object Point =ObjectCollection[1]

5-Use PointHolePlacementDefinition for create hole 

Here is my codes

                PlanarSketch sktch2 = cdef.Sketches.Add(wp, true);
                SketchPoint point = sktch2.SketchPoints.Add(transgeo.CreatePoint2d(0, 3));
                WorkPoint wp1 = cdef.WorkPoints.AddByPoint(point);
ObjectCollection holecenter = application.TransientObjects.CreateObjectCollection(); PointHolePlacementDefinition phpd = cdef.Features.HoleFeatures.CreatePointPlacementDefinition(holecenter[1], cdef.WorkAxes[2]); HoleFeature hf = cdef.Features.HoleFeatures.AddDrilledByThroughAllExtent(phpd,1, PartFeatureExtentDirectionEnum.kPositiveExtentDirection);

it works for me .

Message 5 of 5

AlexFielder
Advisor
Advisor
glad you found the solution.

Of course it needed a holedefinition in order to work.

I find it interesting that (in the help) you can use a collection of sketchpoints, but your example using one sketchpoint is insufficient.
0 Likes