Macro to select same holes/diameter and surfaces on the same level

Macro to select same holes/diameter and surfaces on the same level

FTKnur
Collaborator Collaborator
1,003 Views
4 Replies
Message 1 of 5

Macro to select same holes/diameter and surfaces on the same level

FTKnur
Collaborator
Collaborator

Hi all,

 

first of all: I don't have any experience in programming with VBA 😕

 

My Problem is that I only have a imported file and I can't select the features or holes. I only can select the surfaces.

Is it possible to select one hole and then check all other holes and select all with the same diameter?

Also I need a macro to select all surfaces on the same height of the actually selected.

 

I hope somebody can help me 🙂

 

Accepted solutions (1)
1,004 Views
4 Replies
Replies (4)
Message 2 of 5

CCarreiras
Mentor
Mentor

HI!

 

I supposed that you only have a part, that is just a solid, without any features in the browser three.

In that case, you case use the tool "RECOGNIZE FEATURES" to help you to recognize the holes in the part and group them.

Your aim is to group holes, therefore, you just have to set the filter for searching for all the holes in the part and group the same holes in the same browser hole feature.

Check  this tool in the link below (free tool) 

https://apps.autodesk.com/INVNTOR/en/Detail/Index?id=9172877436288348979&appLang=en&os=Win32_64

CCarreiras

EESignature

0 Likes
Message 3 of 5

FTKnur
Collaborator
Collaborator

Hi @CCarreiras,

 

thank you for the hint with the recognizer.

That tool is realy cool but not so convenient to me. (or I use it wrong)

I can recognize all holes but after this there is no usefull sorting of them. I have very many files with a lot of holes. Don't want to sort them 😕

0 Likes
Message 4 of 5

Sergio.D.Suárez
Mentor
Mentor
Accepted solution

Hi, I leave two ilogic rules for you to try, which can easily be converted to VBA if you need.
The first will select the holes that have the same diameter.
You must first select a cylindrical face.

 

Dim oDoc As PartDocument= ThisDoc.Document
Dim oCD As ComponentDefinition = oDoc.ComponentDefinition
Dim oRad1 As Double, Rad2 As Double
Dim oCommand As CommandManager = ThisApplication.CommandManager

Line1 : 
Dim oF1 As Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter,"Select Cylindrical Face") 
If oF1.SurfaceType <> 5891 Then GoTo Line1
oRad1 = Round(oF1.Geometry.Radius,3)
oCommand.DoSelect(oF1)

For Each oSolid As SurfaceBody In oCD.SurfaceBodies
	For Each oFace As Face In oSolid.Faces
		If oFace.SurfaceType = 5891 Then
			oRad2 = Round(oFace.Geometry.Radius,3)
			If oRad2 = oRad1 Then oCommand.DoSelect(oFace)
		End If
	Next
Next

 

Now a rule that must select the flat faces that are at the same height, comparing their coordinates. You must first select the initial flat face

 

Dim oDoc As PartDocument= ThisDoc.Document
Dim oCD As ComponentDefinition = oDoc.ComponentDefinition

Dim oCommand As CommandManager = ThisApplication.CommandManager
Dim oX1 As Double, oY1 As Double, oZ1 As Double,oX2 As Double, oY2 As Double, oZ2 As Double, oAngle As Double

Line1 : 
Dim oF1 As Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter,"Select Cylindrical Face") 
If oF1.SurfaceType <>  5890 Then GoTo Line1

oCommand.DoSelect(oF1)

oX1 =Round(oF1.PointOnFace.X,3)
oY1 =Round(oF1.PointOnFace.Y,3)
oZ1 =Round(oF1.PointOnFace.Z,3)

For Each oSolid As SurfaceBody In oCD.SurfaceBodies
	For Each oFace As Face In oSolid.Faces
		If oFace.SurfaceType =  5890 Then
			oX2 =Round(oFace.PointOnFace.X,3)
			oY2 =Round(oFace.PointOnFace.Y,3)
			oZ2 =Round(oFace.PointOnFace.Z,3)
			If oX1 = oX2 Or oY1 = oY2 Or oZ1 = oZ2 Then
				oAngle = Round(ThisApplication.MeasureTools.GetAngle( oF1, oFace),3)
				If  oAngle = 0 Then oCommand.DoSelect(oFace)
			End If
		End If
	Next
Next

 

I hope this helps. regards


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 5 of 5

FTKnur
Collaborator
Collaborator

Hi @Sergio.D.Suárez,

 

YES! Thats exactly what I need. Thank you very much! 🙂

0 Likes