Community
Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic to Changed Tapped Hole Modeling Settings

7 REPLIES 7
Reply
Message 1 of 8
tdswanson
1002 Views, 7 Replies

iLogic to Changed Tapped Hole Modeling Settings

Hey everyone:

 

I'm trying to write some iLogic to enable me to do an interference check in an IAM file without finding an interference of every bolt in every hole.  So the idea is to loop through components and change this setting to MAJOR, check for interference, then loop back through with a second rule changing the settings back to TAP DRILL for CAM programming purposes.  (This is why I can't just change the default in our templates.)

 

Anyway, I've got some code and it "usually" works well.  But sometimes I get this error:

**********

Error in rule: Tapped_Hole_Major, in document: <DOC NAME>.iam

Member not found. (Exception from HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND))

**********

 

When I get that error, I've found that I can normally close Inventor.  Re-open it, run the rule, and everything is fine.  What gives?  Suggestions?

 

Here's the code:

 

' ***********REFERENCES***************
' kThreadMajorDiameter 21761
' kThreadMinorDiameter 21762
' kThreadPitchDiameter 21763
' kThreadTapDrillDiameter 21764
' ************************************

' ***********DECLARATIONS***********
app = ThisApplication
Dim openDoc As Document
Dim docFile As Document
Dim assemblyDoc As AssemblyDocument
Dim assemblyDef As AssemblyComponentDefinition
openDoc = ThisDoc.Document
' ************************************

' ***********FOR A COMPONENT FILE***********
openDoc.ModelingSettings.TappedHoleDiameter = 21761
iLogicVb.UpdateWhenDone = True
' ******************************************

' ***********FOR AN ASSEMBLY FILE***********

If openDoc.DocumentType = kAssemblyDocumentObject Then
    assemblyDoc = openDoc
    assemblyDef = assemblyDoc.ComponentDefinition
'    
    For Each docFile In assemblyDoc.AllReferencedDocuments          
			If docFile.IsModifiable = True Then 

				docFile.ModelingSettings.TappedHoleDiameter = 21761
				
			End If 
			
	Next
Else 

End If 
' ******************************************

 

 

7 REPLIES 7
Message 2 of 8
adam.nagy
in reply to: tdswanson

Hi there,

 

There is a long discussion here about a similar error where I think in the end separating the part and assembly document handling helped:

http://forums.autodesk.com/t5/Inventor-General/Use-ilogic-to-set-the-size-and-length-of-a-part/td-p/...

 

Another thing you could try is put your code full of Trace messages to figure out which line is causing issues: 

http://forums.autodesk.com/t5/Inventor-General/iLogic-Developing-and-debugging/td-p/2845670

 

I hope this helps.


Cheers,



Adam Nagy
Autodesk Platform Services
Message 3 of 8
tdswanson
in reply to: adam.nagy

Thanks very much for looking at my post and giving it some thought.  Before I posted this, I actually REM'd out every line and "unleashed" them one at a time to debug.

 

(As an aside, is there a way to "step" through an iLogic program similar to that in Office VBA?)

 

Without much surprised, I found that it was this line that generates the issue:

 

docFile.ModelingSettings.TappedHoleDiameter = 21761

 What I can't seem to come up with is why I can close Inventor, open it again, re-run the code and have no issue.

 

I need to do some more testing, but I don't believe that this problem discriminates between assemblies and components.

 

Anyway, thanks again for looking!

Message 4 of 8
adam.nagy
in reply to: tdswanson

No, you cannot step through the code in iLogic, but you could in Inventor VBA.

 

Also, you could place the problematic part in a Try/Catch block and then print out the name of the file that causes the issue.

That might give a clue about why it's happening.

 

Cheers,



Adam Nagy
Autodesk Platform Services
Message 5 of 8
tdswanson
in reply to: adam.nagy

Adam - thanks for confirming.  Yes I did a combination of message boxes and REMing out code for testing.  I think I got this pretty well knocked out now, but I haven't had a chance to post it.

 

