Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create iterations that fixes errors VBA

Status
Not open for further replies.

Costeldvd

Automotive
Mar 12, 2018
5
RO
Hello,

I come with a new set of questions. I want to create a extrapol with a given value(ex: 50). If the extrapol creates an error the it should decrese the value with 1 until the operation has no errors.

In this moment i have a structure like this:

___________
Dim j As Integer
For j = 1 To SearchSelection.Count

Set hybridShapeSurfaceExplicit2 = SearchSelection.Item2(j).Value
Set reference2 = part1.CreateReferenceFromObject(hybridShapeSurfaceExplicit2)
Set hybridShapeBoundary2 = hybridShapeFactory1.AddNewBoundaryOfSurface(reference2)
Set hybridBody2 = hybridBodies2.Item("Complete Boundary UNTRIM")
hybridBody2.AppendHybridShape hybridShapeBoundary2
part1.InWorkObject = hybridShapeBoundary2
Dim hybridBodies1 As HybridBodies
Set hybridBodies1 = part1.HybridBodies
Dim hybridShapes2 As HybridShapes
Set hybridShapes2 = hybridBody2.HybridShapes
Dim parameters1 As Parameters
Set parameters1 = part1.Parameters

Dim a As Integer
a = 50

Set reference7 = part1.CreateReferenceFromObject(hybridShapeBoundary2)
Dim hybridShapeExtrapol1 As HybridShapeExtrapol
Set hybridShapeExtrapol1 = hybridShapeFactory1.AddNewExtrapolLength(reference7, reference2, a)
hybridShapeExtrapol1.ContinuityType = 1
hybridShapeExtrapol1.BorderType = 1
hybridShapeExtrapol1.LimitType = 0
hybridShapeExtrapol1.SetAssemble True
hybridShapeExtrapol1.PropagationMode = 0
hybridShapeExtrapol1.ExtendEdgesMode = False
hybridShapeExtrapol1.ConstantLengthMode = False
Set hybridBody3 = hybridBodies1.Item("Untrim Extrapolated")
hybridBody3.AppendHybridShape hybridShapeExtrapol1
part1.InWorkObject = hybridShapeExtrapol1

part1.Update

On Error Resume Next
If Err.Number <> 0 Then
a = a - 1
Else
End If
Next

But i do not see a change in value even if the extrapol has an error.
Please help!



 
Replies continue below

Recommended for you

You'll have to include the Update method in a loop something like this
- create the extrapol;
- append it;
- now create the loop: inside the loop do the update and if the update fails EDIT the extrapol (do not decrease the "a" as it makes no sense). I prefer a do-while loop for this kind of scenarios.
- exit the loop when err.number <>0

later edit: careful with On error resume next. You have to use the On error goto 0 clause to reset it.
Calin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top