Chamfer Part Feature count

Chamfer Part Feature count

Anonymous
Not applicable
1,640 Views
12 Replies
Message 1 of 13

Chamfer Part Feature count

Anonymous
Not applicable

If I select more than one edge for a single chamfer feature, the API (ChamferFeatures.Count) counts this as 1.

How would I go about obtaining the total amount of chamfered edges?

0 Likes
Accepted solutions (1)
1,641 Views
12 Replies
Replies (12)
Message 2 of 13

YuhanZhang
Autodesk
Autodesk

Not quite clear about the question, can you explain more about it? Or paste your code here so we can check if it works as expected?



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 3 of 13

Anonymous
Not applicable

Hi @YuhanZhang

 

Thank you for your reply.

 

Please see the code below and the attached part as an example. In the example, I am looking for a result of 4 chamfers. 

 

Dim oRefDoc As PartDocument = ThisApplication.ActiveDocument

' Get the referenced document component definition
Dim oCD As PartComponentDefinition = oRefDoc.ComponentDefinition

' Get the referenced document feature collection
Dim oFeatures As PartFeatures = oCD.Features

Dim oFeature As PartFeature

'  Get the referenced document feature count 
Dim oFeatureCount As Integer = oFeatures.Count

'  Get the referenced document hole feature collection 
Dim oHoles As HoleFeatures = oFeatures.HoleFeatures

'  Get the referenced document chamfer feature collection 
Dim oChamfers As ChamferFeatures = oFeatures.ChamferFeatures
'Dim oChamferCount As Integer = oChamfers.Count
oChamferCount = oChamfers.Count

MsgBox(oChamferCount)  

 

0 Likes
Message 4 of 13

YuhanZhang
Autodesk
Autodesk

So what you want to get is the count of chamfered edges but not the count of ChamferFeatures, below is a sample VBA code to get the chamfered edges' count, you can run it in VBA Editor with your data:

 

Sub GetChamferedEdgesCount()
    Dim oRefDoc As PartDocument
    Set oRefDoc = ThisApplication.ActiveDocument

    ' Get the referenced document component definition
    Dim oCD As PartComponentDefinition
    Set oCD = oRefDoc.ComponentDefinition
    
    ' Get the referenced document feature collection
    Dim oFeatures As PartFeatures
    Set oFeatures = oCD.Features
    
    Dim oFeature As PartFeature
    
    '  Get the referenced document feature count
    Dim oFeatureCount As Integer
    oFeatureCount = oFeatures.Count
    
    '  Get the referenced document hole feature collection
    Dim oHoles As HoleFeatures
    Set oHoles = oFeatures.HoleFeatures
    
    '  Get the referenced document chamfer feature collection
    Dim oChamfers As ChamferFeatures
    Set oChamfers = oFeatures.ChamferFeatures
    'Dim oChamferCount As Integer = oChamfers.Count
    oChamferCount = oChamfers.Count
    
    Dim oEdge As Edge
    Dim oChamferFeature As ChamferFeature
    For Each oChamferFeature In oChamfers
       ' move the feature under the End of Part node to get the chamfered edges.
       Call oChamferFeature.SetEndOfPart(True)
       
       MsgBox oChamferFeature.Name & " has " & oChamferFeature.Definition.ChamferedEdges.Count & " chamfered edges."
       
       For Each oEdge In oChamferFeature.Definition.ChamferedEdges
            oRefDoc.SelectSet.Select oEdge
       Next
       Call oChamferFeature.SetEndOfPart(False)
    Next
    
   ' MsgBox (oChamferCount)
End Sub

 

Hope it helps.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 5 of 13

Anonymous
Not applicable

Hi @YuhanZhang

 

I receive a run-time error '438'

Object doesn't support this property or method

 

On this line:

For Each oEdge In oChamferFeature.Definition.ChamferedEdges

0 Likes
Message 6 of 13

Anonymous
Not applicable

I think it maybe should be:

For Each oEdge In oChamferFeature.Definition.Parent.ChamferedEdges

 

One problem I have with this code is the SetEndOfPart assignment. If my chamfer is in the middle of my model tree, then I lose all features after it. Is there a method to return to the previous position instead?

0 Likes
Message 7 of 13

YuhanZhang
Autodesk
Autodesk
Accepted solution

The oChamferFeature.Definition.Parent.ChamferedEdges works too in this case, but it is actually the ChamferFeature.ChamferedEdges and it is hidden now, so I recommend to use the oChamferFeature.Definition.ChamferedEdges.

 

I added some lines to set the EndofPart node:

Sub GetChamferedEdgesCount()
    Dim oRefDoc As PartDocument
    Set oRefDoc = ThisApplication.ActiveDocument

    ' Get the referenced document component definition
    Dim oCD As PartComponentDefinition
    Set oCD = oRefDoc.ComponentDefinition
    
    ' get the original position of End of Part node.
    Dim oBefore As Object, oAfter As Object
    oCD.GetEndOfPartPosition oAfter, oBefore
    
    ' Get the referenced document feature collection
    Dim oFeatures As PartFeatures
    Set oFeatures = oCD.Features
    
    Dim oFeature As PartFeature
    
    '  Get the referenced document feature count
    Dim oFeatureCount As Integer
    oFeatureCount = oFeatures.Count
    
    '  Get the referenced document hole feature collection
    Dim oHoles As HoleFeatures
    Set oHoles = oFeatures.HoleFeatures
    
    '  Get the referenced document chamfer feature collection
    Dim oChamfers As ChamferFeatures
    Set oChamfers = oFeatures.ChamferFeatures
    'Dim oChamferCount As Integer = oChamfers.Count
    oChamferCount = oChamfers.Count
    
    Dim oEdge As Edge
    Dim oChamferFeature As ChamferFeature
    For Each oChamferFeature In oChamfers
       ' move the feature under the End of Part node to get the chamfered edges.
       Call oChamferFeature.SetEndOfPart(True)
       
       MsgBox oChamferFeature.Name & " has " & oChamferFeature.Definition.ChamferedEdges.Count & " chamfered edges."
       
       For Each oEdge In oChamferFeature.Definition.ChamferedEdges
            oRefDoc.SelectSet.Select oEdge
       Next
       Call oChamferFeature.SetEndOfPart(False)
    Next
    
   ' MsgBox (oChamferCount)
   
   ' restore the position of End of Part node.
    oAfter.SetEndOfPart False
End Sub


If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 8 of 13

Anonymous
Not applicable

two doubts about this solution.

1. If I paste it in the ilogic rule it doesn't work, how would it be adapted to ilogic?

2. To do the same but not only for chamfers, but also for rounding holes, ... Operations in which several entities can be selected at the same time, how would it be done?

 

 

0 Likes
Message 9 of 13

Anonymous
Not applicable

for hole and fillet for example

0 Likes
Message 10 of 13

YuhanZhang
Autodesk
Autodesk

The sample I provided is VBA code which is in VB6 style, while iLogic code is in VB.net style. To convert VBA code to iLogic, for most simple cases you just need to delete the "Set" keyword(which is to assign value to Object-based variable) in the code(some complex may require more edit). You can try it there to delete the "Set"  if it works. 

 

For other features you can also calculate the edges that they use to create them, like what I demonstrated in the VBA code I calculated the ChamferedEdges, for other features you need to find proper properties to calculate the edges. For example the FilletFeature, you can calculate the FilletDefinition.EdgeSetItem and FaceSet and FullRoundSet etc. to calculate the edges.

 

Hope above helps.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 11 of 13

uo9K5H5
Contributor
Contributor

