Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

how to find parts that start with an "S" in an assembly using vba

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
akosi
516 Views, 3 Replies

how to find parts that start with an "S" in an assembly using vba

hi

 

how to find parts that start with an "S" in an assembly using vba

and show it in the msgbox?

 

 

3 REPLIES 3
Message 2 of 4
Gruff
in reply to: akosi

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

Message 3 of 4
akosi
in reply to: Gruff

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.?

 

Message 4 of 4
Gruff
in reply to: akosi

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.

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

Post to forums  

Autodesk Design & Make Report