Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

how to give the good Parts name

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
hugo7
242 Views, 6 Replies

how to give the good Parts name

Hi i want that my rules generate the name off the parts automatically

 

heres my post my problem is at line 30 

6 REPLIES 6
Message 2 of 7
FINET_Laurent
in reply to: hugo7

Hello @hugo7,

 

How would the name be formated ? We can have any name you can think of. 

Also, please copy paste the code here so we can implement it for you.

 

Kind regards,

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

Message 3 of 7
hugo7
in reply to: hugo7

oDoc = ThisDoc.Document

  'check if the part is a sheet metal part
  If oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
                   
    oDoc = ThisApplication.ActiveDocument
    Dim oCompDef As SheetMetalComponentDefinition
    oCompDef = oDoc.ComponentDefinition
    
    If oCompDef.HasFlatPattern = False Then
        oCompDef.Unfold
    Else
        oCompDef.FlatPattern.Edit
    End If
                
    Dim sOut As String
    Dim oPath As String
                                
    oPath = ThisDoc.Path & "\DXF Flat & Step" 
	
                
    If Not System.IO.Directory.Exists(oPath) Then
        System.IO.Directory.CreateDirectory(oPath)
    End If
                
    Dim sFname As String
   
    sOut = "FLAT PATTERN DXF?AcadVersion=2004&RebaseGeometry=True&OuterProfileLayer=0&OuterProfileLayerColor=0;0;0&InteriorProfilesLayer=0&InteriorProfilesLayerColor=0;0;0;0;0;IV_OUTER_PROFILE;IV_INTERIOR_PROFILES;IV_FEATURE_PROFILES;IV_FEATURE_PROFILES_DOWN;IV_ALTREP_FRONT;IV_ALTREP_BACK;IV_ROLL_TANGENT;IV_ROLL&InvisibleLayers=IV_TANGENT;IV_TOOL_CENTER;IV_TOOL_CENTER_DOWN;IV_ARC_CENTERS;IV_UNCONSUMED_SKETCHES;IV_BEND;IV_BEND_DOWN"
               
    sFname = oPath & "test"& ".dxf"
    oCompDef.DataIO.WriteDataToFile(sOut, sFname)
	
    'MessageBox.Show("Your file was saved in the following dirctory: " + sFname)
  Else
    'MessageBox.Show("Only sheet metal parts can be exported as DXF. Nice Try! :-)")
  End If
Message 4 of 7
sebastien_forman
in reply to: hugo7

hello, try that

oDoc = ThisDoc.Document

' Check if the part is a sheet metal part
If oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
    oDoc = ThisApplication.ActiveDocument
    Dim oCompDef As SheetMetalComponentDefinition
    oCompDef = oDoc.ComponentDefinition
    
    ' Check if the part has a flat pattern
    If Not oCompDef.HasFlatPattern Then
        oCompDef.Unfold
    Else
        oCompDef.FlatPattern.Edit
    End If
                
    Dim oPath As String
    oPath = ThisDoc.Path & "\DXF Flat & Step"
                
    ' Check if the output directory exists, if not, create it
    If Not System.IO.Directory.Exists(oPath) Then
        System.IO.Directory.CreateDirectory(oPath)
    End If
                
    Dim sFname As String
    sFname = oPath & "\"&ThisDoc.FileName &"_flat.dxf" ' Correctly formatted DXF file path
    
    ' Define parameters for DXF export
    Dim sOut As String
    sOut = "FLAT PATTERN DXF?AcadVersion=2004&RebaseGeometry=True&OuterProfileLayer=0&OuterProfileLayerColor=0;0;0&InteriorProfilesLayer=0&InteriorProfilesLayerColor=0;0;0;0;0;IV_OUTER_PROFILE;IV_INTERIOR_PROFILES;IV_FEATURE_PROFILES;IV_FEATURE_PROFILES_DOWN;IV_ALTREP_FRONT;IV_ALTREP_BACK;IV_ROLL_TANGENT;IV_ROLL&InvisibleLayers=IV_TANGENT;IV_TOOL_CENTER;IV_TOOL_CENTER_DOWN;IV_ARC_CENTERS;IV_UNCONSUMED_SKETCHES;IV_BEND;IV_BEND_DOWN"
               
    ' Export the sheet metal part as a DXF file
    oCompDef.DataIO.WriteDataToFile(sOut, sFname)
Else
    ' Display a message if the part is not a sheet metal part
    MessageBox.Show("Only sheet metal parts can be exported as DXF.")
End If
Message 5 of 7
hugo7
in reply to: hugo7

Thank that works fine

 

now can you make this rule to save at the same doc ?

i need to generate a dxf and a .step or combine the 2 rules if its possible ?

 

' Get the STEP translator Add-In.
Dim oSTEPTranslator As TranslatorAddIn
oSTEPTranslator = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")
Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap

