How to select all sheet metal parts with a certain thickness ?
Hi guys,
I am new to programming, so maybe its a stuppid question !!
I am looking for a sample code to select all sheet metal parts with, for example thickness 0.5 mm.
i have been seaching for sample but did not find them. Hopefully someone very kind has a piece of code.
Thanks all.
Solved! Go to Solution.
Solved by Vladimir.Ananyev. Go to Solution.
I've developed a small sample code that could be a good start point for your program.
Note that sheet metal document is a subtype of PartDocument.
It has a lot of specific methods and properties.
Please refer Inventor API Help for more details.
Sub FindSheetsByThickness() 'target thickness - search criteria Dim TargetThickness As Double TargetThickness = 0.05 'cm '------------------------------- Dim oAssyDoc As AssemblyDocument Set oAssyDoc = ThisApplication.ActiveDocument Dim oAssyDef As AssemblyComponentDefinition Set oAssyDef = oAssyDoc.ComponentDefinition 'select set object of main assembly Dim oSSet As SelectSet Set oSSet = oAssyDoc.SelectSet Dim oDoc As Inventor.Document For Each oDoc In oAssyDoc.AllReferencedDocuments 'verify document type (we are interested in metsl sheets only) If oDoc.ComponentDefinition.Type = kSheetMetalComponentDefinitionObject Then 'extract thickness of this sheet part Dim oDef As SheetMetalComponentDefinition Set oDef = oDoc.ComponentDefinition Dim Thickness As Double Thickness = oDef.Thickness.Value 'returned in cm (base length units) If Math.Abs(Thickness - TargetThickness) < 0.00001 Then 'thickness is equal to target thickness 'find all child components for this part document 'at all assembly levels Dim oColl As ComponentOccurrencesEnumerator Set oColl = oAssyDef.Occurrences.AllReferencedOccurrences(oDoc) If oColl.Count > 0 Then 'select all found components Dim oOcc As ComponentOccurrence For Each oOcc In oColl Call oSSet.Select(oOcc) Next oOcc End If End If End If Next Beep End Sub
Hope this helps.
Cheers,