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: 

Copy/paste properties from the 3D to the 2D ON SAVE

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
PLM-Sylvain.Bailly
475 Views, 7 Replies

Copy/paste properties from the 3D to the 2D ON SAVE

Hello,

 

1) I did the following script to copy and paste some properties of the 3D to the 2D but it doesn't work when I save the 2D. If I launch the macro manually it works but can you help me to have it automatically please.

 

Public Sub AutoSave_MigrateProperties()

    ' // Normal properties //
    ' The following properties must be migrated: "Title", "Description", "Company", "Project" and "Part Number"
    ' As these properties already exist in the source (3D) and the receiver (2D), we must associate them
    ' WARNING: The properties are contained in the item: "Item(number which indicate the part containing the desired property)"
    Dim drawDoc As DrawingDocument
    Set drawDoc = ThisApplication.ActiveDocument
    
    drawDoc.PropertySets.Item(1).Item("Title").Value = drawDoc.Sheets.Item(1).DrawingViews.Item(1).ReferencedDocumentDescriptor.ReferencedDocument.PropertySets.Item(1).Item("Title").Value
    drawDoc.PropertySets.Item(2).Item("Company").Value = drawDoc.Sheets.Item(1).DrawingViews.Item(1).ReferencedDocumentDescriptor.ReferencedDocument.PropertySets.Item(2).Item("Company").Value
    drawDoc.PropertySets.Item(3).Item("Description").Value = drawDoc.Sheets.Item(1).DrawingViews.Item(1).ReferencedDocumentDescriptor.ReferencedDocument.PropertySets.Item(3).Item("Description").Value
    drawDoc.PropertySets.Item(3).Item("Project").Value = drawDoc.Sheets.Item(1).DrawingViews.Item(1).ReferencedDocumentDescriptor.ReferencedDocument.PropertySets.Item(3).Item("Project").Value
    drawDoc.PropertySets.Item(3).Item("Part Number").Value = drawDoc.Sheets.Item(1).DrawingViews.Item(1).ReferencedDocumentDescriptor.ReferencedDocument.PropertySets.Item(3).Item("Part Number").Value
    
    
    ' // Custom properties //
    ' The following properties must be migrated: "Cat. level1" and "Cat. level2"
    ' For the custom propertiy, a test must be done to check if the property exists
    Dim invProp As Inventor.Property
    Dim strSourcePropVal As String
    
    On Error Resume Next
    For Each invProp In drawDoc.Sheets.Item(1).DrawingViews.Item(1).ReferencedDocumentDescriptor.ReferencedDocument.PropertySets.Item(4)
        drawDoc.PropertySets.Item(4).Item(invProp.Name).Value = invProp.Value
        If Err Then
            Err.Clear
            
            Call drawDoc.PropertySets.Item(4).Add(invProp.Value, invProp.Name)
        End If
    Next

End Sub

2) Once the point 1 is fixed, Is it possible to put the macro on all the 2D contained in Vault? 

 

3) I have heard that I can do a macro or an Add-in (dll) for this job. What is the best choice?

 

Thank you,

Sylvain 

7 REPLIES 7
Message 2 of 8

Hi @PLM-Sylvain.Bailly,

 

 

Just glancing about requirement. "Copying properties from a Part/Assembly(3D) to respective Drawing(2D) on saving Drawing". Correct me if I am wrong requirement.

 

There are 2 solutions for current situation.

 

1. Creating a Drawing template with iLogic. This iLogic should be triggered by "Event Triggers". For more details about Event triggers, refer the below video link.

https://www.youtube.com/watch?v=_hY2P93pr2Y

 

On creating every drawing document, this template must be used.

 

2. Creating Addin with help of Inventor Addin wizard. For more details about Addin, refer the following link.

 

http://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-52422162-1784-4E8F-B495-CDB7BE9987AB

 

In Addin, a OnSave event can be used to copying properties from 3D to 2D. The following API can be used to trigger event.

 

DocumentEvents.OnSave( BeforeOrAfter As EventTimingEnum, Context As NameValueMap, HandlingCode As HandlingCodeEnum )

 

