03-10-2021
08:36 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
03-10-2021
08:36 PM
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