Help with ilogic to check if all bends in sheet metal are 90 deg?

Help with ilogic to check if all bends in sheet metal are 90 deg?

Charlies_3D_T
Advocate Advocate
1,957 Views
17 Replies
Message 1 of 18

Help with ilogic to check if all bends in sheet metal are 90 deg?

Charlies_3D_T
Advocate
Advocate

Hello,

 

I want to write a ilogic to determin if all bends are 90 degrees and if they are i get an okay. If they are not i want the ilogic rule to change the bend rule from deduction to kfactor. 

 

But i don't know how i can get the bend angles and how i can change the bend rule.

 

Thank you!

 

0 Likes
Accepted solutions (2)
1,958 Views
17 Replies
Replies (17)
Message 2 of 18

JamieVJohnson2
Collaborator
Collaborator

Start up top, you need the sheet metal style in use for the part file.

First you start at the PartComponentDefinition, and realize that a Sheet Metal part inherits that but calls it the SheetMetalComponentDefinition.  This is acquired like so:

dim smcd as SheetMetalComponentDefinition = thisapplication.activedocument.definition 'assuming active document is a sheet metal part file

Next you want the style in use that holds the properties:

dim smStyle as SheetMetalStyle = smcd.ActiveSheetMetalStyle

The style contains the properties for all the Bend data defaults.

 

Next you need to verify if the designer, used the default bends or overwrote them per bend feature.

smcd.Features is the list of all features in the part file.  They are browken down into feature types of their own collections so smcd.Features.BendPartFeatures (which may be the standard bend and not the sheet metal bend or both, please verify), or you can just brows the list of features and ask each one it's type:

 

for each feat as PartFeature in smcd.Features

if feat.type = kBendFeatureObject then

     'you now have a bend feature

     dim oBendFeature as BendFeature

     dim oBendDef as BendDefinition = oBendFeatures.Definition

     dim bRad object = oBendDef.BendRadius

end if

Next

 

From there you should be able to accomplish your goals.

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes
Message 3 of 18

Charlies_3D_T
Advocate
Advocate

@JamieVJohnson2

 

I'm sorry but i don't fully understand how you know that there are only 90 degree bends and that it if they are only 90 degrees uses the bend deduction and if there is one bend that is not 90 degrees that it changes to the K factor.

 

Also i get an error when i verify your code. 

 

Btw thank you for your time!

 

SyntaxEditor Code Snippet

Dim smcd As SheetMetalComponentDefinition = ThisApplication.ActiveDocument.definition 'assuming active document is a sheet metal part file
Dim smStyle As SheetMetalStyle = smcd.ActiveSheetMetalStyle

For Each feat As PartFeature In smcd.Features

If feat.Type = kBendFeatureObject Then

     'you now have a bend feature

     Dim oBendFeature As BendFeature

     Dim oBendDef As BendDefinition = oBendFeatures.Definition

     Dim bRad Object = oBendDef.BendRadius

End If

Next

 

 

0 Likes
Message 4 of 18

chandra.shekar.g
Autodesk Support
Autodesk Support

@Charlies_3D_T,

 

Can you please provide part files which are having 90 degree and not 90 degree bend to investigate? Please make sure that files are non confidential.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 5 of 18

lmc.engineering
Advocate
Advocate
Accepted solution

Hi @Charlies_3D_T

 

This code below will do what you are after.

 

Please note you must create your different sheet metal styles in your template document in order for you to switch between a kFactor style and an alternative style.

 

SyntaxEditor Code Snippet

Sub Main()
'Define the document
Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument
Dim oCompDef As SheetMetalComponentDefinition
oCompDef = oDoc.ComponentDefinition

'Find angle of each bend
Dim i As Integer = 0
Dim oBend As FlatBendResult
For Each oBend In oCompDef.FlatPattern.FlatBendResults
	x = oBend.Angle 
	AngleCheck = Round(x / PI * 180, 6)
		'Add check for all angles not 90 degrees
		If Not AngleCheck = 90 Then
			i += 1
		End If
