counting named features (holes, cuts) in patterns

counting named features (holes, cuts) in patterns

wbarnardGTEV5
Contributor Contributor
397 Views
3 Replies
Message 1 of 4

counting named features (holes, cuts) in patterns

wbarnardGTEV5
Contributor
Contributor

we make holes in parts in three ways, punching, drilling, and burning.  i want to be able to pull this data out of large assembly boms later down the road, so im trying to use ilogic in my start parts to help with cost analysis later.

 

workflow will be that if holes are "PUNCHED", "DRILLED" OR "BURNED" the user will simply name the feature so it starts with one of those key words,  i have the macro just about working, except for where it comes to counting the named features once used in a pattern. 

 

'assume part document
Dim oDoc As PartDocument = ThisDoc.Document
'Set oDoc = ThisApplication.ActiveDocument
Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition

'assume rectangular pattern
Dim oRectPatterns As RectangularPatternFeatures = oDef.Features.RectangularPatternFeatures

'assume circular pattern
Dim oCircPatterns As CircularPatternFeatures = oDef.Features.CircularPatternFeatures


Dim A As Integer = 0
For Each BFeat In oDef.Features.ExtrudeFeatures
	If BFeat.Name.Contains("BURN") Then A = A + 1
Next

iProperties.Value("Custom", "BRN_HOLES") = A

' Calc patterned burned holes


Dim B As Integer = 0 'counter



For Each oRPPB As RectangularPatternFeature In oRectPatterns
	'consider only patterns CONTAINING NAME
	If oRPPB.ParentFeatures.Item(1).Name.Contains("BURN") Then Continue For
	For Each oFPEPB As FeaturePatternElement In oRPPB.PatternElements
		If oFPEPB Is active Then B += 1
	Next
Next





For Each oCPPB As CircularPatternFeature In oCircPatterns
	'consider only patterns CONTAINING NAME
	If oCPPB.ParentFeatures.Item(1).Name.Contains("BURN") Then Continue For
	For Each oFPEPB As FeaturePatternElement In oCPPB.PatternElements
		If oFPEPB Is active Then B += 1
	Next
Next
iProperties.Value("Custom", "PTN_BRNS") = B

Dim C As Integer = 0 'counter

For Each oRPbp As RectangularPatternFeature In oRectPatterns
	'consider only hole patterns
	If oRPbp.ParentFeatures.Item(1).Name.Contains("BURN") Then C += 1


Next



For Each oCPbp As CircularPatternFeature In oCircPatterns
	'consider only hole patterns
	If oCPbp.ParentFeatures.Item(1).Name.Contains("BURN") Then C += 1


Next
iProperties.Value("Custom", "BRN_PTNS") = C

'WORK WITH DRILLED HOLES

Dim D As Integer = 0
For Each DFeat In oDef.Features.ExtrudeFeatures
	If DFeat.Name.Contains("DRILL") Then D = D + 1
Next

iProperties.Value("Custom", "DRL_HOLES") = D

' Calc patterned DRILLED holes


Dim E As Integer = 0 'counter



For Each oRPPD As RectangularPatternFeature In oRectPatterns
	'consider only patterns CONTAINING NAME
	If oRPPD.ParentFeatures.Item(1).Name.Contains("DRILL") Then Continue For
	For Each oFPEPD As FeaturePatternElement In oRPPD.PatternElements
		If oFPEPD Is Active Then E += 1
	Next
Next





For Each oCPPD As CircularPatternFeature In oCircPatterns
	'consider only patterns CONTAINING NAME
	If oCPPD.ParentFeatures.Item(1).Name.Contains("DRILL") Then Continue For
	For Each oFPEPD As FeaturePatternElement In oCPPD.PatternElements
		If oFPEPD Is Active Then E += 1
	Next
Next
iProperties.Value("Custom", "PTN_DRLS") = E

Dim F As Integer = 0 'counter

For Each oRPDp As RectangularPatternFeature In oRectPatterns
	'consider only hole patterns
	If oRPDp.ParentFeatures.Item(1).Name.Contains("DRILL") Then F += 1


Next



For Each oCPDp As CircularPatternFeature In oCircPatterns
	'consider only hole patterns
	If oCPDp.ParentFeatures.Item(1).Name.Contains("DRILL") Then F += 1


Next
iProperties.Value("Custom", "DRL_PTNS") = F

'WORK WITH PUNCHED HOLES

Dim G As Integer = 0
For Each PFeat In oDef.Features.ExtrudeFeatures
	If PFeat.Name.Contains("PUNCH") Then G = G + 1
Next

iProperties.Value("Custom", "PUN_HOLES") = G