Hello, @YuhanZhang and @Anonymous I am trying to use your code to count every edge that I have selected for Fillet function. I am keep getting an error. Can you take a look in to the code?

  Dim oRefDoc As PartDocument
    oRefDoc = ThisApplication.ActiveDocument

    ' Get the referenced document component definition
    Dim oCD As PartComponentDefinition
    oCD = oRefDoc.ComponentDefinition
    
    ' get the original position of End of Part node.
    Dim oBefore As Object, oAfter As Object
    oCD.GetEndOfPartPosition (oAfter, oBefore)
    
    ' Get the referenced document feature collection
    Dim oFeatures As PartFeatures
    oFeatures = oCD.Features
    
    Dim oFeature As PartFeature
    
    '  Get the referenced document feature count
    Dim oFeatureCount As Integer
    oFeatureCount = oFeatures.Count
    
    '  Get the referenced document hole feature collection
    Dim oHoles As HoleFeatures
    oHoles = oFeatures.HoleFeatures
    
    '  Get the referenced document chamfer feature collection
	'Dim oChamfers As ChamferFeatures
    Dim oFillet As FilletFeatures
    oFillet = oFeatures.FilletFeatures
    'Dim oChamferCount As Integer = oChamfers.Count
    oFilletCount = oFilletFeatures.Count
	
	Dim FilletFeatures = oFeatures.FilletFeatures

	 
    Dim oEdge As Edge
    Dim oFilletFeatures As FilletFeatures
    For Each oFilletFeatures In oFillet
       ' move the feature under the End of Part node to get the chamfered edges.
       Call ofilletFeatures.SetEndOfPart(True)
       
       MsgBox (oFilletFeatures.Name & " has " & oFilletFeatures.Definition.FilletEdges.Count & " chamfered edges.")
       
       For Each oEdge In oFilletFeatures.Definition.FilletEdges
            oRefDoc.SelectSet.Select (oEdge)
       Next
       Call oFilletFeatures.SetEndOfPart(False)
    Next
    
   ' MsgBox (oChamferCount)
   
   ' restore the position of End of Part node.
    oAfter.SetEndOfPart (False)
0 Likes
Message 12 of 13

YuhanZhang
Autodesk
Autodesk

@uo9K5H5  Please try below iLogic code:

Sub Main()
    Dim oRefDoc As PartDocument
    oRefDoc = ThisDoc.Document 

    ' Get the referenced document component definition
    Dim oCD As PartComponentDefinition
    oCD = oRefDoc.ComponentDefinition
    
    ' get the original position of End of Part node.
    Dim oBefore As Object, oAfter As Object
    oCD.GetEndOfPartPosition (oAfter, oBefore)
    
    ' Get the referenced document feature collection
    Dim oFeatures As PartFeatures
    oFeatures = oCD.Features
    
    Dim oFeature As PartFeature
    
    '  Get the referenced document feature count
    Dim oFeatureCount As Integer
    oFeatureCount = oFeatures.Count
       
    '  Get the referenced document chamfer feature collection
    Dim oFilletFeas As  FilletFeatures
    oFilletFeas = oFeatures.FilletFeatures
    Dim oFilletCount As Integer = oFilletFeas.Count
    oFilletCount = oFilletFeas.Count
    
    Dim oEdge As Edge
    Dim oFilletFeature As FilletFeature
    For Each oFilletFeature In oFilletFeas
       ' move the feature under the End of Part node to get the chamfered edges.
       Call oFilletFeature.SetEndOfPart(True)
       oRefDoc.SelectSet.Clear 
	   
	   Dim iEdgeSetCount As Long
	   iEdgeSetCount = oFilletFeature.FilletDefinition.EdgeSetCount 
	   
	   Dim iEdgeCount As Long, iIndex As Long
	   iEdgeCount = 0
	   
	   For iIndex = 1 To iEdgeSetCount
	       iEdgeCount = iEdgeCount + oFilletFeature.FilletDefinition.EdgeSetItem(iIndex).Edges.Count 
	   Next
	   
	   
       MsgBox (oFilletFeature.Name & " has " & iEdgeCount & " fillet edges.",,"Inventor")
       
       For iIndex = 1 To iEdgeSetCount
	       
			

	   	 	Dim iEdgeIndex As Long
			
	   	   For iEdgeIndex = 1 To  oFilletFeature.FilletDefinition.EdgeSetItem(iIndex).Edges.Count 
		   	   Dim oFilletEdge As Inventor.Edge
			   oFilletEdge = oFilletFeature.FilletDefinition.EdgeSetItem(iIndex).Edges(iEdgeIndex)
		   	   oRefDoc.SelectSet.Select(oFilletEdge)
			   
		   Next
		   
	   Next
       MsgBox("Edges were selected!",,"Inventor")
	   
       Call oFilletFeature.SetEndOfPart(False)
	    ' restore the position of End of Part node.
    	oAfter.SetEndOfPart (False)
    Next
End Sub


If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

Message 13 of 13

uo9K5H5
Contributor
Contributor

@YuhanZhang  Thank you. It works like I wanted.

 

 

0 Likes