Sheet Metal, parameters, styles and iLogic

Sheet Metal, parameters, styles and iLogic

fridtjofZM5ME
Collaborator Collaborator
3,618 Views
12 Replies
Message 1 of 13

Sheet Metal, parameters, styles and iLogic

fridtjofZM5ME
Collaborator
Collaborator

In an effort to automate as much as possible, I've recently dived into the world of iLogic without the slightest clue what I'm doing, and through the help of this forum I get a little bit further each time I make an attempt at something new.

 

Today I'm trying to set up an iLogic rule in my Sheet Metal template that modifies the current active style values for BendRadius and kFactor based on my selection of material and thickness. We use four different thicknesses of three different materials, so the code wrote looks like this:

 

MultiValue.SetList("Thickness", 1.25 mm, 1.5 mm, 2.5 mm, 3.0 mm)
BendRadius = 3 mm
UnfoldMethodType=kLinearUnfoldMethod
	If iProperties.Material = "Stainless Steel" And 
		Thickness = 1.25 Then 
		kLinearUnfoldMethod.KFactor = 0.3862 
	ElseIf iProperties.Material = "Stainless Steel" And
		Thickness = 1.5 Then
		kLinearUnfoldMethod.KFactor = 0.3963 
	ElseIf iProperties.Material = "Stainless Steel" And
		Thickness = 2.5 Then
		kLinearUnfoldMethod.KFactor = 0.3862 
	ElseIf iProperties.Material = "Stainless Steel" And
		Thickness = 3 Then
		kLinearUnfoldMethod.KFactor = 0.41385 
	ElseIf iProperties.Material = "Steel" And
		Thickness = 1.5 Then
		kLinearUnfoldMethod.KFactor = 0.40835 
	ElseIf iProperties.Material = "Steel" And
		Thickness = 2.5 Then
		kLinearUnfoldMethod.KFactor = 0.4332 
	ElseIf iProperties.Material = "Steel, Galvanized" And
		Thickness = 1.25 Then
		kLinearUnfoldMethod.KFactor = 0.4363 
	ElseIf iProperties.Material = "Steel, Galvanized" And
		Thickness = 1.5 Then
		kLinearUnfoldMethod.KFactor = 0.421
	End If

 

As of now it doesen't do much other than returning an error message stating that "object variable or "With"-block variable is not defined".

 

I've searched around this forum trying to find out what Inventor recognizes as kFactor in the code through a couple of posts similar to this and I had the code running without error at one point, but it didn't change the default kFactor, nor did it change the value of the BendRadius parameter. It did manage to set a mutivalue for the thickness though.

 

Any help appreciated 🙂

0 Likes
3,619 Views
12 Replies
Replies (12)
Message 2 of 13

marcin_otręba
Advisor
Advisor

try:

 

 

MultiValue.SetList("Thickness", 1.25 mm, 1.5 mm, 2.5 mm, 3.0 mm)
BendRadius = 3 mm
UnfoldMethodType = kLinearUnfoldMethod
Dim sh As SheetMetalComponentDefinition = ThisDoc.Document.componentdefinition
	If iProperties.Material = "Stainless Steel" And 
		(sh.Thickness.Value*10).tostring = "1,25" Then 
		sh.UnfoldMethod.kFactor = 0.3862 
	ElseIf iProperties.Material = "Stainless Steel" And
		(sh.Thickness.Value*10).tostring= "1,5" Then
		sh.UnfoldMethod.kFactor = 0.3963 
	ElseIf iProperties.Material = "Stainless Steel" And
		(sh.Thickness.Value*10).tostring= "2,5" Then
		sh.UnfoldMethod.kFactor = 0.3862 
	ElseIf iProperties.Material = "Stainless Steel" And
		(sh.Thickness.Value*10).tostring= "3" Then
		sh.UnfoldMethod.kFactor = 0.41385 
	ElseIf iProperties.Material = "Steel" And
		(sh.Thickness.Value*10).tostring = "1,5" Then
		sh.UnfoldMethod.kFactor = 0.40835 
	ElseIf iProperties.Material = "Steel" And
		(sh.Thickness.Value*10).tostring = "2,5" Then
		sh.UnfoldMethod.kFactor = 0.4332 
	ElseIf iProperties.Material = "Steel, Galvanized" And
		(sh.Thickness.Value*10).tostring = "1,25" Then
		sh.UnfoldMethod.kFactor= 0.4363 
	ElseIf iProperties.Material = "Steel, Galvanized" And
		(sh.Thickness.Value*10).tostring = "1,5" Then
		sh.UnfoldMethod.kFactor = 0.421
	End If

bu

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 3 of 13

fridtjofZM5ME
Collaborator
Collaborator

Nope, didn't affect the KFactor Value in the style and standard editor. It's still the default 0.440.

0 Likes
Message 4 of 13

marcin_otręba
Advisor
Advisor

this is wrong:

 

iProperties.Material

 charge it to sh.material

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 5 of 13

fridtjofZM5ME
Collaborator
Collaborator

Didn't appear to work either.

 

Skjermbilde.JPG

0 Likes
Message 6 of 13

marcin_otręba
Advisor
Advisor

try this one:

MultiValue.SetList("Thickness", 1.25 mm, 1.5 mm, 2.5 mm, 3.0 mm)
BendRadius = 3 mm
UnfoldMethodType = kLinearUnfoldMethod


Dim sh As SheetMetalComponentDefinition = ThisDoc.Document.componentdefinition
	If ThisDoc.Document.PropertySets(3).Item("Material").Value = "Stainless Steel" And 
		(sh.Thickness.Value*10).ToString = "1,25" Then 
		sh.UnfoldMethod.kFactor = 0.3862 
	ElseIf ThisDoc.Document.PropertySets(3).Item("Material").Value = "Stainless Steel" And
		(sh.Thickness.Value*10).ToString= "1,5" Then
		sh.UnfoldMethod.kFactor = 0.111
	ElseIf ThisDoc.Document.PropertySets(3).Item("Material").Value = "Stainless Steel" And
		(sh.Thickness.Value*10).ToString= "2,5" Then
		sh.UnfoldMethod.kFactor = 0.3862 
	ElseIf ThisDoc.Document.PropertySets(3).Item("Material").Value = "Stainless Steel" And
		(sh.Thickness.Value*10).ToString= "3" Then
		sh.UnfoldMethod.kFactor = 0.41385 
	ElseIf ThisDoc.Document.PropertySets(3).Item("Material").Value = "Steel" And
		(sh.Thickness.Value*10).ToString = "1,5" Then
		sh.UnfoldMethod.kFactor = 0.40835 
	ElseIf ThisDoc.Document.PropertySets(3).Item("Material").Value = "Steel" And
		(sh.Thickness.Value*10).ToString = "2,5" Then
		sh.UnfoldMethod.kFactor = 0.4332 
	ElseIf ThisDoc.Document.PropertySets(3).Item("Material").Value = "Steel, Galvanized" And
		(sh.Thickness.Value*10).ToString = "1,25" Then
		sh.UnfoldMethod.kFactor= 0.4363 
	ElseIf ThisDoc.Document.PropertySets(3).Item("Material").Value = "Steel, Galvanized" And
		(sh.Thickness.Value*10).ToString = "1,5" Then
		sh.UnfoldMethod.kFactor = 0.421
	End If

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 7 of 13

fridtjofZM5ME
Collaborator
Collaborator

It didn't work either. I think we need to tell it specifically to change style parameters in some way. I get the feeling everything we've done so far only applies to parameters in the part. I also need a command to uncheck the "use thickness from style" box for the multivalue to work.

0 Likes
Message 8 of 13

marcin_otręba
Advisor
Advisor

in my file it works.

I also need a command to uncheck the "use thickness from style" box for the multivalue to work. - you don change thickness. - added sh.UseSheetMetalStyleThickness=False

It must run in sheetmetal part.

 

MultiValue.SetList("Thickness", 1.25 mm, 1.5 mm, 2.5 mm, 3.0 mm)
BendRadius = 3 mm
UnfoldMethodType = kLinearUnfoldMethod

Try
Dim sh As SheetMetalComponentDefinition = ThisDoc.Document.componentdefinition
Catch
	MessageBox.Show("sheetmetal part enviroment must be active.", "error")
Return
End Try
sh.UseSheetMetalStyleThickness = False

	If ThisDoc.Document.PropertySets(3).Item("Material").Value = "Stainless Steel" And 
		(sh.Thickness.Value*10).ToString = "1,25" Then 
		sh.UnfoldMethod.kFactor = 0.3862 
	ElseIf ThisDoc.Document.PropertySets(3).Item("Material").Value = "Stainless Steel" And
		(sh.Thickness.Value*10).ToString= "1,5" Then
		sh.UnfoldMethod.kFactor = 0.111
	ElseIf ThisDoc.Document.PropertySets(3).Item("Material").Value = "Stainless Steel" And
		(sh.Thickness.Value*10).ToString= "2,5" Then
		sh.UnfoldMethod.kFactor = 0.3862 
	ElseIf ThisDoc.Document.PropertySets(3).Item("Material").Value = "Stainless Steel" And
		(sh.Thickness.Value*10).ToString= "3" Then
		sh.UnfoldMethod.kFactor = 0.41385 
	ElseIf ThisDoc.Document.PropertySets(3).Item("Material").Value = "Steel" And
		(sh.Thickness.Value*10).ToString = "1,5" Then
		sh.UnfoldMethod.kFactor = 0.40835 
	ElseIf ThisDoc.Document.PropertySets(3).Item("Material").Value = "Steel" And
		(sh.Thickness.Value*10).ToString = "2,5" Then
		sh.UnfoldMethod.kFactor = 0.4332 
	ElseIf ThisDoc.Document.PropertySets(3).Item("Material").Value = "Steel, Galvanized" And
		(sh.Thickness.Value*10).ToString = "1,25" Then
		sh.UnfoldMethod.kFactor= 0.4363 
	ElseIf ThisDoc.Document.PropertySets(3).Item("Material").Value = "Steel, Galvanized" And
		(sh.Thickness.Value*10).ToString = "1,5" Then
		sh.UnfoldMethod.kFactor = 0.421
	End If

