Changing sheet metal Gauge via API

Good evening,

Can someone help me how to change sheet metal parameters steel gauge via API. Part I have is using predefined gauge table with 15 different materials.

I assume I`ll have to use the following code with some other code to change the gauge? Right?

boolstatus = Part.Extension.SelectByID2("Sheet-Metal", "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0)

Any information or link to a similar topic will be great.

Thanks,

SolidworksApi macros
Answers 13
AT
AT 2014-04-30 Best Answer

Hi,

You need to get the pointer to sheet metal feature. You can do this via selection or just directly by name: PartDoc::FeatureByName. This will give you a pointer to IFeature object where you can call the Feature::GetDefinition method. Now just call the following method to set the gauge table parameters: SheetMetalFeatureData::SetUseGaugeTable.

Take a look at this example demonstrating the usage of gauge table: http://help.solidworks.com/2013/English/api/sldworksapi/create_base-flange_feature_using_gauge_table_example_vb.htm

______________________________________________

Regards, Artem Taturevych | Snr. Developer | IC3D ANZ

IC3DSteel – New Steel Solution for SolidWorks

translationXpert – SolidWorks files language translator

LinkedIn - SolidWorks API Group

SF
SF 2014-05-04

Sorry Artem, I`ve got myself confused.. Don`t really have a lot of experience with API and its structure.

So I have a sheet metal part with "Sheet-Metal" feature and Gauge table attached.

    Dim swApp As SldWorks.SldWorks

    Dim swModel As SldWorks.ModelDoc2

    swModel = swApp.ActiveDoc

    Dim ShMetalFeat As SldWorks.SheetMetalFeatureData

    ShMetalFeat.SetUseGaugeTable(True, "c:\Program Files\SolidWorks Corp\SolidWorks\lang\english\Sheet Metal Gauge Tables\Steel Gauge Table.xls")

   What should I do next to change thickness from 7gauge to 10 gauge? Typically it has to be done manually by choosing Gauge from the drop down menu in Sheet metal Parameters (see 1st post picture).

Thank you.

AT
AT 2014-05-05

Hi Sanya,

Here is the sample which changes the gauge thickness to the last value in the drop-down. You need to select the base flange which is uses gauge table and run the macro:

<p>Dim swApp As SldWorks.SldWorks</p><p>Dim swModel As SldWorks.ModelDoc2</p><p>Dim swSelMgr As SldWorks.SelectionMgr </p><p></p><p>Sub main() </p><p></p><p>    Set swApp = Application.SldWorks </p><p></p><p>    Set swModel = swApp.ActiveDoc</p><p>    </p><p>    Set swSelMgr = swModel.SelectionManager</p><p>    </p><p>    Dim swFeat As SldWorks.Feature</p><p>    </p><p>    Set swFeat = swSelMgr.GetSelectedObject6(1, -1)</p><p>    </p><p>    Dim swBaseFlangeFeatData As SldWorks.BaseFlangeFeatureData</p><p>    </p><p>    Set swBaseFlangeFeatData = swFeat.GetDefinition</p><p>    </p><p>    Debug.Print swBaseFlangeFeatData.UseGaugeTable</p><p>    Debug.Print swBaseFlangeFeatData.GaugeTablePath</p><p>    Debug.Print swBaseFlangeFeatData.ThicknessTableName</p><p>    </p><p>    Dim vThicknesses As Variant</p><p>    vThicknesses = swBaseFlangeFeatData.GetTableThicknesses()</p><p>    swBaseFlangeFeatData.ThicknessTableName = vThicknesses(UBound(vThicknesses))</p><p></p><p></p><p>    swFeat.ModifyDefinition swBaseFlangeFeatData, swModel, Nothing</p><p>    </p><p>End Sub</p>

______________________________________________

Regards, Artem Taturevych | Snr. Developer | IC3D ANZ

IC3DSteel – New Steel Solution for SolidWorks

translationXpert – SolidWorks files language translator

LinkedIn - SolidWorks API Group

SF
SF 2014-05-06

Artem,

thank you.

I think I`m missing something. I added the code below to my VB code and I`m getting an error:

      swBaseFlangeFeatData = swFeat.GetDefinition  <--Additional information: Object reference not set to an instance of an object.

I tried to save it as a macro in SW and I`m getting Run-time error 91 Object variable or with block variable not set. Same line as above.

AT
AT 2014-05-06

You haven't selected the base flange feature in Feature Manager tree (this should be the only or first selected object).

SF
SF 2014-05-06

ok I see. Is it possible not to select it in the tree and tell it via code what base flange to choose ?  may be using Feat.Name?

AT
AT 2014-05-06

Yes, not a problem. Just replace this

<p>Set swFeat = swSelMgr.GetSelectedObject6(1, -1)</p>

with this

<p>Set swFeat = swModel.FeatureByName ("Base Flange Feature Name Here")</p>
SF
SF 2014-05-06

Artem,

for some reason I`m getting the following error. Any thoughts?

comment imagecomment image
AT
AT 2014-05-06

You need to specify base flange feature not sheet metal feature. Looks like you are passing the name of main sheet metal feature. Can you post a snapshot of your tree and I will point you to the correct one.

______________________________________________

Regards, Artem Taturevych | Snr. Developer | IC3D ANZ

IC3DSteel – New Steel Solution for SolidWorks

translationXpert – SolidWorks files language translator

LinkedIn - SolidWorks API Group

SF
SF 2014-05-06

ok. got it. you right I used the wrong name. Thank you.

but correct me if I`m wrong this code is overiding thickness of the part. if you look into the sheet metal properties it still show the default (user choosen) thickness.

In addition when you create the part drawing BOM reflects incorrect material. Is there a way to avoid this and change the gauge like you do from dropdown menu?

YN
YN 2014-07-15

like FeatureByName code →

Set SwFeat = SwModel.FeatureByName("草图1")

DD
DD 2014-12-11

Sanya,

I'm looking to accomplish something similar... were you able to get this to work and if you did, could you repost the code to share?

SF
SF 2014-12-16

What I end up doing is the overriding model parameters:

Private Sub Thickness()

        Try

            Dim Material As String

            ' changing baffle thickness

            'D1- bend Radius, D2-K-Factor

            Select Case cbox_Material.SelectedItem

                Case "12 GA" 'R1330 Sheet Steel Galvanized, 12 ga (4.531 per sq ft)

                    IDMaterial = "12" : IDSheetPlate = "PS"

                    ' Bend radius

                    swPart.Parameter("D1@Sheet-Metal").SystemValue = 0.062 * 0.0254

                    'sheet metal k-faktor

                    swPart.Parameter("D2@Sheet-Metal").SystemValue = 0.357

                    ' thickness

                    swPart.Parameter("Thickness@Sheet-Metal").SystemValue = 0.1046 * 0.0254

                    Material = "R1330 - 12 Ga Galvanized Steel"

                    swPart.SetMaterialPropertyName2("Default", MaterialDB, Material) ' (config, DBpath, material)

Case ' and so on for each material thickness, k-factor, bend radius

end sub