Next

Dim sSheetMetalStyle As String
'''Check condition for setting sheet metal style
If i > 0 Then
sSheetMetalStyle = "kFactorStyle" 'CHANGE THIS TO MATCH YOUR STYLES
Else
sSheetMetalStyle = "OtherStyle" 'CHANGE THIS TO MATCH YOUR STYLES
End If

oCompDef.SheetMetalStyles.Item(sSheetMetalStyle).Activate
End Sub
Message 6 of 18

Charlies_3D_T
Advocate
Advocate

@lmc.engineering

 

 

Thank you!

 

But i don't have succes. In attachment is a printscreen of my Style and Standard. 

 

Do i need to add it like below? 

If i do that i get an error. 

 

Sub Main()

'Define the document
Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument
Dim oCompDef As SheetMetalComponentDefinition
oCompDef = oDoc.ComponentDefinition

'Find angle of each bend
Dim i As Integer = 0
Dim oBend As FlatBendResult
For Each oBend In oCompDef.FlatPattern.FlatBendResults
x = oBend.Angle
AngleCheck = Round(x / PI * 180, 6)
'Add check for all angles not 90 degrees
If Not AngleCheck = 90 Then
i += 1
End If
Next


Dim sSheetMetalStyle As String
'''Check condition for setting sheet metal style
If i > 0 Then
sSheetMetalStyle = "Charlies3DT KFactor" 'CHANGE THIS TO MATCH YOUR STYLES
Else
sSheetMetalStyle = "BendCompensation" 'CHANGE THIS TO MATCH YOUR STYLES
End If

oCompDef.SheetMetalStyles.Item(sSheetMetalStyle).Activate
End Sub

0 Likes
Message 7 of 18

Charlies_3D_T
Advocate
Advocate

@lmc.engineering

 

Found it!

 

Thank you! You helped me to prevent faults now!

Message 8 of 18

JamieVJohnson2
Collaborator
Collaborator

