CHANGE THE "SHEET METAL THICKNESS RULES" OF PARTS FROM AN ASSEMBLY USING ILOGIC

CHANGE THE "SHEET METAL THICKNESS RULES" OF PARTS FROM AN ASSEMBLY USING ILOGIC

ocastro63PFF
Explorer Explorer
1,684 Views
7 Replies
Message 1 of 8

CHANGE THE "SHEET METAL THICKNESS RULES" OF PARTS FROM AN ASSEMBLY USING ILOGIC

ocastro63PFF
Explorer
Explorer

THANKS FOR THE REPLIES, I SPEAK SPANISH SO I HAVE USED THE TRANSLATOR.

I HAVE AN ASSEMBLY WITH PARTS IN "SHEET METAL" AND I HAVE PARAMETERIZED USING THE "FORM DE ILOGIC".

AT THE ASSEMBLY LEVEL I CAN'T CHANGE THE THICKNESSES OF THE PIECES, SINCE ALL THE PIECES HAVE RULES CONFIGURED.

CAN SOMEONE HELP ME TO SOLVE THIS DOUBT.

------------------------------------

ocastro63PFF_1-1716097272166.png

 

Parameter("PIEZA A:1", "Thickness") = X
Parameter("PIEZA B:1", "Thickness") = Y
Parameter("PIEZA C:1", "Thickness") = Z

-----------------------------IMAGE 1.png 

0 Likes
1,685 Views
7 Replies
Replies (7)
Message 2 of 8

batuhanozmen98
Enthusiast
Enthusiast

Hello,

 

I think this is about the names.

 

You should change the rule like this:

 

Parameter("PART A:1", "Thickness") = X
Parameter("PART B:1", "Thickness") = Y
Parameter("PART C:1", "Thickness") = Z

Name of the parts must be the same with the tree browser names.


If this reply solve your problem, Then click on the ACCEPT SOLUTION button please.
My LinkedIn | Instagram
0 Likes
Message 3 of 8

WCrihfield
Mentor
Mentor

Hi @ocastro63PFF.  I just wanted to inform you that simply changing the value of the 'Thickness' parameter within the part will not actually change which sheet metal rule/style it is set to.  It will only change the value of that one parameter.  The sheet metal rule/style has many other settings defined within it besides just thickness.  And if you just change the value of that one parameter, without changing which sheet metal rule/style it is set to, you will likely break the link between the part's active sheet metal rule/style, and that thickness, essentially forcing it to use a 'custom' thickness.  If you truly want to change which sheet metal rule/style the parts are set to by code (not just change the value of that one parameter), then you will need a lot more code than what you currently have there.  You would need to actually dig down into each of those parts, check which sheet metal rule/style they are currently set to, check if its thickness matches what you want it to be, and if not, try to change its sheet metal rule/style to one that is for the thickness you want.  It can get fairly complicated.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 8

ocastro63PFF
Explorer
Explorer

THANK YOU FOR YOUR ANSWERS

I THOUGHT THERE WAS SOME ROUTINE OR RULE THAT WOULD HELP ME SOLVE THIS CASE.

0 Likes
Message 5 of 8

WCrihfield
Mentor
Mentor

Hi @ocastro63PFF.  Sorry, but there is no already existing, short or simple code solution that will instantly work exactly the way you want it to.  Partially because of how custom your situation is.  However, that does not mean that a solution could not eventually be created for this, with enough time and effort invested into it.

 

What you are trying to do is very likely possible to do by code.  However, since it is a very custom situation, it will require a very custom solution.  Since there is unfortunately no short or simple way to accomplish what you want to do by code, some significant investments of time and effort must be made to create a longer and more complex solution.  A strategy or plan must be made to utilize either known code resources and/or create new code resources, in an efficient way, to accomplish this task.  Then the actual code must be generated and tested.

 

Custom aspects of this task:

  • Multiple specifically named parts that each need to be changed differently from each other.
  • The specific names of the assembly parameters do not appear to be logically associated to the names of the specific parts they are supposed to be effecting, so that association between part names and parameter names must be specified within the code somehow, making the code dependent on all those specific, hardcoded names.
  • You have a limited set of sheet metal rules / styles, where there may (or may not be) a rule / style for available for every possible thickness variation that you may specify on the assembly side.  So, what should happen when one of the assembly parameters is set to a thickness that there is no sheet metal style available for within the part?  Should it just not do anything, or should it try to create a new sheet metal style, or something else?  And if it should create a new style, then how should all the other settings of the style (besides thickness) be set?

One thing to keep in mind is that, if the names of the parts involved, or the names of the parameters involved, ever change, then those names within the code will also need to be changed, or it will start throwing errors and not work anymore.

 

