How can I detect the holes in a Assembly with Ilogic?

How can I detect the holes in a Assembly with Ilogic?

a90214
Participant Participant
2,004 Views
10 Replies
Message 1 of 11

How can I detect the holes in a Assembly with Ilogic?

a90214
Participant
Participant

Hi again, is possible to know using the Ilogic the diameter of the hole and if it is different from the bolt or screw change the hole diameter?

 

I am modifying my script:

 

https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/change-screw-dimensions-based-in-hol...

 

because the holes are made using Hole feature in the 3D Model.

 

I need to access the info of the Hole1, Hole2 and Hole3 in the assembly. This ones:

a90214_0-1659464427463.png

Because they aren't listed in here:

a90214_1-1659464556712.png

 

Thank you very much in advance.

 

0 Likes
2,005 Views
10 Replies
Replies (10)
Message 2 of 11

mcgyvr
Consultant
Consultant

How would the code know which hole is for which bolt if different sizes?

 



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
0 Likes
Message 3 of 11

A.Acheson
Mentor
Mentor

It might be a better approach to use bolt generator to create both hole and bolt size together based on center points. This way they at least complete a portion of your request. 

 

Otherwise you would need to do a deep dive into to the API to get a bolt, match the constraint associated with the bolt and the hole then check there sizes. Not exactly beginners coding for sure. 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 4 of 11

a90214
Participant
Participant

I am imaging that I have this layout:

 

Hole0 matches the first Bolt or Screw

Hole1 matches the second Bolt or Screw

Hole2 matches the third Bolt or Screw

 

I can make some limitations if needed.

0 Likes
Message 5 of 11

a90214
Participant
Participant

I have found this:

 

https://resources.imaginit.com/manufacturing-solutions-blog/traversing-assembly-structure-with-ilogi...

 

I was really happy when I saw recursion meaning that all of the parts are in one tree and if so I could be able to enter the child rigth?

The code should be something like:

 

 

Sub Main
    ' Get the active assembly. 
	Dim oAssyDoc As AssemblyDocument
	oAssyDoc = ThisApplication.ActiveDocument 
	
    ' Call the function
    Call TraverseAssembly(oAssyDoc.ComponentDefinition.Occurrences)
End Sub 
 
