hi
how to find parts that start with an "S" in an assembly using vba
and show it in the msgbox?
Solved! Go to Solution.
Solved by Gruff. Go to Solution.
Private Sub Button1_Click()
Dim oApp As Inventor.Application
Dim oTopDoc As Inventor.Document
Dim oDoc As Inventor.Document
Dim sFile As String
Dim sMsg As String
Set oApp = ThisApplication
Set oTopDoc = oApp.ActiveDocument
For Each oDoc In oTopDoc.AllReferencedDocuments
sFile = GetFileName(oDoc.FullFileName)
If LCase(Left$(sFile, 1)) = "s" Then 'Remove the lCase() function if you want to check for Upper case "S" specifically
sMsg = sMsg & sFile & vbCrLf
End If
Next oDoc
MsgBox sMsg
End Sub
'-----
Public Function GetFileName(ByVal FullFileName) As String
Dim nPos As Integer
Dim sName As String
sName = FullFileName
nPos = InStrRev(sName, "\")
If nPos > 0 Then
sName = Mid(sName, nPos + 1)
End If
GetFileName = sName
End Function
i think "all referenced " is giving all referenced docs. in all nodes.
i need to get the parts of the assembly (first node?) only.
does this apply to blocks too? i need to get a particular blocks that start with a "9" too.?
You can of course use the ReferencedDocuments property on the top level document instead of the AllReferencedDocuments Property. This will give you what you ask for.
As far as Blocks. No. You would have to create several sub loops on each part to drill down to each block.
(In the Inventor API they are defined as SketchBlocks.)
As far as I can tell from a quick peek at Inventor API help. (Which by the way would be a good thing for you to start doing. 🙂 Select the pulldown next to the question mark in the top right of the ribbon and select: Community Resources then Programming Help.)
You would need to get the ComponentDefinition within each part,
then get the SketchBlockDefinitions Collection Loop through it and
get the SketchBlocks Collection then loop through that looking for a sketch block that fits your criteria.
Be aware that different part types have different ComponentDefinition types that are not compatable.
SheetmetalComponentDefintion <> PartComponentDefiniton. Etc...
Another thing for you to start doing is using VBA's intellisense. This feature will list all properties, methods, and events for every Inventor API object in the VBA editor. Simply type the name of the object and press the period key. If you have declared and set your inventor variable object types correctly you will see the drop down list.
For a test try it with the oDoc object inside the loop in the code I provided previously.
I cannot give you not detailed code on Sketchblocks as I have never used them.