What is more i think there is better approach if you create style for each combination.

 

Could you share any of your files to test it ?

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 9 of 13

WCrihfield
Mentor
Mentor

I have to agree with @marcin_otręba last comment.  That's exactly what the Sheet Metal Defaults (Sheet Metal Rules) are for.  It really is best practice to create a different Sheet Metal Rule Style for each combination of Material & Thickness you use.

Are you using that rule above to follow after using a Form to change Material &/or Thickness, etc?

If so, you could probably avoid the Form altogether and simply select a different Sheet Metal Rule Style from the drop-down list under Sheet Metal Defaults.  That will change the models settings to match all of the settings of the Sheet Metal Rule Style.

They are fairly quick & easy to create in your Styles Manager dialog.

Then if you still wanted to automate the process with a custom Form, in which you specify a different Material or Thickness, you would then just have the iLogic rule change the model's default Sheet Metal Rule Style.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 10 of 13

fridtjofZM5ME
Collaborator
Collaborator

I guess I can agree with you both in that using a style definition for each of the cases migth be a better way. As for your presumption of this code following a form, it doesen't, but my plan was to figure out how to make that happen afterwards and insert it into the code above the current.

 

The way I ideally would have this work, is so that when I double click the the "My_template_Sheet_Metal.ipt" from the home screen in Inventor to create a new file (or if I click "convert to sheet metal" for that matter, but first things first), some dialogue box immediately pops up and prompts me to make a selection of material and thickness, and based on the combination of these will activate the apropriate style.

0 Likes
Message 11 of 13

marcin_otręba
Advisor
Advisor

you can start from this:

 

Dim doc As PartDocument
 doc = ThisApplication.ActiveDocument
Dim sh As SheetMetalComponentDefinition
 sh = doc.ComponentDefinition
Dim shd As SheetMetalStyle
For Each shd In sh.SheetMetalStyles
' on this loop you can input all styles inside your combobox or listbox shd.Name
Next
Dim lasset
For Each lasset In doc.Assets
If lasset.Type = 50448896 Then ' material assets
' on this loop you can input all materials from document inside your combobox or listbox lasset.displayname
End If
Next
' after choosing all in form after button click you can:

shd.SheetMetalStyles.Item("style name from combo").Activate
shd.UseSheetMetalStyleMaterial = False


Dim localAsset As MaterialAsset

localAsset = doc.Assets.Item("material name from combo")
odoc.ActiveMaterial = localAsset

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

Message 12 of 13

fridtjofZM5ME
Collaborator
Collaborator

This is what I've come up with, and it appears to work as intended so far. I created a style for each possible combo of thickness and material, then created two multivalue text parameter for thickness and material, placed them in a form, and created an iLogic rule triggered by "New Document" that runs the form and sets the active style based on the selection using plain "and-or-not"-logic.

 

This might be a bit of a cumbersome way to write code, but my understanding of code writing is very limited, so this is currently about as far as my wits go regarding this. (The first part of the rule I've copy/pasted from another post where a guy had problems with the form running on placement into assembly, so I just included it to not repeat the mistakes of others.)

 

I see that "Dim"-command a lot, what does it do exactly?

0 Likes
Message 13 of 13

marcin_otręba
Advisor
Advisor

Dim - is variable declaration.

I think ilogic will not be good choise for what you want to accomplish. You need to create parameters to fill comboboxes (in my opinion you should have only one with name of sheet metal style), this will have inpact if you will decide to use parametric modelling.

I have some of my codes working in simmilar way, but it was made in vbs and add-in.There is no need to have additional parameters. It runs when new file is started, user can choose file type, after that if sheetmetal is chosen code reads all sheetmetastyles to combobox. this way it is secured that you will not chose anythink what do not exist.

if you still will go with ilogic check this :

 

https://www.cadlinecommunity.co.uk/hc/en-us/articles/207282775-Inventor-2016-iLogic-Create-Multivalu...

 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes