Hi everyone,
I wrote an app some time ago that swaps out userparameters that drive sheetmetal thickness and bendradius.
it appears to work about 60% of the time when it doesn't it does not give any warning but even though the FX table shows the new userparameters driving thickness and bendradius the "sheet metal defaults dialog" thickness input box is grayed out and shows no value what so ever. Clicking the Edit Sheet metal rule to display the "Style and Standard Edtior" the Thickness and Bendradius still show the Old userparameters. See attached Pic.
I am setting the parameters as follows.
Replaced "Chan_Th" with "chn_thk" in FX Userparameters
then...
[Code]
oSheetMetalCompDef.UseSheetMetalStyleMaterial = True oSheetMetalCompDef.ActiveSheetMetalStyle.Thickness = sThick
[/Code]
As you can see FX reports the change but sheet metal settings does not.
This code appears to work or not at random.
We really need to figure this one out.
You have only given 2 lines of code, but you have told it to use a style and then are trying to set a thickness by some parameter. If you are going to use a style then you need to do something like go through all the styles and find the one with the thickness you want and then set it active.
I am very confident of the code that set the userparameters. I've used it many times before.
The problem is that we are trying to drive the thickness and bendradius with USERPARAMETERS.
as shown in the attached pics.
This can be done manually and it works 100% of the time.
Programmically I am using ActiveSheetMetalStyle.Thickness = sThick
Where in this case sThick = "chn_thk". A userparameter name not a value.
We set "UseSheetMetalStyleMaterial = True" because inventor appears to need it set that way to work.
We do this when we set thickness and bendradius to a userparameter manually.
Just for testing what you are saying I have created this and ran it 50+ time with a button click and even have it creating a new parameter and it has worked 100% of the time. I am using Inv 2012 X64 and X32 for testing.
Dim R As New Random Try Dim MyParameterName As String = "MyParam_" & R.Next(1000) Dim oPart As PartDocument = ThisApplication.ActiveEditDocument Dim oParams As Parameters = oPart.ComponentDefinition.Parameters oParams.UserParameters.AddByValue(MyParameterName, R.Next(1, 24) / 16, UnitsTypeEnum.kInchLengthUnits) Dim oSheetMetalCompDef As SheetMetalComponentDefinition = oPart.ComponentDefinition oSheetMetalCompDef.ActiveSheetMetalStyle.Thickness = MyParameterName oSheetMetalCompDef.UseSheetMetalStyleMaterial = True oPart.Update() Catch ex As Exception MsgBox(ex.Message) End Try
Okay, Let's try again.
' I am using Inventor 2011 on Win732 and Win764.
' What I am trying to show here is that we are changing the userparameter names NOT the values.
' We ended up creating a entirely new set of userparameter names for all our inventor files.
' The program i wrote swaps that old naming convention for the new convention.
' The new naming convention is critical for our new company processes.
' Miles of validation and variable defs left out of this snippet for ease of reading.
Set oSheetMetalCompDef = oDoc.ComponentDefinition
sOldThick = oSheetMetalCompDef.ActiveSheetMetalStyle.Thickness
sOldBendRadius = oSheetMetalCompDef.ActiveSheetMetalStyle.BendRadius
sThick = ""
sBendRadius = ""
For Each oUp In oUserParameters
NewUserParam = ""
OldUserParam = oUp.Name
If Not isNameInDB(oConn, OldUserParam) Then
' Function that returns a new userparameter name from a database
NewUserParam = Get_Old_2_New(oConn, OldUserParam)
If NewUserParam <> "" Then
If OldUserParam = sOldThick Then sThick = NewUserParam
If OldUserParam = sOldBendRadius Then sBendRadius = NewUserParam
' Rename old parameter name as new parameter name
oUp.Name = NewUserParam
End If
End If
Next oUp
' Make sure Thickness and Bendradius driving userparameters NAMES are updated in sheetmetal defs.
If sThick <> "" then
oSheetMetalCompDef.UseSheetMetalStyleMaterial = True
oSheetMetalCompDef.ActiveSheetMetalStyle.Thickness = sThick
oSheetMetalCompDef.ActiveSheetMetalStyle.BendRadius = sBendRadius
End If
The code that I had posted was adding a new parameter of some random name and a random value and then was doing just what you are having problems with and it worked 100% of the time. The differences here are that you are working in VBA and I am working in .NET, you have 2011 and I have 2012. Have you been able to step through the code in a non working instance to see what went wrong? I know that is not the easiest thing to do when it only fails part of the time.
With respect your code is creating userparameters from scratch. by value.
Mine is renaming Existing userparameters.
These are two very different things.
With renaming userparameters Inventor has to ripple the changes through FX entirely rebuilding formula expressions that use the parameters.
Stepping through the code is difficult as it has to recurse through huge assemblies.
Also I can only open inventor to write code when someone else is not using the network license.
These days that is a very rare event. Harder yet is to get one of the engineers to allow me the time to debug on their machines when something breaks.
Since I am using VBA I
BTW the files we are updating can be either Inventor Version 10 (Not 2010) or Version 2011.
Dear all,
I am in a similar problem while trying to handle sheet metal parameters through VBA.
For my specific tast I would need to be able to catch the name (or the item number) of the sheet metal parameters.
with ThisApplication.ActiveDocument.ComponentDefinition.ActiveSheetMetalStyle
.Thickness
.BendRadius
...etc etc
I can catch the values, and of course we are not dealing with parameters here.
Does anyone know how/if it is possible to catch the sheetmetal parameter names?
Thanks,
Massimo