How to define A-Side for sheet metal parts using VBA

How to define A-Side for sheet metal parts using VBA

3DAli
Collaborator Collaborator
1,203 Views
3 Replies
Message 1 of 4

How to define A-Side for sheet metal parts using VBA

3DAli
Collaborator
Collaborator

Hello,

 

I am trying to define an A-Side for my sheet metal part using VBA and it fails

 

Dim oPartDoc As PartDocument
Set oPartDoc = ThisApplication.ActiveDocument
                            
Dim oDef As PartComponentDefinition
Set oDef = oPartDoc.ComponentDefinition

'Change Document.SubType to Sheetmetal
oPartDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"
                         
Dim cd As SheetMetalComponentDefinition

Set cd = oPartDoc.ComponentDefinition
cd.UseSheetMetalStyleThickness = False
cd.Thickness.Value = 0.5

'---Find the biggest face
  Dim f As Face
  Dim bf As Face
  Dim area As Double
  For Each f In oDef.SurfaceBodies(1).Faces
    ' Only care about planar faces
    If TypeOf f.Geometry Is Plane And f.Evaluator.area > area Then
      Set bf = f
      area = f.Evaluator.area
    End If
  Next
'--- Change the color of the biggest face  
    Dim oRenderStyle As RenderStyle
    Set oRenderStyle = oPartDoc.RenderStyles.Item("Yellow")
    
    Call bf.SetRenderStyle(StyleSourceTypeEnum.kOverrideRenderStyle, oRenderStyle)
    oPartDoc.Rebuild2 (True)
    
'---Define A-Side    
    
    Call cd.ASideDefinitions.Add(bf) '<----- Fails here)
    Debug.Print cd.ASideDefinitions.Count
    
    If cd.HasFlatPattern = False Then
        cd.Unfold
    End If
    cd.FlatPattern.ExitEdit

 

it first return this error message and when you cancel it ;

 

3DAli_0-1639681264518.png

 

it shows this error

 

3DAli_1-1639681284449.png

 

any idea on how to get this to work? the part has no existing flat pattern, even if you first create the flat pattern ad then try to define an A-Side still fails the same way as shown here.

 

any help is greatly appreciated .

Best,

Ali 

 

0 Likes
Accepted solutions (1)
1,204 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor

Is the part always a regular part when the code starts, or is it always already a sheet metal part, or is it sometimes a regular part, and sometimes a sheet metal part when the code starts.  I'm asking because it looks like you are trying to convert a regular part into a sheet metal?  Also, if it were already a sheet metal part, and it already had a flat pattern, you would no longer be able to define an A-Side.  You would have to delete the existing FlatPattern before you could define a new A-Side.  Also, what version of Inventor are you using, because I do not see references to the 'RenderStyle' object or the 'PartDocument.RenderStyles' property, or the 'Face.SetRenderStyle' method shown or listed in my Inventor 2022 or the 2022 online help area.  I believe those were being used before 2013, then they switched to using an Asset object for 'Appearance', and I believe they may still be functional, just hidden now (link to that reference).

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 4

3DAli
Collaborator
Collaborator

Hi

just to confirm, the part is always a regular part and converted into Sheetmetal with no existing flat pattern. I use IV2022 and yes those are still functional and i works fine no issues.

 

Thanks

0 Likes
Message 4 of 4

3DAli
Collaborator
Collaborator
Accepted solution

I managed to make it work by selecting the face in the same sub instead of passing it through i/o variable.

0 Likes