I did try to design the code below in a way to minimize the changes that would be needed to the code when the part names or parameter names need to be changed.  You may need to change the values in Lines 17 through 19, or...add or remove lines of code in that area to be able to work with more or less part name & parameter name pairs.   I also tried to include a lot of comments in this code, to help you read through it and understand what is going on, but those notes may need to be translated.  As you can see, it is quite long and complex, so I can only hope that you will eventually be able to fully understand what all it is trying to do along the way.  I also have not had the chance to test this code, so be cautious, and initially test it out on files that are not super important.

 

Sub Main
	'make sure this rule only tries to work with an assembly (not a part, drawing, or presentation)
	Dim oADoc As AssemblyDocument = TryCast(ThisDoc.Document, Inventor.AssemblyDocument)
	If oADoc Is Nothing Then
		Logger.Debug("Rule named '" & iLogicVb.RuleName & "' could not obtain an AssemblyDocument!")
		Return
	End If
	'get all referenced documents at all levels of the entire assembly structure
	Dim oAllRefDocs As DocumentsEnumerator = oADoc.AllReferencedDocuments
	Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
	'get access to the UserParameters of the main assembly
	Dim oAsmUParams As UserParameters = oADef.Parameters.UserParameters

	'<<< specify which part names, and which assembly parameter names to associate with each other >>>
	Dim oPairs As New Dictionary(Of String, String)
	'first specify part file name (without extension), then specify assembly parameter name
	oPairs.Add("PART A", "X")
	oPairs.Add("PART B", "Y")
	oPairs.Add("PART C", "Z")

	For Each oPair As KeyValuePair(Of String, String) In oPairs
		'create variable to represent the UserParameter object we are looking for
		Dim oPairParam As UserParameter = Nothing
		'try to find those specific UserParameter objects by name, then assign them to the variables
		Try
			oPairParam = oAsmUParams.Item(oPair.Value)
		Catch
			MsgBox("Could not find UserParameter named '" & oPair.Value & "' in assembly!", vbExclamation, "iLogic")
			Continue For 'skip to next Dictionary entry
		End Try
		If oPairParam Is Nothing Then Return
		
		'try to find the referenced part document by its specified file name (filtered to only sheet metal parts)
		Dim oPairPartDoc As PartDocument = Nothing
		For Each oRefDoc As Inventor.Document In oAllRefDocs
			'get the file name, without file path, and without file extension
			Dim sFileName As String = System.IO.Path.GetFileNameWithoutExtension(oRefDoc.FullFileName)
			'compare the file name to the specified file name in the current Dictionary entry
			If sFileName <> oPair.Key Then Continue For 'if they do not match, then skip to next referenced document
			'if it is not a part, then skip to next referenced document
			If Not TypeOf oRefDoc Is PartDocument Then Continue For
			'declare a PartDocument type variable, then set its value (makes things easier later)
			Dim oPDoc As PartDocument = oRefDoc
			'if it is not specifically a sheet metal part, then skip directly to next referenced document
			If Not TypeOf oPDoc.ComponentDefinition Is SheetMetalComponentDefinition Then Continue For
			'<<< matching file name, document type, and document sub type - found the part >>>
			oPairPartDoc = oPDoc
			Exit For 'exit loop of referenced documents
		Next oRefDoc 'go to the next referenced document
		
		If oPairPartDoc Is Nothing Then
			MsgBox("Could not find Part file named '" & oPair.Key & "' in assembly referenced documents!", vbCritical, "iLogic")
			Continue For
		End If
		'make sure this referenced part is 'fully' open (but not visible), and make sure it is the active version (if multiple versions)
		oPairPartDoc = ThisApplication.Documents.Open(oPairPartDoc.FullDocumentName, False)
		'make sure that if this part document requires an update, it gets updated before further inspection / changes
		If oPairPartDoc.RequiresUpdate Then oPairPartDoc.Update2(True)
		Dim oSMDef As SheetMetalComponentDefinition = oPairPartDoc.ComponentDefinition
		'get the collection of all Sheet Metal Rules/Styles that are available for this sheet metal part
		Dim oSMStyles As SheetMetalStyles = oSMDef.SheetMetalStyles
		'get the active sheet metal rule/style (the value of this property can be read, but not changed directly)
		Dim oActiveSMStyle As SheetMetalStyle = oSMDef.ActiveSheetMetalStyle 'ReadOnly property
		'get the expression / equation defining the Thickness that this sheet metal rule/style is for (a String)
		Dim sActiveSMStyleThickness As String = oActiveSMStyle.Thickness
		'get the main Parameter object for this part's Thickness (ReadOnly - we can not set a different Parameter as its value)
		Dim oThicknessParam As Inventor.Parameter = oSMDef.Thickness
		'check if the style thickness expression matches the part's "Thickness" parameter's expression
		'if they do not match, then force the parameter's expression to be the thickness of the sheet metal style
		If oThicknessParam.Expression <> sActiveSMStyleThickness Then
			'if True, forces the part to use the Thickness defined within the part's active sheet metal style
			oSMDef.UseSheetMetalStyleThickness = True 'Read/Write property with Boolean value
		End If
		'compare the assembly parameter's expression to the part's active sheet metal style thickness String
		If sActiveSMStyleThickness = oPairParam.Expression Then
			'if the match, then no action is needed, so just skip to the next Dictionary entry
			Continue For 'everything is already OK, so skip to next referenced document
		Else 'they do not match, so attempt to switch to a different sheet metal style for needed thickness
			For Each oSMStyle As SheetMetalStyle In oSMStyles
				If oSMStyle.Thickness = oPairParam.Expression Then
					'found a sheet metal style with matching thickness, so activate it
					Try : oSMStyle.Activate : Catch : End Try
					'<<< if no sheet metal style is found with matching thickness, nothing will happen >>>
				End If
			Next oSMStyle
		End If
		If oPairPartDoc.RequiresUpdate Then oPairPartDoc.Update2(True)
	Next oPair 'go to the next Dictionary entry
	'if the main assembly requires an update, then update it
	If oADoc.RequiresUpdate Then oADoc.Update2(True) 'True = Accept Errors And Continue
	'if the main assembly has been dirtied (changed since last save), then save it now
	'If oADoc.Dirty Then oADoc.Save2(True) 'True = also save dependent documents that have changed
