Macro to create hole feature at center of selected face

Macro to create hole feature at center of selected face

Anonymous
Not applicable
2,858 Views
8 Replies
Message 1 of 9

Macro to create hole feature at center of selected face

Anonymous
Not applicable

Hi All,

 

I am looking for a macro, to create hole feature of 0.5" Diameter at the center of selected faces.

When I run the macro, it should ask for "SELECT FACE" once I select the face/faces, hole of 0.5" Diameter to be created at the center of selected face and should ask for "NEXT FACE" to repeat same operation and "DONE" for terminating the operation.

 

Please let me know if a code can be written for above mentioned case. Kindly need help from our community's experts on this.

 

Attached image for your reference.

 

Thank you..

 

Regards,

Harish

0 Likes
Accepted solutions (1)
2,859 Views
8 Replies
Replies (8)
Message 2 of 9

Mark.Lancaster
Consultant
Consultant

@Anonymous

 

Are you looking to automate your steps or can you use this workflow by creating a work point that centers based on a loop of edges?

 

6-21-2017 3-57-38 PM.jpg

 

Then use that point as your starting point for that hole.  If the size of the face changes, the point automatically rec-enters.

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.

Message 3 of 9

Curtis_Waguespack
Consultant
Consultant

Hi hmanoharBYAYC,

 

Here's a quick iLogic macro to do this. Attached is a 2017 example file as well.

 

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 


Dim oSheetMetalDoc As PartDocument oSheetMetalDoc = ThisApplication.ActiveEditDocument ' a reference to the component definition. Dim oCompDef As SheetMetalComponentDefinition oCompDef = oSheetMetalDoc.ComponentDefinition ' a reference to the sheet metal features collection. Dim oSheetMetalFeatures As SheetMetalFeatures oSheetMetalFeatures = oCompDef.Features Dim oFace As Face 'Keep Selecting Faces, Hit Esc to finish Do oFace = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllPlanarEntities, "Select a face") If Not oFace Is Nothing Then Exit Do End If Loop While Not oFace Is Nothing ' Get the outer loop of the face. Dim outerLoop As EdgeLoop For Each outerLoop In oFace.EdgeLoops If outerLoop.IsOuterEdgeLoop Then Exit For End If Next ' Create a workpoint at the edge mid-point Dim oWorkPoint As WorkPoint oWorkPoint = oCompDef.WorkPoints.AddAtCentroid(outerLoop) Dim oPointPlacement As PointHolePlacementDefinition oPointPlacement = oCompDef.Features.HoleFeatures.CreatePointPlacementDefinition(oWorkPoint,oFace) ' Create the hole feature, 0.5 cm dia Call oCompDef.Features.HoleFeatures.AddDrilledByThroughAllExtent( _ oPointPlacement, 0.5, kPositiveExtentDirection) 'turn off workpoint oWorkPoint.Visible = False

 

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

Message 4 of 9

Curtis_Waguespack
Consultant
Consultant

@Anonymous wrote:

... and should ask for "NEXT FACE" to repeat same operation and "DONE" for terminating the operation.

 

 


Hi hmanoharBYAYC,

 

This version repeats as per your request.

 

Also just as a tip, you can search and ask programming questions of this type on the Inventor Customization forum too:
http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/bd-p/120

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

Dim oSheetMetalDoc As PartDocument
oSheetMetalDoc = ThisApplication.ActiveEditDocument

' a reference to the component definition.
Dim oCompDef As SheetMetalComponentDefinition
oCompDef = oSheetMetalDoc.ComponentDefinition

' a reference to the sheet metal features collection.
Dim oSheetMetalFeatures As SheetMetalFeatures
oSheetMetalFeatures = oCompDef.Features

Dim oFace As Face

'Keep Selecting Faces, Hit Esc to finish
Do
    oFace = ThisApplication.CommandManager.Pick _
	(SelectionFilterEnum.kAllPlanarEntities, _
	"Select a face, press Esc to finish")
    If Not oFace Is Nothing Then 
		' Get the outer loop of the face.
		Dim outerLoop As EdgeLoop
		For Each outerLoop In oFace.EdgeLoops
			If outerLoop.IsOuterEdgeLoop Then
				Exit For
			End If
		Next
		
		' Create a workpoint at the edge mid-point
		Dim oWorkPoint As WorkPoint
		oWorkPoint = oCompDef.WorkPoints.AddAtCentroid(outerLoop)
		
		Dim oPointPlacement As PointHolePlacementDefinition 
		oPointPlacement = oCompDef.Features.HoleFeatures. _
		CreatePointPlacementDefinition (oWorkPoint,oFace)
		
		' Create the hole feature, 0.5 cm dia
		Call oCompDef.Features.HoleFeatures. _
		AddDrilledByThroughAllExtent( _
		oPointPlacement, 0.5 * 2.54, kPositiveExtentDirection)
		'turn off workpoint
		oWorkPoint.Visible = False
    End If
Loop While Not oFace Is Nothing

EESignature

Message 5 of 9

Anonymous
Not applicable

Hello Sir,

 

Thank you so much for your response and the ilogic code provided.

Unfortunately the above ilogic code is not working at my end, its showing error:

------------------------------------------------------------------------------------------------------------

Error in rule: Rule0, in document: Part3.ipt

Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))

------------------------------------------------------------------------------------------------------------

Also i am not able to use the example part file provided, since i am using Inventor-2016 version.

 

Request you to send me a part file in 2016 version to see the ilogic fulfills my requirement.

 

As i went through the ilogic code, where i noticed that the center for hole is created by "Work Point". I am looking for an option, where the ilogic should enter into the sketch mode and insert "Point, Center Point" at the center of selected face.

 

Please help me on this..

 

Thank you,

 

Regards,

Harish

0 Likes
Message 6 of 9

Anonymous
Not applicable

Hello Sir,

 

Thank you so much for your response.

 

I am looking for an ilogic and my requirement posted on Mr Curtis post.

 

Please let me know if you have nay solution.

 

Thank you Again,

 

Regards

Harish

0 Likes
Message 7 of 9

S_May
Mentor
Mentor
Accepted solution

Hi @Anonymous,

 

I could also make them an ifeature with which you can create the lick and the hole at once (example in the screencast).

If they work a lot with sheet metal there are 100 Solutions.

 

MFG

 

Sascha May

Message 8 of 9

Anonymous
Not applicable

Hi Sascha May,

 

Thank you so much for your response and screencast provided.

 

The Screecast provided helped me to think in different way to improve my work process.

 

Problem is, right now we are not suppose to use ifeatures in our project, since these part designs are used globally and we need to set standards to use ifeature, which may happen in later stages.

 

Please let me know if you know any other  method than this, where center point for hole should be sketch based.

 

Thanks a lot...

 

Regards,

Harish Kumar M

0 Likes
Message 9 of 9

Curtis_Waguespack
Consultant
Consultant

Hi hmanoharBYAYC,

 

I looked at the example I provided in Inventor 2015 and I do see the Unspecified Error in that version. The error seems to be related to creating the workpoint, which you have updated this post to say that you do not want that result.

 

I think the method for hole placement from linear edges would be the method to use, but unfortunately I do not have the time today to look at this further. Below is that sample in case it helps you or someone else interested in this.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

Hole feature linear placement API Sample

https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2018/ENU/Inventor-API/files/Ho...

 

 

EESignature