What does the error state?  Where is it taking place?  (I use msgbox("hi") and move it around to find errors in code that doesn't 'stop' at the error).

 

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes
Message 9 of 18

lmc.engineering
Advocate
Advocate

That should be correct, assuming you have Sheet metal styles called "Charlies3DT KFactor" and"BendCompensation" set-up in your document.

 

Note my styles are "Default" and Default_mm"

 

Capture.PNG

0 Likes
Message 10 of 18

Charlies_3D_T
Advocate
Advocate

@lmc.engineering

 

Could you help me out with one more thing?

 

Now i need to activate it by hand. Is there a ilogic that i can tell it to activate it when there is a flat pattern produced? 

0 Likes
Message 11 of 18

JamieVJohnson2
Collaborator
Collaborator

SheetMetalStyles have a .Activate command.  Feature...Definition.SheetMetalRule can swap different SheetMetalStyles

 

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes
Message 12 of 18

lmc.engineering
Advocate
Advocate

Unfortunately it's not possible for the rule to monitor when a flat pattern has been made. 

 

What you can do though is use this rule to create the flat pattern, then the checks will run when created. You can save this rule in your template file, so any new sheet metal parts will contain this rule.

 

Try this;

 

SyntaxEditor Code Snippet

Sub Main()
'Define the document
Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument
Dim oCompDef As SheetMetalComponentDefinition
oCompDef = oDoc.ComponentDefinition

'Check For flat pattern, if none, create one
If oCompDef.HasFlatPattern = False Then
	oCompDef.Unfold
	CheckBendAngles(oCompDef)
	bExitEdit = True
Else
	CheckBendAngles(oCompDef)
	bExitEdit = False
End If

If bExitEdit = True Then oCompDef.FlatPattern.ExitEdit

End Sub

Function CheckBendAngles(oCompDef As Object)
	'Find angle of each bend
Dim i As Integer = 0
Dim oBend As FlatBendResult
For Each oBend In oCompDef.FlatPattern.FlatBendResults
	x = oBend.Angle 
	AngleCheck = Round(x / PI * 180, 6)
		'Add check for all angles not 90 degrees
		If Not AngleCheck = 90 Then
			i += 1
		End If
Next

Dim sSheetMetalStyle As String
'''Check condition for setting sheet metal style
If i > 0 Then
sSheetMetalStyle = "Default" 'CHANGE THIS TO MATCH YOUR STYLES
Else
sSheetMetalStyle = "Default_mm" 'CHANGE THIS TO MATCH YOUR STYLES
End If

oCompDef.SheetMetalStyles.Item(sSheetMetalStyle).Activate
Return Nothing
End Function

 

0 Likes
Message 13 of 18

Charlies_3D_T
Advocate
Advocate

@lmc.engineering 

 

Hello,

 

I have found a problem with this ilogic. And that is that it changes the rule but not the sheet metal unfold rule... 

 

How can i fix this? 

0 Likes
Message 14 of 18

lmc.engineering
Advocate
Advocate

Hi @Charlies_3D_T 

 

You can get hold of the unfold method and set it using the following:

 

Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument
Dim oCompDef As SheetMetalComponentDefinition
oCompDef = oDoc.ComponentDefinition

Dim oUnfoldMethod As UnfoldMethod
For Each oUnfoldMethod In oCompDef.UnfoldMethods
x = oUnfoldMethod.Name
	If x = "YourUnfoldRuleName" Then oCompDef.UnfoldMethod = oUnfoldMethod
Next

 

0 Likes
Message 15 of 18

Charlies_3D_T
Advocate
Advocate

@lmc.engineering 

 

Thank you!

 

I have a last question. i want to make a rule that when i change the material to for example S235JR the unfold rule changes to Charlies3DT S235JR.

 

How can i do that?

 

I tried to change the ilogic above but no succes.

 

Thank you for your time!

 

0 Likes
Message 16 of 18

lmc.engineering
Advocate
Advocate
Accepted solution

Hi @Charlies_3D_T 

 

You can do this with the following:

Sub Main()
Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument
Dim oCompDef As SheetMetalComponentDefinition
oCompDef = oDoc.ComponentDefinition

Dim sMaterial As String = oDoc.ActiveMaterial.DisplayName
Dim sUnfoldPt1 As String = "Charlies3DT "
Dim sUnfoldStr As String = sUnfoldPt1 & sMaterial

Dim i As Integer = 0
Dim j As Integer = 0
Dim sUnfoldName As String

Dim oUnfoldMethod As UnfoldMethod
	For Each oUnfoldMethod In oCompDef.UnfoldMethods
	sUnfoldName = oUnfoldMethod.Name
		If sUnfoldName = sUnfoldStr Then 
			oCompDef.UnfoldMethod = oUnfoldMethod
			j+=1
		End If
	i+=1
	Next
	
	iCheckIfFound = i + j 'If this is zero, then the unfold style has not been found
	If i - iCheckIfFound = 0 Then MessageBox.Show("Cannot find the unfold style with the name " & sUnfoldStr _
		& vbLf & vblf & "Please check if it exists, if not please create it first", "Title")
End Sub

I added a check in there to test if the style exists. That should stop you progressing with the incorrect unfold rules.

0 Likes
Message 17 of 18

Charlies_3D_T
Advocate
Advocate

@lmc.engineering 

 

Thank you!

 

I will adjust it a bit because i want to add multiple material for the same rule.

 

If i don't find it i will let you know!

0 Likes
Message 18 of 18

lmc.engineering
Advocate
Advocate

No Problem, happy to help.

 

If you're wanting multiple materials on each rule, I might suggest a 'select case' on the sMaterial string, and use each case to fill in the correct 'sUnfoldStr'. Happy to assist if you get stuck.

 

Regards

0 Likes