Sub TraverseAssembly(oOccs As ComponentOccurrences)
    ' Iterate through all of the occurrence in this collection
	Dim oOcc As ComponentOccurrence
	
	For Each oOcc In oOccs 
		
		' See each component

		MessageBox.Show(oOcc.Name, "My iLogic Dialog", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1)

                'it's a hole save diameter

		' find the bolts or screws outside and do a comparation between bolt diameter and hole
		If iProperties.Value(oOcc.Name, "Project", "Description").Contains("bolt") Or iProperties.Value(oOcc.Name, "Project", "Description").Contains("Bolt") Or iProperties.Value(oOcc.Name, "Project", "Description").Contains("screw") Or iProperties.Value(oOcc.Name, "Project", "Description").Contains("Screw") Then

		'Notify user that they are different
		My_Message0 = "O diâmetro do parafuso e do furo são diferente." + vbLf + "Deseja fazer a correção?"
        inputUser = MessageBox.Show(My_Message0, "Erro Detetado", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2)

        'Show the option to change, add to log or stop rule
        If inputUser = 6 Then '''Yes - change the Hole diameter
			MessageBox.Show(inputUser, "Yes", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1)
        
        ElseIf inputUser = 7 'No - creat a log saying that the HoleN wasn't change
			MessageBox.Show(inputUser, "No", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1)
		
        Else 'Cancel - Stop Everything and Exit Rule
			My_Message1 = "A execução da rule foi cancelada." + vbLf + "A parar a execução..."
			MessageBox.Show(My_Message1, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1)
	End If
		
                End If
		' Recursively call sub if needed
		If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
			Call TraverseAssembly(oOcc.SubOccurrences)
			MessageBox.Show("Aqui")
		End If
	Next

End Sub

 

 

0 Likes
Message 6 of 11

a90214
Participant
Participant

If there's any otherway more clear or simple please share.

 

Can I make like a file that sees the infos of the different holes in the .ipt file and save then in a .txt then on the .iam see the screws or bolts diameters, open my file .txt with the holes and do the comparasions one by one offering those options?

@mcgyvr @A.Acheson 

0 Likes
Message 7 of 11

A.Acheson
Mentor
Mentor

To start with you will need to access the hole feature in the part. Once you declare the first hole as a hole feature you can have access to everything about that feature. 

Dim oDoc As PartDocument = ThisApplication.ActiveDocument
    Dim oHoleFeature As HoleFeature =  oDoc.ComponentDefinition.Features.HoleFeatures.Item(1)
	MessageBox.Show(oHoleFeature.HoleDiameter.Value, "Hole Diameter with value in cm")

 

Then to access the hole feature in the assembly here is the easiest method for now just to manually select the occurrence.

	Dim oOcc As ComponentOccurrence = ThisApplication.CommandManager.Pick(
					SelectionFilterEnum.kAssemblyOccurrenceFilter, 
					"Select a component")
		
    Dim oHoleFeature As HoleFeature =  oOcc.Definition.Features.HoleFeatures.Item(1)
	MessageBox.Show(oHoleFeature.HoleDiameter.Value, "Hole Diameter with value in cm")

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 8 of 11

a90214
Participant
Participant

This is a really interesting solution, I am seeing that in the in the part a simple for each loop would be able to get everything.

The only thing with the assembly is that this is meant to be used in 300 or N Holes and Screws or Bolts and selecting 1 by one would be painful.

0 Likes
Message 9 of 11

A.Acheson
Mentor
Mentor

I have worked on a workflow that seems to be working. Some of how to finish it depends on how you are implementing the fastners at the moment. It isn't finished yet but it works like this.

Option1. Constraining the bolts into the holes

1.Look at the part file, loop through the holefeatures. 

2.On the edge where the hole is to be constrained create an edge label or read an existing one.

3.Read the hole diameter

3. Add a bolt from content center

4.Constrain using imates to the edge label.

 

To make a change to hole diameter,  change the definition in the assembly then delete the bolts and reapply new bolts at new size.

Can you let us know are all bolt holes utilized in the design? How are you deciding where the bolts go? How are you currently getting them into the assembly? Are other parts fixed to the same bolts? Some images would help. 

 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 10 of 11

a90214
Participant
Participant

Hi, instead of saying wrong stuuf I send an example of a part they want to use the rule. Everything done is done manually, they see the schemas that they have and build the part based on it.

 

Here is an example of the type of pieces they work with and want to apply the rule: https://we.tl/t-6JAUWZfTnG

 

@A.Acheson I will give more info when I talk directly with my colleague.

Also thank you so much for your help and interest in the subject.

0 Likes
Message 11 of 11

A.Acheson
Mentor
Mentor

If you can attach the assembly in a zip folder through pack and go directly in the post that would be better than users having to go to an external cloud storage link. I haven't viewed your assembly and can only view 2020. What version are you using?

 

The attached rules are 3 methods of working with fasteners in assemblies. 

  1.  Loops over all the holes in the part and assigns an edge label then adds a bolt to the hole. If you change the hole diameter this triggers the rule to run and deletes all the bolts and adds the bolts again. This might be a good one to use at the beginning of the process. 
  2. Loops over the all ready constrain bolts and detects the hole diameter via the constraint.geometry which is a circle. Then deletes the bolt and adds a bolt of a given size. 
  3. Similar to 2 but instead of deleting and adding a bolt it replaces from CC. It seems to be a good bit slower than deleting/adding but may have benefits in keeping annotation  attached in the drawing. 

Which one you might choose will depend on how your workflow is carried out but hopefully there is some starting point for you in there. 

This link here will help with naming edges, faces etc.

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan