Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Change sheet metal rule on a solid body with iLogic

62 REPLIES 62
SOLVED
Reply
Message 1 of 63
Anonymous
4478 Views, 62 Replies

Change sheet metal rule on a solid body with iLogic

Hello ,

 

Does anyone knows, if it is possible to set the sheet metal rule for a solid body in a Multi-body sheet metal?

You can set a different sheet metal rule for each solid body. So is it possible with ilogic to create a rule,

if this parameter = 5mm, then set sheet metal rule for a specific solid body? So, when the parameter change to

another value, you don't have to reset manualy the sheet metal rule for this specific solid body...

 

thx in advance!

62 REPLIES 62
Message 21 of 63
JBerns
in reply to: JBerns

I have encountered new challenges using a multi-body sheet metal part in the design process. I would welcome assistance from the Community.

 

  • Our sheet metal library contains approximately 20 rules.
  • The multi-body part that I am developing currently is using three of those rules.

 

Challenge 1:

I cannot assign a rule from the library to a solid body if it is not already in use by another solid body.

 

I would like to be able to assign any rule from the library to a solid body.

 

Challenge 2:

I would also like to find a more efficient way to assign the rule to each solid body in the design. Using the code example above would require a For-loop and Select Case for each component. With potential for 6 - 8 parts in a design, that would require a lot of repetitive code. Instead, it would be useful if functions could be called passing it the component name and required sheet metal rule.

 

Challenge 3:

Is it the best practice to change the rule and dimensions in the multi-body part or at the assembly level? Either way, I need to be able to select any rule from the library and assign it to a solid body. This of course will update the part and in turn, the assembly.

 

Thank you for your time and attention. I look forward to your replies.

 

 

Regards,

Jerry

 

-----------------------------------------------------------------------------------------
CAD Administrator
Using Inventor 2022
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
Message 22 of 63
Anonymous
in reply to: JBerns

@JBerns

There are some different formstyles available. When you select the topline of the form, you can select visual style in the appearance section.

 

Kind Regards

Visual Style Form.png

Message 23 of 63
Anonymous
in reply to: JBerns

@JBerns

 

In sheet metal defaults -> style and standard editor -> change filter options to all styles.

 

I hope this helps you on the way for you first challenge.

For your other challenges, i can't help you yet, since i'm just at the beginning stage for using and programming with iLogic. So i also have to find my way trought this.

 

Best regards

All Syles From Style Library.png

Message 24 of 63
JBerns
in reply to: Anonymous

@Anonymous,

Thanks. That was the style info I was seeking.

Regards,

Jerry

-----------------------------------------------------------------------------------------
CAD Administrator
Using Inventor 2022
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
Message 25 of 63
JBerns
in reply to: Anonymous

@Anonymous,

 

Unfortunately, the filter is already set to 'All Styles' in the Styles and Standards Editor.

 

I am under the assumption that if a dialog box can list all the styles, then iLogic (VB / API) should also be able to access the styles. I hope this assumption is true.

 

Perhaps @chandra.shekar.g can shed some light on how to access and select a style (sheet metal rule) from the library to assign to a solid body within the master part.

 

Regarding Challenge 2, perhaps this article by @Anonymous will be helpful in assigning the rule to specific solid bodies.

 

Regarding Challenge 3, I hope to continue to drive control from the sheet metal multi-body part. Changing the assigned rule for a solid body can easily communicate new dimensions to surrounding bodies in the master part.

 

 

 

Regards,

Jerry

-----------------------------------------------------------------------------------------
CAD Administrator
Using Inventor 2022
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
Message 26 of 63
chandra.shekar.g
in reply to: Anonymous

@Anonymous,

 

Issue is reproducible at my end as well. For further investigation, issue is reported to engineering team. I will get back to you after hearing from engineering team.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 27 of 63
JBerns
in reply to: chandra.shekar.g

@chandra.shekar.g,

 

Thank you for confirming the issue. I look forward to hearing of a solution.

 

From the forums, I hope to discover how to create a function to which I could pass the name of the sheet metal body/feature and the sheet metal rule. This would improve the code efficiency. Would you know of any code examples that would match this goal?

 

Regards,

Jerry

-----------------------------------------------------------------------------------------
CAD Administrator
Using Inventor 2022
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
Message 28 of 63
chandra.shekar.g
in reply to: JBerns

@JBerns,

 

Thanks for suggestion,

 

Currently, there is no iLogic function which can accepts sheet metal rule and solid body as parameters.

 

Please post this wish list at idea station using below link.

 

https://forums.autodesk.com/t5/inventor-ideas/idb-p/v1232

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 29 of 63
JBerns
in reply to: chandra.shekar.g

@chandra.shekar.g,

 

I understand that there is no specific function for this task. My goal was to create a user-defined function to which you could pass the two parameters - the surface body and the rule.

 

For example, Function Update_Surface_Body (Surface_Body, SM_Rule)

 

I attempted to build the function using your code example (message 6 of this thread) provided to @Anonymous, but I struggled with global and local declared parameters. I was hoping the API might offer a search tool, like the AutoLISP TBLSEARCH function, to find the surface body or a rule instead of having to do a For-Next loop each time to find the surfacebody/rule.

 

I am confident I can develop this with the assistance of the Community. Thanks again, Chandra.

 

 

Regards,

Jerry

-----------------------------------------------------------------------------------------
CAD Administrator
Using Inventor 2022
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
Message 30 of 63
chandra.shekar.g
in reply to: Anonymous

@Anonymous,

 

Try below workaround iLogic code to update sheet metal rule.

 

In "SheetMetalRuleDekplaten" rule at SchetspartTrog1.ipt file.

 

Sub Main() 

	Dim oDoc As PartDocument 

	oDoc = ThisApplication.ActiveDocument

	Call oDoc.Update() 

	Dim oDef As SheetMetalComponentDefinition 

	oDef = oDoc.ComponentDefinition 

	Dim oBody As SurfaceBody 

	For Each oBody In oDef.SurfaceBodies
		
		If oBody.Name = "Dekplaat 1" Then
	    
		Exit For
	    
		End If

	Next

	Dim oStyle As SheetMetalStyle 
 
	Select Case DikteDekplaat

	Case 2 
				 
				For Each oStyle In oDef.SheetMetalStyles
	     
				If oStyle.Name = "PLAAT KGW 002 S235JR" Then
	    			
				Exit For
	    
				End If
	    
				Next
	Case 3
				For Each oStyle In oDef.SheetMetalStyles
	    
				If oStyle.Name = "PLAAT 003 LASERFORM S235JR" Then
	    
				Exit For
	    
				End If
	    
				Next
	Case 4
				For Each oStyle In oDef.SheetMetalStyles
	    
				If oStyle.Name = "PLAAT 004 LASERFORM S235JR" Then
	    
				Exit For
	    
				End If
	    
				Next
	Case 5
				For Each oStyle In oDef.SheetMetalStyles
	    
				If oStyle.Name = "PLAAT 005 LASERFORM S235JR" Then
	    
				Exit For
	    
				End If
	    
				Next
				
	Case 6
				For Each oStyle In oDef.SheetMetalStyles
	    
				If oStyle.Name = "PLAAT 006 LASERFORM S235JR" Then
	    
				Exit For
	    
				End If
	    
				Next
	Case 8
				For Each oStyle In oDef.SheetMetalStyles
	    
				If oStyle.Name = "PLAAT 008 LASERFORM S235JR" Then
	    
				Exit For
	    
				End If
	    
				Next
	End Select
		
If Not oStyle Is Nothing AndAlso Not oBody Is Nothing AndAlso
	oDef.GetBodySheetMetalStyle(oBody) IsNot oStyle Then

	Logger.Info("changing body {0} --> {1}", oBody.Name, oStyle.Name)

	' Suppress some feature to avoid an update error.
	Feature.IsActive("Bend 1 Zijplaat R Trog") = False
	Feature.IsActive("Bend 2 Zijplaat R Trog") = False
	Feature.IsActive("Bend 1 Dekplaat 1") = False
	Feature.IsActive("Bend 2 Dekplaat 2") = False

	Try
	       Call oDef.SetBodySheetMetalStyle(oBody, oStyle)
	Finally
	       ' Unsuppress the features after the style has been changed.
	       Feature.IsActive("Bend 1 Zijplaat R Trog") = True
	       Feature.IsActive("Bend 2 Zijplaat R Trog") = True
	       Feature.IsActive("Bend 1 Dekplaat 1") = True
	       Feature.IsActive("Bend 2 Dekplaat 2") = True
	End Try

End If
End Sub

 

In "SheetMetalRuleZijplaatRTrog" rule at SchetspartTrog1.ipt file.

 

Sub Main() 

Dim oDoc As PartDocument 

oDoc = ThisApplication.ActiveDocument

Call oDoc.Update() 

ThisApplication.UserInterfaceManager.DoEvents()

Dim oDef As SheetMetalComponentDefinition 

oDef = oDoc.ComponentDefinition 

Dim oBody As SurfaceBody 

For Each oBody In oDef.SurfaceBodies
	
	If oBody.Name = "Zijplaat R Trog" Then
    
	Exit For
    
	End If

	Next

Dim oStyle As SheetMetalStyle 

Select Case DikteZijplaat
Case 3
			For Each oStyle In oDef.SheetMetalStyles
    
			If oStyle.Name = "PLAAT 003 LASERFORM S235JR" Then
    
			Exit For
    
			End If
    
			Next
Case 4
			For Each oStyle In oDef.SheetMetalStyles
    
			If oStyle.Name = "PLAAT 004 LASERFORM S235JR" Then
    
			Exit For
    
			End If
    
			Next
Case 5
			For Each oStyle In oDef.SheetMetalStyles
    
			If oStyle.Name = "PLAAT 005 LASERFORM S235JR" Then
    
			Exit For
    
			End If
    
			Next
			
Case 6
			For Each oStyle In oDef.SheetMetalStyles
    
			If oStyle.Name = "PLAAT 006 LASERFORM S235JR" Then
    
			Exit For
    
			End If
    
			Next
Case 8
			For Each oStyle In oDef.SheetMetalStyles
    
			If oStyle.Name = "PLAAT 008 LASERFORM S235JR" Then
    
			Exit For
    
			End If
    
			Next
End Select
	
If Not oStyle Is Nothing AndAlso Not oBody Is Nothing AndAlso
	oDef.GetBodySheetMetalStyle(oBody) IsNot oStyle Then

	Logger.Info("changing body {0} --> {1}", oBody.Name, oStyle.Name)

	' Suppress some feature to avoid an update error.
	Feature.IsActive("Bend 1 Zijplaat R Trog") = False
	Feature.IsActive("Bend 2 Zijplaat R Trog") = False
	Feature.IsActive("Bend 1 Dekplaat 1") = False
	Feature.IsActive("Bend 2 Dekplaat 2") = False

	Try
	       Call oDef.SetBodySheetMetalStyle(oBody, oStyle)
	Finally
	       ' Unsuppress the features after the style has been changed.
	       Feature.IsActive("Bend 1 Zijplaat R Trog") = True
	       Feature.IsActive("Bend 2 Zijplaat R Trog") = True
	       Feature.IsActive("Bend 1 Dekplaat 1") = True
	       Feature.IsActive("Bend 2 Dekplaat 2") = True
	End Try

End If

	
End Sub

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 31 of 63
chandra.shekar.g
in reply to: JBerns

@JBerns,

 

Can you please explain your situation with sample code?

 

For each loop is required to find SurfaceBody / rule in code example (message 6 of this thread). Transferring variables from one iLogic to another iLogic may not feasible.

 

For sample code on global variable declaration, refer below link.

 

https://www.cadlinecommunity.co.uk/hc/en-us/articles/203491091-Inventor-2016-iLogic-Using-Global-Var...

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 32 of 63
Anonymous
in reply to: chandra.shekar.g

@chandra.shekar.g

 

Thanks again for helping me out on this!

I've changed my rules to the new ones. At first i thought it wasn't working. Because when i opened the parts for the first time, and changed 2 parameters, then i still got an error after hitting the save button. but when i hit run all rules again, the errors are gone. and if i changed again 2  parameters at the time and hit the save button, it works fine. i did this a couple of times, and it worked every time. When i closed the documents and reopend them, i had the same problem, the first time errors, and after running al rules again, everything works fine. if i hit the update command instead of save butten, i also first get an error message eacht time. i tought with the suppression you added to the rule, this would be gone, and it would work fine also if we hit the update command instead.

 

I think we are almost there, since it works most of the time. but it would be great if everything works from the first time we've opend the files. and also that it wouldn't matter if we hit the save button or the update command. now we still have the error when we use the update command.

 

When i hit run al rules the first time i opend the document, before i change the parameters, it works also fine. so i tought mabe i could run my rules when opening the document, but this doesn't give the same result. errors are still there.

 

I added another video, to explain more, and the parts with the new rules, so maybe you can reproduce the problem, and if possible, helping out on a solution to avoid the last bugs.

 

If you need anything else, or more explanation, let me know.

 

Thx in advance!!!

 

https://knowledge.autodesk.com/community/screencast/fec2596a-2537-422c-8264-dfb2c021bb20

 

 

 

Message 33 of 63
JBerns
in reply to: chandra.shekar.g

@chandra.shekar.g,

 

I was surprised that a user must use a For-Next loop to find a surface body or a sheet metal rule or most anything. I would have thought there would have been a built-in search function. If For-Next loop is required, then that is what I will use.

 

Until the issue is resolved for selecting a sheet metal rule that is not in use, there is not much point in further development.

 

@Anonymous, are you able to assign a sheet metal rule from your library to a surface body? 

-----------------------------------------------------------------------------------------
CAD Administrator
Using Inventor 2022
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
Message 34 of 63
JBerns
in reply to: JBerns

I found this API Sample that iterates through the Sheet Metal Styles (rules):

Inventor - API - Sheet Metal Style Display sample

 

It can determine if a style is 'In Use' and its location (Local, Library, Both).

 

Perhaps some code from this sample can be used to assign a sheet metal rule to a surface body. The pursuit continues.

 

Regards,

Jerry

-----------------------------------------------------------------------------------------
CAD Administrator
Using Inventor 2022
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
Message 35 of 63
Anonymous
in reply to: JBerns

@JBerns

Yes i can assign them. All rules from our library are available.

Message 36 of 63
JBerns
in reply to: Anonymous

@Anonymous,

 

Are all rules in use by a solid body in your multi body part?

 

In my test,  I created three solid bodies, each assigned a different sheet metal rule. In the iLogic form I have many rules available, but only those currently in use can be assigned to a solid body.

 

Would you mind testing your code on a multi body part with just two solids? As I recall, your library also has several sheet metal rules.

 

Thanks. I look forward to the replies.

 

Regards,

Jerry

 

-----------------------------------------------------------------------------------------
CAD Administrator
Using Inventor 2022
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
Message 37 of 63
MjDeck
in reply to: JBerns

@Anonymous, I'm working with @chandra.shekar.g on this.

I found a way to avoid the situation where you have to run the rules manually after the first changes in a session. To fix that, add this line near the top of the SheetMetalRuleDekplaten rule:

trigger = DikteZijplaat & DikteDekplaat

 This statement can actually go anywhere in the rule, but it makes sense to put it near the top (after Sub Main).

Without this change, the rule would run only when DikteDekplaat changes. With this new statement, the rule will also run when DikteZijplaat changes. I'm not exactly sure why this is required, but I think it has something to do with dependencies between features.

This change does not get rid of the Update pop-up warning dialog.


Mike Deck
Software Developer
Autodesk, Inc.

Message 38 of 63
Anonymous
in reply to: MjDeck

@MjDeck and @chandra.shekar.g

Thx again for helping out. This works fine now.

Let me know if you find any solution for the update problem. i think this has to work somehow, since we don't get any errors when hitting the save button instead.

 

Thx in advance!

Message 39 of 63
Anonymous
in reply to: JBerns

@JBerns

When i delete all the local sheet metal styles in my document, and then run my rules with the changes i've made, then inventor automaticly create the sheet metal rules from my library in my local document.

So each library sheet metal style is available, no problems with that at my end here...

Message 40 of 63
JBerns
in reply to: Anonymous

@Anonymous,

 

I have the sheet metal assignment to a surface body working now - it was an error on my part. My apologies all.

 

Now to work on efficiency.

  • Our library has 70 sheet metal rules.
  • Our multibody part could have as many as 12 bodies.
  • 6 lines of code are required to test for one rule.
  • 6 lines * 70 rules = 420 lines of code to test for one solid body (surface)
  • 12 bodies * 420 lines for rule testing = 5040 lines of code.

A function to test and change the body rule assignment will be essential to keep this manageable. However, I am struggling with the development of the function, especially passing the argument, which will be the surface body name.

 

I have attached a part with the iLogic developed to-date. Thanks again, @chandra.shekar.g, for the code snippets. And thanks again, @Anonymous, for testing sheet metal rules in library, but not in use in the part.

 

 

Regards,

Jerry

 

-----------------------------------------------------------------------------------------
CAD Administrator
Using Inventor 2022
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report