Change Screw Dimensions Based In Hole Dimension (iLogic)

Change Screw Dimensions Based In Hole Dimension (iLogic)

a90214
Participant Participant
598 Views
2 Replies
Message 1 of 3

Change Screw Dimensions Based In Hole Dimension (iLogic)

a90214
Participant
Participant

Hi, I am a Student and started working on Inventor about a week ago because a colleague of mine asked me to try to develop a script that would modify a screw based on the size of the hole automatically, taking as reference the drawn but the problem is that I can't even make Inventor run what I write or other scripts just crash. I also found this:

 

https://knowledge.autodesk.com/support/inventor/learn-explore/caas/simplecontent/content/get-thread-...

 

and

 

https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/change-size-of-clearance-hole-with-i...

 

both from @WCrihfield


That I think almost do what I am looking for.
I would be very grateful if you could guide me to develop a solution, in order to fulfill this promise.

Attached I send what I was doing but it seems to be something wrong. These are just example parts, that I was testing the scripts mention ahead.

 

Resume: Make a general script able to detect the holes and make comparisons the with the screws in order to change them if the dimensions are not the same.


Thank you very much in advance.

0 Likes
599 Views
2 Replies
Replies (2)
Message 2 of 3

A.Acheson
Mentor
Mentor

If you can post the rule your using and the error messages your receiving users might be able to help. I would suggest work to get an existing working rule up and running first before modifying. If you are unsure of where the rule fails place a message box after a line of code and if you successfully get there you can assume all is ok to that point. Repeat the process then you get an error. 

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

a90214
Participant
Participant

Hello again, I ended up leaving this project a little idle but I'm back to it and I ended up with this solution:

 

Dim assemblyDef As AssemblyComponentDefinition = ThisDoc.Document.ComponentDefinition
Dim oco As AssemblyConstraints = assemblyDef.Constraints
Dim occ As Inventor.ComponentOccurrence
For Each occ In assemblyDef.Occurrences.AllLeafOccurrences
	Dim refDoc As PartDocument = occ.Definition.Document
	If iProperties.Value(occ.Name, "Project", "Description").Contains("bolt") Or iProperties.Value(occ.Name, "Project", "Description").Contains("Bolt") Or iProperties.Value(occ.Name, "Project", "Description").Contains("screw") Or iProperties.Value(occ.Name, "Project", "Description").Contains("Screw") Then
		
		For Each myconstraint As AssemblyConstraint In occ.Constraints						  
							  
  
			boltlength = Parameter(myconstraint.OccurrenceOne.Name, "NLG")
			partlength = Parameter(myconstraint.OccurrenceTwo.Name, "LEN")
			
			boltdiameter = Parameter(myconstraint.OccurrenceOne.Name, "NND")
			partdiameter = Parameter(myconstraint.OccurrenceTwo.Name, "DIA")
			
			
			
			If boltlength>partlength
				myconstraint.OccurrenceOne.Edit
				i = MessageBox.Show("O comprimento do parafuso é maior do que o comprimento do componente", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1)
				Parameter(myconstraint.OccurrenceTwo.Name, "LEN") = boltlength
			End If
			
			If Not boltdiameter = partdiameter
				myconstraint.OccurrenceOne.Edit
				i = MessageBox.Show("O diametro do parafuso e do buraco não correspondem", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1)
				Parameter(myconstraint.OccurrenceTwo.Name, "DIA") = boltdiameter
			End If
					
		Next
		occ.Visible = True

	Else
		occ.Visible = True
	End If
	

Next

 

But this solution is not fully automated because I have to reference the DIA (diameter) and LEN (length) in the component parameters by hand because I don't know how to make the comparison without doing this, the last problem is that the operation applied to one screw and it should be performed in N.


Does anyone have a tip on how to do it?

 

Note: holes are made as Circle and Extrude. Everything must be in mm.

 

Thanks in advance


Ref for help: @A.Acheson @WCrihfield