Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Add Custom Properties Sheet metal extends - Assembly contex

CCarreiras
Mentor

Add Custom Properties Sheet metal extends - Assembly contex

CCarreiras
Mentor
Mentor

Hi!

 

I'm trying to create two custom properties (Flat Pattern Extends: With and Length) in sheet metal parts within main assembly.

I tried another code, but it's only create the properties in the main assembly, not in the parts.

 

Now, I'm trying this code below, but it's not working yet.

 

Any help?

Thanks.

 

SyntaxEditor Code Snippet

Dim openDoc As Document
openDoc = ThisApplication.activedocument
Dim docFile As Document
'Is Assembly?
If openDoc.DocumentType = 12291 Then

    For Each docFile In openDoc.AllReferencedDocuments
        'Is Sheet Metal File? (assuming it has FP already)
        If docFile.SubType.Equals("{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}") Then
    
                'if yes, Assuming it has a Flat Pattern deffined
            Dim smComp As SheetMetalComponentDefinition 
            smComp = docFile.ComponentDefinition
            
            If smComp.HasFlatPattern = True Then
                    
                    'CREATE With and Length as user properties (NOT WORKING)
                        Dim Prop_Length As String
                        Dim Prop_With As String
                        
                        oCustomPropertySet = ThisDoc.Document.PropertySets.Item _
                    ("Inventor User Defined Properties")
                        
                        oCustomPropertySet.Add("Custom", Prop_Length)
                        oCustomPropertySet.Add("Custom", Prop_With)
                            
                    'Adds Flat Pattern extends (Length and With) as a custom propertie (ready to use in a Part List Column) (NOT WORKING)
                        docFile.oCustomPropertySet.Item("Design Tracking Properties").Item("Custom", "Length").Value = "=<Sheet Metal Length>"
                        docFile.oCustomPropertySet.Item("Design Tracking Properties").Item("Custom", "Width").Value = "=<Sheet Metal Width>"
                    'THIS LINE IS TO ABLE THE Thickness PARAMETER TO GET READY TO EXPORT IN EACH SHEET METAL PART    (WORKING)            
                        docFile.ComponentDefinition.Parameters("Thickness").ExposedAsProperty = True 
                    
            Else    
                MessageBox.Show("No Flat Pattern Info ", "INFO!",MessageBoxButtons.OK,MessageBoxIcon.Exclamation)        
            End If    
        Else
            MessageBox.Show("Not a SM Part", "INFO!",MessageBoxButtons.OK,MessageBoxIcon.Exclamation)
        End If
    Next

Else
MessageBox.Show("This is not an Assembly", "File Type Mismatch!",MessageBoxButtons.OK,MessageBoxIcon.Exclamation)
End If

 

 

CCarreiras

EESignature

0 Likes
Reply
Accepted solutions (1)
643 Views
2 Replies
Replies (2)

MechMachineMan
Advisor
Advisor
Accepted solution
See my notes below.
@CCarreiras wrote:

Hi!

 

I'm trying to create two custom properties (Flat Pattern Extends: With and Length) in sheet metal parts within main assembly.

I tried another code, but it's only create the properties in the main assembly, not in the parts.

 

Now, I'm trying this code below, but it's not working yet.

 

Any help?

Thanks.

 

SyntaxEditor Code Snippet

Dim openDoc As Document
openDoc = ThisApplication.activedocument
Dim docFile As Document
'Is Assembly?
If openDoc.DocumentType = 12291 Then

    For Each docFile In openDoc.AllReferencedDocuments
        'Is Sheet Metal File? (assuming it has FP already)
        If docFile.SubType.Equals("{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}") Then
    
                'if yes, Assuming it has a Flat Pattern deffined
            Dim smComp As SheetMetalComponentDefinition 
            smComp = docFile.ComponentDefinition
            
            If smComp.HasFlatPattern = True Then
                    
                    'CREATE With and Length as user properties (NOT WORKING)
                        Dim Prop_Length As String
                        Dim Prop_With As String
                        
'ThisDoc.Document is accessing the active assembly document rather than iterating through docFile with you.
'The fix: replace ThisDoc.Document in this case with docFile oCustomPropertySet = ThisDoc.Document.PropertySets.Item _ ("Inventor User Defined Properties") oCustomPropertySet.Add("Custom", Prop_Length) oCustomPropertySet.Add("Custom", Prop_With)
' oCustomPropertySet is already a fully defined object (as you have worked your way down to it with the previous call we fixed.
'The fix: just delete docFile. from this line. 'Adds Flat Pattern extends (Length and With) as a custom propertie (ready to use in a Part List Column) (NOT WORKING) docFile.oCustomPropertySet.Item("Design Tracking Properties").Item("Custom", "Length").Value = "=<Sheet Metal Length>" docFile.oCustomPropertySet.Item("Design Tracking Properties").Item("Custom", "Width").Value = "=<Sheet Metal Width>" 'THIS LINE IS TO ABLE THE Thickness PARAMETER TO GET READY TO EXPORT IN EACH SHEET METAL PART (WORKING) docFile.ComponentDefinition.Parameters("Thickness").ExposedAsProperty = True Else MessageBox.Show("No Flat Pattern Info ", "INFO!",MessageBoxButtons.OK,MessageBoxIcon.Exclamation) End If Else MessageBox.Show("Not a SM Part", "INFO!",MessageBoxButtons.OK,MessageBoxIcon.Exclamation) End If Next Else MessageBox.Show("This is not an Assembly", "File Type Mismatch!",MessageBoxButtons.OK,MessageBoxIcon.Exclamation) End If

 

 


 


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes

CCarreiras
Mentor
Mentor

@MechMachineMan Thank you for your precious notes, very helpful.

 

Some changes and now it works.

CCarreiras

EESignature

0 Likes