For statement issue processing Solid Bodies

For statement issue processing Solid Bodies

brianA32ZM
Advocate Advocate
248 Views
3 Replies
Message 1 of 4

For statement issue processing Solid Bodies

brianA32ZM
Advocate
Advocate

Hello, I am attempting to navigate through the solid bodies in a part to set each body's sheet metal style. The body names are contained in a list named oBodynames. The code matches a body name to a surface body and then changes the sheet metal style. I run into an issue in the code after it processes the first style change. From what I can tell the For statement loses its definition and fails to process the rest of the Bodies.  

 

For Each oBody As SurfaceBody In oBodies
	For Each oBodyname As SurfaceBody In oBodyNames
		If oBody.Name = oBodyName
			Try
				oCompDef.SetBodySheetMetalStyle(oBody, oStyle)
				Logger.Info("********Processed " + oBodyName)
			Catch
				Logger.Info("!!!!!!!!!!!Failed!! " + oBodyName)
			End Try
			Exit For
		End If
		Logger.Info("+++++++++ NOT Found " + oBodyName)
	Next
Next

 

0 Likes
249 Views
3 Replies
Replies (3)
Message 2 of 4

JelteDeJong
Mentor
Mentor

I can't test your code but there are some strange things there. I don't understand why it works at all. this line should throw an exception.

For Each oBodyname As SurfaceBody In oBodyNames

If I understand correctly oBodyNames is a list of strings. And here the items in the list are cast to SurfaceBody objects. That is impossible.

Maybe this works better for you:

For Each oBody As SurfaceBody In oBodies
	If (oBodyNames.Contains(oBody.Name)) Then

		' oCompDef.SetBodySheetMetalStyle(oBody, oStyle)
		logger.Info("********Processed " & oBody.Name)
	Else
		logger.Info("+++++++++ NOT Found " & oBody.Name)
	End If
Next

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 4

brianA32ZM
Advocate
Advocate

Thank you!

Sorry, line 2 should have been:  For Each oBodyname  In oBodyNames. 

The workflow was to place bodies with common styles into list, oBodyNames. Then send the list and oStyle to the sub rule listed below. I am trying to avoid sending each individual body (about 60bodies) to be processed one at time to the sub rule.  

 

 

For Each oBody As SurfaceBody In oBodies
	For Each oBodyname In oBodyNames
		If oBody.Name = oBodyName
			Try
				oCompDef.SetBodySheetMetalStyle(oBody, oStyle)
				Logger.Info("********Processed " + oBodyName)
			Catch
				Logger.Info("!!!!!!!!!!!Failed!! " + oBodyName)
			End Try
			Exit For
		End If
		Logger.Info("+++++++++ NOT Found " + oBodyName)
	Next
Next

 

 

 

0 Likes
Message 4 of 4

brianA32ZM
Advocate
Advocate

I had to look at this problem differently, but I think I have the solution.

The thing I do not understand is that I could not use oBody. Instead, I had to use oCompDef.SurfaceBodies.Item(index) or the code would process the first Style change and stop. Did it consume oBody and leave it's value blank? 

JelteDeJong,  thank you again for your help!

	Sub Option_Material(oCompDef, oOccs)

		Dim oBodies As SurfaceBodies = oCompDef.SurfaceBodies
		Dim oBody As SurfaceBody
		For index As Integer = 1 To oBodies.Count
		'oBody = oBodies.Item(index)

			'Select Case oBody.Name
Select Case oCompDef.SurfaceBodies.Item(index)'oBody.Name '[Body Group 1 --------------------------------------- Case "Body1", _ "Body2" oStyle = "7 GA 304 STAINLESS STEEL" Call BodyMaterial(oBody, oCompDef, oStyle, index) '] End Select End Sub Sub BodyMaterial(oBody, oCompDef, Style, index) oStyle = oCompDef.SheetMetalStyles.Item(oStyle) 'If Not oCompDef.GetBodySheetMetalStyle(oBody).name = oStyle.name If Not oCompDef.GetBodySheetMetalStyle(oCompDef.SurfaceBodies.Item(index)).name = oStyle.name Try 'oCompDef.SetBodySheetMetalStyle(oCompDef.SurfaceBodies.Item(oBody, oStyle)
oCompDef.SetBodySheetMetalStyle(oCompDef.SurfaceBodies.Item(oCompDef.SurfaceBodies.Item(index), oStyle) 'Logger.Info("********Processed " + oBody.name)
Logger.Info("********Processed " + oCompDef.SurfaceBodies.Item(index).Name'oBody.name)
Catch 'Logger.Info("!!!!!!!!!!!Failed!! " + oBody.name)
Logger.Info("!!!!!!!!!!!Failed!! " + oCompDef.SurfaceBodies.Item(index).Name)
End Try End If End Sub

 

0 Likes