If oSTEPTranslator.HasSaveCopyAsOptions(ThisApplication.ActiveDocument, oContext, oOptions) Then
    ' Set application protocol.
    ' 2 = AP 203 - Configuration Controlled Design
    ' 3 = AP 214 - Automotive Design
    oOptions.Value("ApplicationProtocolType") = 3
    ' Other options...
    'oOptions.Value("Author") = ""
    'oOptions.Value("Authorization") = ""
    'oOptions.Value("Description") = ""
    'oOptions.Value("Organization") = ""
    oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
    Dim oData As DataMedium
    oData = ThisApplication.TransientObjects.CreateDataMedium
    oData.FileName = ThisDoc.PathAndFileName(False) & ".stp"
oSTEPTranslator.SaveCopyAs(ThisApplication.ActiveDocument, oContext, oOptions, oData)
End If

 

 

Message 6 of 7
sebastien_forman
in reply to: hugo7

try that 😉

Sub main()
    ' Get the active document
    oDoc = ThisDoc.Document

    ' Check if the part is a sheet metal part
    If oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
        ' Set the active document as the current document
        oDoc = ThisApplication.ActiveDocument
        Dim oCompDef As SheetMetalComponentDefinition
        oCompDef = oDoc.ComponentDefinition
        
        ' Check if the part has a flat pattern
        If Not oCompDef.HasFlatPattern Then
            oCompDef.Unfold
        Else
            oCompDef.FlatPattern.Edit
        End If
                    
        ' Define the output directory path
        Dim oPath As String
        oPath = ThisDoc.Path & "\DXF Flat & Step"
                    
        ' Check if the output directory exists, if not, create it
        If Not System.IO.Directory.Exists(oPath) Then
            System.IO.Directory.CreateDirectory(oPath)
        End If
                    
        ' Define the DXF file name and path
        Dim sFname As String
        sFname = oPath & "\"&ThisDoc.FileName &"_flat.dxf" ' Correctly formatted DXF file path
        
        ' Define parameters for DXF export
        Dim sOut As String
        sOut = "FLAT PATTERN DXF?AcadVersion=2004&RebaseGeometry=True&OuterProfileLayer=0&OuterProfileLayerColor=0;0;0&InteriorProfilesLayer=0&InteriorProfilesLayerColor=0;0;0;0;0;IV_OUTER_PROFILE;IV_INTERIOR_PROFILES;IV_FEATURE_PROFILES;IV_FEATURE_PROFILES_DOWN;IV_ALTREP_FRONT;IV_ALTREP_BACK;IV_ROLL_TANGENT;IV_ROLL&InvisibleLayers=IV_TANGENT;IV_TOOL_CENTER;IV_TOOL_CENTER_DOWN;IV_ARC_CENTERS;IV_UNCONSUMED_SKETCHES;IV_BEND;IV_BEND_DOWN"
                   
        ' Export the sheet metal part as a DXF file
        oCompDef.DataIO.WriteDataToFile(sOut, sFname)
        
        ' Export STEP
        ExportStep(oPath, ThisDoc.FileName)
        
    Else
        ' Display a message if the part is not a sheet metal part
        MessageBox.Show("Only sheet metal parts can be exported as DXF.")
    End If
End Sub

Function ExportStep(ByVal oPath As String, ByVal fileName As String)
    ' Get the STEP translator Add-In
    Dim oSTEPTranslator As TranslatorAddIn
    oSTEPTranslator = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")
    Dim oContext As TranslationContext
    oContext = ThisApplication.TransientObjects.CreateTranslationContext
    Dim oOptions As NameValueMap
    oOptions = ThisApplication.TransientObjects.CreateNameValueMap

    ' Set the STEP file folder
    oFolder = oPath

    ' Check for the STEP folder and create it if it does not exist
    If Not System.IO.Directory.Exists(oFolder) Then
        System.IO.Directory.CreateDirectory(oFolder)
    End If

    ' Check if the translator has save copy options
    If oSTEPTranslator.HasSaveCopyAsOptions(ThisDoc.Document, oContext, oOptions) Then
        ' Set application protocol
        oOptions.Value("ApplicationProtocolType") = 3 ' 3 = AP 214 - Automotive Design
        
        ' Set the context type
        oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
        
        ' Create a data medium
        Dim oData As DataMedium
        oData = ThisApplication.TransientObjects.CreateDataMedium
        
        ' Set the STEP file name and path
        oData.FileName = oFolder & "\" & fileName & "-flat.stp"
        
        ' Save the part as a STEP file
        oSTEPTranslator.SaveCopyAs(ThisDoc.Document, oContext, oOptions, oData)
    End If
End Function
Message 7 of 7
hugo7
in reply to: hugo7

thank you very helpfull

 

have a good one !

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report