It took a lot of testing, but I think it'll drill through sub assemblies and stuff too.  I'll try to post soon.

Message 6 of 8
mrattray
in reply to: tdswanson

There are certain entities that can cause unexpected errors when looping through the occurrences collection.
The ones that come to mind are weld beads, suppressed components and virtual components. Do you have anything like this in your test assembly? What happens if you try your code in a new, simplified test assembly?
Mike (not Matt) Rattray

Message 7 of 8
tdswanson
in reply to: mrattray

That's good information to have.  I didn't have any components fitting those descriptions in my testing, but I conceivably could in the future and I'd like to be able to account for it.  Thanks for the warning!

Message 8 of 8
tdswanson
in reply to: tdswanson

OK - Here's my code for this project.  The idea is that a user can be in an assembly file and change all the model files to model the threaded holes as MAJOR, then run an interference check, then change the modeling settings back.  So there's a companion program to this one that changes them back to the tap drill size.

 

Some notes and/or random thoughts:

 

* At my company, we always want tapped holes modeled at tap drill so the pilot holes are sized correctly for cutting on our water jet.  I've also created a rule to run "before save" in my templates to verify that the modeling settings are set to tap drill so that I don't inadvertantly cut a bunch of oversized holes.

 

* The below code will obviously do nothing for models not originally modeled in Inventor, like manufacturer provided models for store-bought components, etc.

 

* You will also still often see some interference in your assembly models, like for an oversized dowel pin pressed in a hole for example.

 

* This file will loop through all referenced documents in the assembly file.  It appears that it will only touch part documents and assembly documents, and will ignore weld beads, virtual components, and components that are referenced from libraries and thus not modifiable.

 

I hope this helps some folks!  If you've got suggestions, I'd be interested to hear them....  Good luck!

 

' ********** References *********
' kThreadMajorDiameter 21761
' kThreadMinorDiameter 21762
' kThreadPitchDiameter 21763
' kThreadTapDrillDiameter 21764

' ********** Declarations 
iLogicVb.UpdateWhenDone = True
Dim partDoc As PartDocument = TryCast(ThisDoc.Document, PartDocument) ' Set Variable if the Current Doc Type is Part
Dim assemDoc As AssemblyDocument = TryCast(ThisDoc.Document, AssemblyDocument) ' Set Variable if the Current Doc Type is Assembly

' ********** For a Component File
If (partDoc IsNot Nothing) Then ' If this is a part document
	partDoc.ModelingSettings.TappedHoleDiameter = 21761 ' Set the Tapped Hole Type
End If

' ********** For an Assembly File
If (assemDoc IsNot Nothing)Then ' If this is an Assembly document
	assemDoc.ModelingSettings.TappedHoleDiameter = 21761 ' Set the Tapped Hole in the Assembly File
	Dim docFile As Document ' Declare a Variable for each referenced document to loop thru
	i = 0
	For Each docFile In assemDoc.Allreferenceddocuments ' For all the documents referenced in the assembly
		If docFile.IsModifiable = True Then ' If the document is able to be modified
			Dim RefassemDoc As AssemblyDocument = TryCast(docFile, AssemblyDocument) ' Set Variable if the Current Doc Type is Part
			Dim RefpartDoc As PartDocument = TryCast(docFile, PartDocument) ' Set Variable if the Current Doc Type is Assembly
			If (RefpartDoc IsNot Nothing) Then ' If this Doc is a Part
				
				RefpartDoc.ModelingSettings.TappedHoleDiameter = 21761 ' Set the Tapped Hole Type
			Else ' This Doc must be an assembly
				Dim RefAsmDoc As AssemblyDocument = TryCast(docFile, AssemblyDocument) ' Set Variable if the Current Doc Type is Part
				Try
				RefAsmDoc.ModelingSettings.TappedHoleDiameter = 21761 ' Set the Tapped Hole Type
				Catch
				End Try
			End If
		End If
	Next
End If

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report