End Sub

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 8

ocastro63PFF
Explorer
Explorer

THANK YOU WCrihfield for taking your time to help me.

As you know, I am not a programmer and I do not know how those codes that you have sent work. I have only tested them and translated the suggestions you say.
I have tried it and nothing happens, maybe I am making a mistake, I don't know. I work with ILOGIC only to link assembly parameters and my knowledge is very limited.

I attach my "assembly file" so you can review it.

---------------------------------------------------------------------------------------------------------------

OPTION 2

On the other hand, I have tried another way, it works but without using any rule or program, but with this solution the "pieces" lose the "Sheet metal rule":

 

ocastro63PFF_1-1716301145756.png

 

IN "STEP 4"
SHOULD THERE ONLY BE SOME RULE OR PROGRAM THAT HELP "UPDATE" THIS VALUE IN THE RULES?

 

ocastro63PFF_2-1716301416043.png

 

 

 

0 Likes
Message 7 of 8

WCrihfield
Mentor
Mentor

Hi @ocastro63PFF.  I am not allowed to download or open ZIP (or RAR, or similar compressed) files from forums with my work computer, due to corporate security policies, so I will not be able to review those files.

 

Did any error message show when you ran the code I posted above?  If so, could you capture what it said, and can you post that here?  Especially if it mentioned which line of code that the error happened on.  My code example did not include a lot of feedback, because that would have taken even longer to type out, and would have made the code even longer.

 

My code example was trying to find those few names parameter objects within the assembly, then find those specifically named parts within the assembly, then check their current main 'Thickness' parameter's expression against the 'Thickness' specified within that part's active sheet metal rule/style, to see if they are the same value.  If they are the same, then no action is needed.  If they are different, then it should turn that one setting on, forcing the main thickness of the part to be the same as the active sheet metal rule/style's thickness setting.  Then, try to find an existing sheet metal rule/style that is for the thickness being requested by the assembly parameter.  If one is found, then activate that rule/style.  But if no such rule/style is found for that specific thickness, then it will not do anything.

 

By the way, in your original post above, within the images, it looked like one of the assembly parameters was set to "5 mm", but in the image showing the list of available sheet metal rules, I do not see one for 5 mm.  It goes from 4.5 to 6.0.  If that is the case, then what should happen?  You may need to somehow limit the possible values for those parameters in the assembly to only thicknesses that you have sheet metal rules for in those parts.

 

If that checkbox property is not important to you, then doing things that simpler way should be just fine.  When that option is off, that just means that the active sheet metal rule/style will not dictate the thickness of the part.  However, depending on how other things are set-up, the other settings of the active sheet metal rule/style should still have some level of control over that sheet metal part.  So, it may not be a major problem, but I am not familiar with how important that may be on your end.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 8 of 8

ocastro63PFF
Explorer
Explorer

THANK YOU FOR YOUR REPLY

0 Likes