Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Length of extrusion or sweep

donaldleigh
Advocate

Length of extrusion or sweep

donaldleigh
Advocate
Advocate

Evening all

 

I have 2 rules, one returns the length of the 1st feature if its an extrude "Length Extrude" and the other returns the length of a sweep, the browser name must be called "Sweep1", This rule is called "Length Sweep". Both these rules work well.

 

What I an trying to do is to have another rule like below.

 

If (1st feature if its an extrude) Then

       Run rule "Length Extrude"

Else if 1st feature is a sweep and called "Sweep1" Then

      Run Rule "Length Sweep"

Else

End If

 

Any help would be great

0 Likes
Reply
540 Views
4 Replies
Replies (4)

matt_jlt
Collaborator
Collaborator

Try this

 

' Check document is a part / a document is open
If ThisApplication.Documents.VisibleDocuments.Count = 0 Or ThisApplication.ActiveEditDocument.DocumentType <> Inventor.DocumentTypeEnum.kPartDocumentObject Then
	MessageBox.Show("A part document must be open")
End If

' Get active part document
Dim oDoc As Inventor.PartDocument = ThisApplication.ActiveDocument

' Get part component definition
Dim oCompDef As Inventor.PartComponentDefinition = oDoc.ComponentDefinition

' Check there are features before accessing them
If oCompDef.Features.Count = 0 Then
	MessageBox.Show("There are no features in this part")
End If

' Check the first feature type
Select Case oCompDef.Features(1).Type ' Collection is not zero based so use 1 to get the first item
	Case Inventor.ObjectTypeEnum.kExtrudeFeatureObject
		MessageBox.Show("Extrude Feature")
		' Run extrude rule
		'iLogicVb.RunRule("ruleName")
	Case Inventor.ObjectTypeEnum.kSweepFeatureObject
		MessageBox.Show("Sweep Feature")	
		' Run sweep rile
		'iLogicVb.RunRule("ruleName")

End Select 

 

0 Likes

donaldleigh
Advocate
Advocate

Hi @matt_jlt

 

Thanks for the reply

 

Just had a quick look and it looks great. Will have more of a test next week.

 

Cheers

 

0 Likes

donaldleigh
Advocate
Advocate

Hi @matt_jlt 

 

The code you provided works great but, (now the fun part to explain). When this rule is fired in a part that is not opened, as only an assembly will be open, I have an error. How do I change the start of this code so its run at the part level from an assembly. This code is also set up as an external rule.

 

 

 

 

iLogicVb.UpdateWhenDone = True

' Check document is a part / a document is open
If ThisApplication.Documents.VisibleDocuments.Count = 0 Or ThisApplication.ActiveEditDocument.DocumentType <> Inventor.DocumentTypeEnum.kPartDocumentObject Then
	MessageBox.Show("A part document must be open")
End If

' Get active part document
Dim oDoc As Inventor.PartDocument = ThisApplication.ActiveDocument
'oDoc = ThisApplication.ActiveDocument

' Get part component definition
Dim oCompDef As Inventor.PartComponentDefinition = oDoc.ComponentDefinition

' Check there are features before accessing them
If oCompDef.Features.Count = 0 Then
	MessageBox.Show("There are no features in this part")
End If

If oCompDef.Features(1).Type = Inventor.ObjectTypeEnum.kSweepFeatureObject Then
	iLogicVb.RunExternalRule("Length Sweep")
Else
	iLogicVb.RunExternalRule("Length - Rev 1")
End If
Return

' Check the first feature type
Select Case oCompDef.Features(1).Type ' Collection is not zero based so use 1 to get the first item
	Case Inventor.ObjectTypeEnum.kExtrudeFeatureObject
		'MessageBox.Show("Extrude Feature")
		'Run extrude rule
		iLogicVb.RunExternalRule("Length - Rev 1")
	Case Inventor.ObjectTypeEnum.kSweepFeatureObject
		'MessageBox.Show("Sweep Feature")	
		'Run sweep rile
		iLogicVb.RunExternalRule("Length Sweep")
End Select 

 

0 Likes

donaldleigh
Advocate
Advocate

@matt_jlt 

 

Got it to work now. Thanks anyway

0 Likes