Sheet Metal - Flat Pattern Width and Length - Parametric (VBA) ??

Sheet Metal - Flat Pattern Width and Length - Parametric (VBA) ??

Anonymous
Not applicable
3,323 Views
6 Replies
Message 1 of 7

Sheet Metal - Flat Pattern Width and Length - Parametric (VBA) ??

Anonymous
Not applicable

Hi to community.

I need to get sheet metals flat pattern extents width and length expressions in mm format, and assign them to description property of document as parametric values. By this code I can get them in cm unit and can not control precision of values.

 

Sub AssignFlatPatternDimensionsToDescription(partDoc As PartDocument)
    'If partDoc.DocumentType = kPartDocumentObject Then
        'If IsSheetMetal(partDoc) Then
            On Error GoTo exitSubPartToSheetMetal
            Dim oCompDef As SheetMetalComponentDefinition
            Set oCompDef = partDoc.ComponentDefinition
            
             If oCompDef.HasFlatPattern = False Then
                 Dim oPartDoc As Document
                 Set oPartDoc = ThisApplication.Documents.Open(partDoc.FullFileName, True)
                 oCompDef.Unfold
                 oPartDoc.Close
             End If
            
             Dim oPropsets As PropertySets
             Set oPropsets = partDoc.PropertySets
                    
             Dim designTrackPropSet As PropertySet
             Set designTrackPropSet = partDoc.PropertySets.item("Design Tracking Properties")
        
             ' Get the Description property.
             Dim oPropDescription As Property
             Set oPropDescription = oPropsets.item("{32853F0F-3444-11d1-9E93-0060B03C1CA6}").ItemByPropId(kDescriptionDesignTrackingProperties)
        
             ' Add flat pattern expressions to the property.
             oPropDescription.Expression = "=<Flat Pattern Width> x <Flat Pattern Length>"
        'End If
            
exitSubPartToSheetMetal:
        If Err.Number <> 0 Then
            Err.Clear
        End If
    'End If
End Sub

For a drawing view I can set the label by this code (as parametric) in mm;

'' FLAT PATTERN WIDTH x LENGTH
                    Msg = "<StyleOverride FontSize='0.3'><SheetMetalProperty SheetMetalPropertyID='78850' Precision='1'>FLAT PATTERN EXTENTS WIDTH</SheetMetalProperty></StyleOverride>"
                    Msg = Msg & "<StyleOverride FontSize='0.3'> x </StyleOverride>"
                    Msg = Msg & "<StyleOverride FontSize='0.3'><SheetMetalProperty SheetMetalPropertyID='78849' Precision='1'>FLAT PATTERN EXTENTS LENGTH</SheetMetalProperty></StyleOverride>"
drawView.Label.FormattedText = Msg                    

And I can expose thickness parameter as property and use the value as parametric in mm. But can't find a way to get flat pattern extents values in mm & and can't control precision.. 

 

May someone tell me; if it is possible in VBA; how to do it?

Thanks in advance. 

 

0 Likes
Accepted solutions (2)
3,324 Views
6 Replies
Replies (6)
Message 2 of 7

Sergio.D.Suárez
Mentor
Mentor

Hi, I usually use an ilogic rule similar to the example below. I use ilogic because it is easier for me to reference this sheet metal document. For example I have an assembly, and I want to create a rule in each metal sheet file linked, this rule I want to be automatically updated before changes in geometry. To achieve this, I use a mother rule that creates other rules in each file of an assembly. I think that vba could also be used to create internal rules for each component, as I described above.
I hope you can solve your problem. regards


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 3 of 7

Anonymous
Not applicable

Hi and thanks for giving time.

I am not so familiar with the logic of iLogic but as I understant iLogic rules execute it self like repainting, or say updating, re-executing the routine. Your code sets a static value, but the rule updates document when a change occurs; if I am not wrong.

In VBA it is not possible as you know. This is exactly the same code as yours and sets the value once - as static.

partDoc.PropertySets.item("Design Tracking Properties").item("Description").Value = strThickness & strLength & "x" & strWidth
partDoc.PropertySets.item("Design Tracking Properties").item("Description").Value = width & "x" & length

When a parameter like thickness or geometry chances, value of item("Description").value remains the same.  It must be a parametric expression. 