' Calc patterned punched holes


Dim H As Integer = 0 'counter



For Each oRPPP As RectangularPatternFeature In oRectPatterns
	'consider only patterns CONTAINING NAME
	If oRPPP.ParentFeatures.Item(1).Name.Contains("PUNCH") Then Continue For
	For Each oFPEPP As FeaturePatternElement In oRPPP.PatternElements 
		If Feature.IsActive(oRPPP)=True Then H += 1
	Next
Next


For Each oCPPP As CircularPatternFeature In oCircPatterns
	'consider only patterns CONTAINING NAME
	If oCPPP.ParentFeatures.Item(1).Name.Contains("PUNCH") Then Continue For
	For Each oFPEPP As FeaturePatternElement In oCPPP.PatternElements
		If Feature.IsActive(oCPPP)=True Then H += 1
	Next
Next
iProperties.Value("Custom", "PTN_PUNS") = H

Dim J As Integer = 0 'counter

For Each oRPPPAT As RectangularPatternFeature In oRectPatterns
	'consider only hole patterns
	If oRPPPAT.ParentFeatures.Item(1).Name.Contains("PUNCH") Then J += 1


Next



For Each oCPPPAT As CircularPatternFeature In oCircPatterns
	'consider only hole patterns
	If oCPPPAT.ParentFeatures.Item(1).Name.Contains("PUNCH") Then J += 1


Next
iProperties.Value("Custom", "PUN_PTNS") = J

BURNCOUNT = (iProperties.Value("Custom", "BRN_HOLES") + iProperties.Value("Custom", "PTN_BRNS")) -iProperties.Value("Custom", "BRN_PTNS")


iProperties.Value("Custom", "BURNED HOLES") = BURNCOUNT



DRILLCOUNT = (iProperties.Value("Custom", "DRL_HOLES") + iProperties.Value("Custom", "PTN_DRLS")) -iProperties.Value("Custom", "DRL_PTNS")


iProperties.Value("Custom", "DRILLED HOLES") = DRILLCOUNT



PUNCHCOUNT = (iProperties.Value("Custom", "PUN_HOLES") + iProperties.Value("Custom", "PTN_PUNS")) -iProperties.Value("Custom", "PUN_PTNS")


iProperties.Value("Custom", "PUNCHED HOLES") = PUNCHCOUNT



TOTALCOUNT = iProperties.Value("Custom", "DRILLED HOLES") + iProperties.Value("Custom", "BURNED HOLES") + iProperties.Value("Custom", "PUNCHED HOLES")


iProperties.Value("Custom", "HOLES TOTAL") = TOTALCOUNT

 

0 Likes
Accepted solutions (2)
398 Views
3 Replies
Replies (3)
Message 2 of 4

wbarnardGTEV5
Contributor
Contributor

specifically, the issue is in these loops.  it will not count the consumed features

 

For Each oRPPB As RectangularPatternFeature In oRectPatterns
	'consider only patterns CONTAINING NAME
	If oRPPB.ParentFeatures.Item(1).Name.Contains("BURN") Then Continue For
	For Each oFPEPB As FeaturePatternElement In oRPPB.PatternElements
		If oFPEPB Is active Then B += 1
	Next
Next
For Each oCPPB As CircularPatternFeature In oCircPatterns
	'consider only patterns CONTAINING NAME
	If oCPPB.ParentFeatures.Item(1).Name.Contains("BURN") Then Continue For
	For Each oFPEPB As FeaturePatternElement In oCPPB.PatternElements
		If oFPEPB Is active Then B += 1
	Next

 

0 Likes
Message 3 of 4

WCrihfield
Mentor
Mentor
Accepted solution

It's a little difficult to debug remotely but when I look at those two loops you pointed out, the final line within the loop that is supposed to add to the count does not look valid to me.

This line:

If oFPEPB Is active Then B += 1

does not appear to be doing anything, because 'Is active' is not a valid property/method of a FeaturePatternElement (Link1, Link2).  You could try something like this in its place, which would be a similar sounding test:

If oFPEPB.Suppressed = False Then B += 1

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 4

wbarnardGTEV5
Contributor
Contributor
Accepted solution

Thank you!

 

It is now working, I also needed to invert part of the selection.

 

resulting loop example

 

For Each oRPb As RectangularPatternFeature In oRectPatterns
	'consider only patterns CONTAINING NAME
	If Not oRPb.ParentFeatures.Item(1).Name.Contains("BURN") Then Continue For
	For Each oFPEb As FeaturePatternElement In oRPb.PatternElements
		If oFPEb.Suppressed = False Then B += 1
	Next
Next
0 Likes