Please feel free to contact if there is any queries.

 

If issue is solved, click on "Accept as solution" / give a "Kudo".

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 3 of 8

Hi,
I would prefer creating add ins.
Using vb.net has advantages regarding error handling etc.
I also have a code doing this.
I will take a look at it ASAP.
Ok?

Regards

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Message 4 of 8

Hi,

 

The add-in works correctly but we have created a .msi to help the designers for the installation and it is better for us to manage it.

 

If you want the code is the following one:

Private Sub m_appEvents_OnSaveDocument(
               ByVal drawDoc As Inventor._Document,
               ByVal BeforeOrAfter As Inventor.EventTimingEnum,
               ByVal Context As Inventor.NameValueMap,
               ByRef HandlingCode As Inventor.HandlingCodeEnum) _
                                  Handles m_appEvents.OnSaveDocument
            If BeforeOrAfter = EventTimingEnum.kBefore Then
                If drawDoc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
                    drawDoc.PropertySets.Item("Inventor Summary Information").Item("Title").Value = drawDoc.Sheets.Item(1).DrawingViews.Item(1).ReferencedDocumentDescriptor.ReferencedDocument.PropertySets.Item("Inventor Summary Information").Item("Title").Value
                    drawDoc.PropertySets.Item("Inventor Document Summary Information").Item("Company").Value = drawDoc.Sheets.Item(1).DrawingViews.Item(1).ReferencedDocumentDescriptor.ReferencedDocument.PropertySets.Item("Inventor Document Summary Information").Item("Company").Value
                    drawDoc.PropertySets.Item("Design Tracking Properties").Item("Description").Value = drawDoc.Sheets.Item(1).DrawingViews.Item(1).ReferencedDocumentDescriptor.ReferencedDocument.PropertySets.Item("Design Tracking Properties").Item("Description").Value
                    drawDoc.PropertySets.Item("Design Tracking Properties").Item("Project").Value = drawDoc.Sheets.Item(1).DrawingViews.Item(1).ReferencedDocumentDescriptor.ReferencedDocument.PropertySets.Item("Design Tracking Properties").Item("Project").Value
                    drawDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value = drawDoc.Sheets.Item(1).DrawingViews.Item(1).ReferencedDocumentDescriptor.ReferencedDocument.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value

                   
                    Dim invProp As Inventor.Property
                    Dim strSourcePropVal As String

                    On Error Resume Next
                    For Each invProp In drawDoc.Sheets.Item(1).DrawingViews.Item(1).ReferencedDocumentDescriptor.ReferencedDocument.PropertySets.Item("Inventor User Defined Properties")
                        drawDoc.PropertySets.Item("Inventor User Defined Properties").Item(invProp.Name).Value = invProp.Value
                        If (Err.Number > 0) Then
                            Err.Clear()

                            Call drawDoc.PropertySets.Item("Inventor User Defined Properties").Add(invProp.Value, invProp.Name)
                        End If
                    Next
                End If
            End If
        End Sub
Message 5 of 8

Hi,

 

This is also what I am doing similar.

But what events are you using in your coding?

Are you using the Documentevents or Applicationevents to trigger the save event?

 

I am using the applicationevents due to some errors in the documentevents.

 

I do not understand what is going wrong then with your coding.

 

Regards,

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Message 6 of 8

I m using this:

' Inventor application object.
        Private m_inventorApplication As Inventor.Application
        Private WithEvents m_appEvents As Inventor.ApplicationEvents

Everything works correctly for me now. Why are you saying that something is going wrong?

Message 7 of 8

Hi,

 

You wrote:

1) I did the following script to copy and paste some properties of the 3D to the 2D but it doesn't work when I save the 2D. If I launch the macro manually it works but can you help me to have it automatically please.

 

When it works I did misunderstand the question, sorry!

 

Regards,

 

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Message 8 of 8

Ah ok but Chandra has provided the answer that's why I have selected his post as the answer.

Thank you for your concern

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

Post to forums  

Autodesk Design & Make Report