Thanks a lot.

Sub AssignFlatPatternDimensionsToDescription_II(partDoc As PartDocument)
    If IsSheetMetal(partDoc) Then
        On Error GoTo exitSub
               
        Dim oCompDef As SheetMetalComponentDefinition
        Set oCompDef = partDoc.ComponentDefinition
       
        If oCompDef.HasFlatPattern = False Then
            Dim oPartDoc As Document
            Set oPartDoc = ThisApplication.Documents.Open(partDoc.FullFileName, True)
            oCompDef.Unfold
            oPartDoc.Close
        End If
       
        Dim fpBox As Box
        Set fpBox = oCompDef.FlatPattern.body.RangeBox

        Dim width As Double
        Dim length As Double

        length = fpBox.MaxPoint.X - fpBox.MinPoint.X
        width = fpBox.MaxPoint.Y - fpBox.MinPoint.Y

        Dim objUOM As UnitsOfMeasure
        Set objUOM = partDoc.UnitsOfMeasure

        Dim strLength As String
        Dim strWidth As String
        Dim strThickness As String

        strLength = objUOM.GetStringFromValue(length, UnitsTypeEnum.kDefaultDisplayLengthUnits)
        strWidth = objUOM.GetStringFromValue(width, UnitsTypeEnum.kDefaultDisplayLengthUnits)
        strThickness = objUOM.GetStringFromValue(oCompDef.Thickness.ModelValue, UnitsTypeEnum.kDefaultDisplayLengthUnits)

        partDoc.PropertySets.item("Design Tracking Properties").item("Description").Value = strThickness & strLength & "x" & strWidth

   End If
        
exitSub:
        If Err.Number <> 0 Then
            Err.Clear
        End If
    End If
End Sub

 

0 Likes
Message 4 of 7

Anonymous
Not applicable
Accepted solution
Function ExposeSheetMetalThicknessParameterAsProperty(partDoc As PartDocument) As Boolean

    Dim oParameters As Parameters
    Set oParameters = partDoc.ComponentDefinition.Parameters
                      
    On Error Resume Next
    Dim oThicknessParam As Parameter
    Set oThicknessParam = oParameters.item("Thickness")
    
    If Err.Number = 0 Then
        With oThicknessParam
            .ExposedAsProperty = True
            .CustomPropertyFormat.PropertyType = CustomPropertyTypeEnum.kNumberPropertyType
            .CustomPropertyFormat.Units = UnitsTypeEnum.kMillimeterLengthUnits
            .CustomPropertyFormat.Precision = CustomPropertyPrecisionEnum.kOneDecimalPlacePrecision
            .CustomPropertyFormat.ShowUnitsString = True
        End With
        ExposeSheetMetalThicknessParameterAsProperty = True
        Exit Function
    End If
    ExposeSheetMetalThicknessParameterAsProperty = False
End Function

 

 

' Add an expression to the property.
       partDoc.PropertySets.item("Design Tracking Properties").item("Description").Expression = "=<Thickness> - <Sheet Metal Width> x <Sheet Metal Length>"
       'partDoc.PropertySets.item("Design Tracking Properties").item("Description").Expression = "=<Flat Pattern Width> x <Flat Pattern Length>"

Works as parametric.. in VBA. The only problem is precision.

 

0 Likes
Message 5 of 7

Anonymous
Not applicable
partDoc.UnitsOfMeasure.LengthDisplayPrecision = 1

This solves the precision issue..

 

0 Likes
Message 6 of 7

YuhanZhang
Autodesk
Autodesk
Accepted solution

Glad to see you solved it. Here is reference for those who want to know why:

 

http://help.autodesk.com/view/INVNTOR/2020/ENU/?guid=GUID-9ED64200-A0CA-4F27-A308-9BF7ADB22D06

 



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

Message 7 of 7

Anonymous
Not applicable

Thank you for informative article.

And we can control the precision of decimal values from;

Tools Ribbon > Options Panel > Document Settings > Units Tab > Linear Dim Display Precision value.

And also selecting the option Display precise value is aiding while sketch editing when you set 0. in Linear Dim Display Precision value. Creating a template file using these presettings will help me so much.

Thanks a lot.

0 Likes