- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have a macro to place a part into the assembly. The problem is that while it works, it seems to skip past it and not wait for user input. So I am attempting to write a code into my program to check for the existence of the part and simply loop the code until the part is actually placed. Unfortunately I'm not great at coding in inventor and I'm getting some of the nomenclature wrong it seems.
This is the code for my check function
SyntaxEditor Code Snippet
Function CompExist(sName) As Boolean 'Declaring Parameters Dim blTag As Boolean blTag = False Dim oOcc As ComponentOccurrence Dim oDoc As AssemblyDocument oDoc = ThisDoc.Document Dim oCompDef As AssemblyComponentDefinition oCompDef = oDoc.ComponentDefinition Dim Occurrences As ComponentOccurrences ' Iterate through all of the occurrence in this collection. This ' represents the occurrences at the top level of an assembly. Dim i As Integer For i = 1 To oCompDef.ComponentDefinition.ComponentOccurrences(i).Name If oCompDef.ComponentDefinition.ComponentOccurrences(i).Name = sName Then blTag = True End If Next CompExist = blTag End Function
My error seems to come from the for loop, where I can't quite get the naming correct for iterating through all of the components. I keep getting the error "Public member 'ComponentDefinition' on type 'AssemblyComponentDefinition' not found."
In case you had any suggestions for implementing a wait code directly into the component placement macro, here is the code for it.
Public Sub Place_Part()
' Get the command manager.
Dim oCommandMgr As CommandManager
Set oCommandMgr = ThisApplication.CommandManager
' Post the filename.
Call oCommandMgr.PostPrivateEvent(kFileNameEvent, _
"N:\Mechpart\TLONG\Reference Materials\C15.ipt")
' Get control definition for the place component command.
Dim oControlDef As ControlDefinition
Set oControlDef = oCommandMgr.ControlDefinitions.Item( _
"AssemblyPlaceComponentCmd")
' Execute the command.
Call oControlDef.Execute
End Sub
Thank you in advance for your help.
Solved! Go to Solution.