How to catch exceptions caused by geometrically impossible features created by iLogic / vb?

How to catch exceptions caused by geometrically impossible features created by iLogic / vb?

FxRod
Enthusiast Enthusiast
400 Views
4 Replies
Message 1 of 5

How to catch exceptions caused by geometrically impossible features created by iLogic / vb?

FxRod
Enthusiast
Enthusiast

Hi, I'm looking for a solution to catch exceptions occurring during feature creation.
Example:
My script creates a sketch in a part and uses that to create a cut extrusion. The data for the geometry comes from an external spreadsheet. When the data is correct, the sketch lies on a face of the part body and extrudes into the part, so everything is fine. But when the data is bad, it may happen that the sketch lies outside the part faces, so a cut is impossible and the extrudefeature fails.

... bad example because it doesn't cause the behavior I wanted to show. New example, which really shows the error:

The script tries to create a simple fillet (Fillets.AddSimple) on an edge with a much too big radius, which makes the fillet creation geometrically impossible. This causes an exception and stops the rule execution.

	Try
		Dim oFillet As FilletFeature = oCompDef.Features.FilletFeatures.AddSimple(oEdgeCollection, 50)
	Catch
	End Try

 

Even if I put the creation of the feature (extrude, fillet etc) into a try-catch-block, it still causes the script to crash with an exception. What I want to achieve is that I can output an error message and the script continues without creating the feature, or maybe creates a feature with a healtproblem but doesn't crash.

Is that possible? If it is: how?

0 Likes
Accepted solutions (1)
401 Views
4 Replies
Replies (4)
Message 2 of 5

Curtis_Waguespack
Consultant
Consultant

Hi @FxRod 

 

Attached is an Inventor 2022 example that creates a sketch outside the solid geometry of the part and then extrudes it as a cut, thereby cutting nothing. This creates the feature with errors, but does not create an error in the code or a crash.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

0 Likes
Message 3 of 5

FxRod
Enthusiast
Enthusiast

Weird, that's exactly the workflow I have in my code. Maybe I remembered something false and the problem appears only on some feature types. Now try this: I added a fillet, which has a way too big radius. That causes an exception, although it is in a Try-Catch-Block:

 

    Dim oPartDoc As PartDocument
    oPartDoc = ThisApplication.ActiveDocument
                    
    ' a reference to the component definition.
    Dim oCompDef As PartComponentDefinition
    oCompDef = oPartDoc.ComponentDefinition    
   
    ' a reference to the transient geometry object.
    Dim oTransGeom As TransientGeometry
    oTransGeom = ThisApplication.TransientGeometry   

    Dim oExtrude As ExtrudeFeature
    oExtrude = oCompDef.Features.ExtrudeFeatures.Item(1)
                        
    ' Get the top face of the extrusion to use for creating the new sketch.
    Dim oFrontFace As Face
    oFrontFace = oExtrude.StartFaces.Item(1)
	
	
	Dim oEdgeCollection As EdgeCollection = ThisApplication.TransientObjects.CreateEdgeCollection
	For Each oEdge As Edge In oFrontFace.Edges
		oEdgeCollection.Add(oEdge)
	Next
	Try
		Dim oFillet As FilletFeature = oCompDef.Features.FilletFeatures.AddSimple(oEdgeCollection, 50)
	Catch
	End Try
		
    
    ' Create a new sketch on this face, but use the method that allows you to
    ' control the orientation and orgin of the new sketch.
    oSketch = oCompDef.Sketches.AddWithOrientation(oFrontFace, _
                    oCompDef.WorkAxes.Item(1), True, True, oCompDef.WorkPoints(1))
                    

    Dim oCorner As Point2d
    oCorner = oSketch.ModelToSketchSpace(oTransGeom.CreatePoint(0.5, 0.5, 0))
   
    oRectangleLines = oSketch.SketchLines.AddAsTwoPointRectangle( _
                oCorner, oTransGeom.CreatePoint2d(oCorner.X + 3, oCorner.Y + 2))
                
    ' Create a profile.
    oProfile = oSketch.Profiles.AddForSolid
    
    ' Create a pocket .25 cm deep.
    oExtrudeDef = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, kCutOperation)
    Call oExtrudeDef.SetDistanceExtent(1, kNegativeExtentDirection)
    oExtrude = oCompDef.Features.ExtrudeFeatures.Add(oExtrudeDef)





0 Likes
Message 4 of 5

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @FxRod 

 

It's the sketch that is failing, so I would catch there error there and bail out ( exit sub) . See example below.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

    Dim oPartDoc As PartDocument
    oPartDoc = ThisApplication.ActiveDocument
                    
    ' a reference to the component definition.
    Dim oCompDef As PartComponentDefinition
    oCompDef = oPartDoc.ComponentDefinition    
   
    ' a reference to the transient geometry object.
    Dim oTransGeom As TransientGeometry
    oTransGeom = ThisApplication.TransientGeometry   

    Dim oExtrude As ExtrudeFeature
    oExtrude = oCompDef.Features.ExtrudeFeatures.Item(1)
                        
    ' Get the top face of the extrusion to use for creating the new sketch.
    Dim oFrontFace As Face
    oFrontFace = oExtrude.StartFaces.Item(1)
	
	
	Dim oEdgeCollection As EdgeCollection = ThisApplication.TransientObjects.CreateEdgeCollection
	For Each oEdge As Edge In oFrontFace.Edges
		oEdgeCollection.Add(oEdge)
	Next
	
	Dim oFillet As FilletFeature = oCompDef.Features.FilletFeatures.AddSimple(oEdgeCollection, 50)

    
    ' Create a new sketch on this face, but use the method that allows you to
    ' control the orientation and orgin of the new sketch.
	Try
    oSketch = oCompDef.Sketches.AddWithOrientation(oFrontFace, _
                    oCompDef.WorkAxes.Item(1), True, True, oCompDef.WorkPoints(1))
	Catch
		Exit sub 
	End Try
                    

    Dim oCorner As Point2d
    oCorner = oSketch.ModelToSketchSpace(oTransGeom.CreatePoint(0.5, 0.5, 0))
   
    oRectangleLines = oSketch.SketchLines.AddAsTwoPointRectangle( _
                oCorner, oTransGeom.CreatePoint2d(oCorner.X + 3, oCorner.Y + 2))
                
    ' Create a profile.
    oProfile = oSketch.Profiles.AddForSolid
    
    ' Create a pocket .25 cm deep.
    oExtrudeDef = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, kCutOperation)
    Call oExtrudeDef.SetDistanceExtent(1, kNegativeExtentDirection)
    oExtrude = oCompDef.Features.ExtrudeFeatures.Add(oExtrudeDef)

 

EESignature

0 Likes
Message 5 of 5

FxRod
Enthusiast
Enthusiast

Aaaaah now I got it. The same occurs, when I cut the rest of the rule after the fillet (so only the fillet is created, which runs without errors) and run the rule a second time: The Startfaces.Item(1) is impossible in the second run.

 

So I just caught the errors in the wrong place and have to check where the consequences of the first error cause further errors, and catch or avoid these also.

 

Thank you!

0 Likes