I am looking for examples (VBA or C#) of code to copy all or specific iProperties from a model to the iProperties of the drawing the model is placed in. Ideally automatic when a model is (first) placed on the sheet, so without a button. The user should not have to do anything in this process.
Solved! Go to Solution.
I am looking for examples (VBA or C#) of code to copy all or specific iProperties from a model to the iProperties of the drawing the model is placed in. Ideally automatic when a model is (first) placed on the sheet, so without a button. The user should not have to do anything in this process.
Solved! Go to Solution.
Solved by bradeneuropeArthur. Go to Solution.
Solved by bradeneuropeArthur. Go to Solution.
As far as the task of copying properties from the model document to the drawing, there are multiple ways to do this, depending on the exact situation. Here is a link to one of my contribution posts which contains an example of one way to do it (using iLogic, but can very easily be converted for VBA). That example is specifically for 'custom' properties, but the process would be basically the same for copying all iProperties over, just with a bit more code to cover the other property sets.
As for it triggering by you placing the first drawing view onto the drawing, that part is quite a bit more tricky, and would likely require creating a custom 'event handler'. I have created some other custom event handlers before, but I don't think I've created one for that specific event before, yet. Sounds doable though.
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Wesley Crihfield
(Not an Autodesk Employee)
As far as the task of copying properties from the model document to the drawing, there are multiple ways to do this, depending on the exact situation. Here is a link to one of my contribution posts which contains an example of one way to do it (using iLogic, but can very easily be converted for VBA). That example is specifically for 'custom' properties, but the process would be basically the same for copying all iProperties over, just with a bit more code to cover the other property sets.
As for it triggering by you placing the first drawing view onto the drawing, that part is quite a bit more tricky, and would likely require creating a custom 'event handler'. I have created some other custom event handlers before, but I don't think I've created one for that specific event before, yet. Sounds doable though.
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Wesley Crihfield
(Not an Autodesk Employee)
There is a command in Inventor that will do that.
Go to the document settings of the drawing, there you can select the properties that you want to copy from the model to the drawing.
No coding needed.
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 !
There is a command in Inventor that will do that.
Go to the document settings of the drawing, there you can select the properties that you want to copy from the model to the drawing.
No coding needed.
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 !
That's a step in the right direction, but I still need some coding. It needs to be automated in some way so that users don't have to do anything (initial copying, updating properties if changed in the model etc.). Any ideas, examples?
That's a step in the right direction, but I still need some coding. It needs to be automated in some way so that users don't have to do anything (initial copying, updating properties if changed in the model etc.). Any ideas, examples?
Dim CmdMan As ControlDefinition
Set CmdMan = ThisApplication.CommandManager.ControlDefinitions.Item("UpdateCopiedModeliPropertiesCmd")
CmdMan.Execute
CmdMan.Execute2 (True)
for i logic
Dim CmdMan As ControlDefinition
CmdMan = ThisApplication.CommandManager.ControlDefinitions.Item("UpdateCopiedModeliPropertiesCmd")
CmdMan.Execute
CmdMan.Execute2 (True)
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 !
Dim CmdMan As ControlDefinition
Set CmdMan = ThisApplication.CommandManager.ControlDefinitions.Item("UpdateCopiedModeliPropertiesCmd")
CmdMan.Execute
CmdMan.Execute2 (True)
for i logic
Dim CmdMan As ControlDefinition
CmdMan = ThisApplication.CommandManager.ControlDefinitions.Item("UpdateCopiedModeliPropertiesCmd")
CmdMan.Execute
CmdMan.Execute2 (True)
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 !
For some reason I was thinking you were looking for a way to copy 'all' (including any 'custom') iProperties over to your drawing from the model when you place the first view. But since that's not the case, I'll just inform you of the simple, no code needed way I dealt with this situation years ago. I simply chose which properties I wanted to be copied over within the Document Settings > Drawing tab of the Drawing Template file, without specifying any target model document, then saved it. After that, all new drawings have simply always copied those properties over from whatever model document is being represented in the first drawing view I place, without ever needing any code.
It wasn't until I started dealing heavily in custom iProperties, that I started to need an iLogic solution. Since custom iProperties aren't going to be listed in that list, until after you have placed a model view in the drawing, and I didn't want to include any iLogic rules in my Template (in favor of an external rule), I then developed a rule that only looked for any 'custom' properties there may be within the model, and copied them over. This solved the whole issue of dealing with possible 'custom' properties.
Wesley Crihfield
(Not an Autodesk Employee)
For some reason I was thinking you were looking for a way to copy 'all' (including any 'custom') iProperties over to your drawing from the model when you place the first view. But since that's not the case, I'll just inform you of the simple, no code needed way I dealt with this situation years ago. I simply chose which properties I wanted to be copied over within the Document Settings > Drawing tab of the Drawing Template file, without specifying any target model document, then saved it. After that, all new drawings have simply always copied those properties over from whatever model document is being represented in the first drawing view I place, without ever needing any code.
It wasn't until I started dealing heavily in custom iProperties, that I started to need an iLogic solution. Since custom iProperties aren't going to be listed in that list, until after you have placed a model view in the drawing, and I didn't want to include any iLogic rules in my Template (in favor of an external rule), I then developed a rule that only looked for any 'custom' properties there may be within the model, and copied them over. This solved the whole issue of dealing with possible 'custom' properties.
Wesley Crihfield
(Not an Autodesk Employee)
I didn't know that was possible. But I am also facing custom properties, so I am still forced to use some form of code. But with the example provided above and activating this command prior to any save action of the drawing, the properties will always be in sync. I am going to incorporate it like this (probably) in my addin.
I didn't know that was possible. But I am also facing custom properties, so I am still forced to use some form of code. But with the example provided above and activating this command prior to any save action of the drawing, the properties will always be in sync. I am going to incorporate it like this (probably) in my addin.
So far I have it working with this:
private void onSaving(_Document DocumentObject, EventTimingEnum BeforeOrAfter, NameValueMap Context, out HandlingCodeEnum HandlingCode)
{
var colorScheme = string.Empty;
#region Before Save
if (BeforeOrAfter == EventTimingEnum.kBefore)
{
if (DocumentObject.DocumentType == DocumentTypeEnum.kDrawingDocumentObject)
{
ControlDefinition controlDefinition = Globals.invApp.CommandManager.ControlDefinitions["UpdateCopiedModeliPropertiesCmd"];
controlDefinition.Execute();
controlDefinition.Execute2(true);
}
}
}
The thing now is that it only copies with what is already checked in the document settings and it shows a messagebox if you want to overwrite the current iProperties. The first issue I can change, I think. The second one I don't know. Is it possible to disable the messagebox?
So far I have it working with this:
private void onSaving(_Document DocumentObject, EventTimingEnum BeforeOrAfter, NameValueMap Context, out HandlingCodeEnum HandlingCode)
{
var colorScheme = string.Empty;
#region Before Save
if (BeforeOrAfter == EventTimingEnum.kBefore)
{
if (DocumentObject.DocumentType == DocumentTypeEnum.kDrawingDocumentObject)
{
ControlDefinition controlDefinition = Globals.invApp.CommandManager.ControlDefinitions["UpdateCopiedModeliPropertiesCmd"];
controlDefinition.Execute();
controlDefinition.Execute2(true);
}
}
}
The thing now is that it only copies with what is already checked in the document settings and it shows a messagebox if you want to overwrite the current iProperties. The first issue I can change, I think. The second one I don't know. Is it possible to disable the messagebox?
There are ways to deal with unwanted 'notifications' and/or confirmation messages. One way is the application property called "SilentOperation". It is designed to bypass any usual prompting you may not want to deal with.
Another (slightly unrelated) tool is the "ScreenUpdating" property, which can be useful when you don't want the model screen to attempt to update until after you have done a bunch of changes, to reduce unnecessary resource consumption (slowness).
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Wesley Crihfield
(Not an Autodesk Employee)
There are ways to deal with unwanted 'notifications' and/or confirmation messages. One way is the application property called "SilentOperation". It is designed to bypass any usual prompting you may not want to deal with.
Another (slightly unrelated) tool is the "ScreenUpdating" property, which can be useful when you don't want the model screen to attempt to update until after you have done a bunch of changes, to reduce unnecessary resource consumption (slowness).
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Wesley Crihfield
(Not an Autodesk Employee)
Unfortunately this is not working:
ControlDefinition controlDefinition = Globals.invApp.CommandManager.ControlDefinitions["UpdateCopiedModeliPropertiesCmd"];
Globals.invApp.SilentOperation = true;
controlDefinition.Execute();
controlDefinition.Execute2(true);
Globals.invApp.SilentOperation = false;
Even if I use just one execute or execute2(false) will give the messagebox.
Unfortunately this is not working:
ControlDefinition controlDefinition = Globals.invApp.CommandManager.ControlDefinitions["UpdateCopiedModeliPropertiesCmd"];
Globals.invApp.SilentOperation = true;
controlDefinition.Execute();
controlDefinition.Execute2(true);
Globals.invApp.SilentOperation = false;
Even if I use just one execute or execute2(false) will give the messagebox.
Hmm... OK. Maybe we can use the old SendKeys trick to 'deal with' that prompt message, so it doesn't bother you.
The trick with using it is making sure that dialog is in focus when sent, and sending the right keys to it to simulate clicking the Yes button or using the Enter key, (or similar, whatever works for you).
In simple iLogic situations, this can usually be done using something like this:
ThisApplication.CommandManager.ControlDefinitions.Item("UpdateCopiedModeliPropertiesCmd").Execute2(False)
AppActivate(ThisApplication.Caption)
System.Windows.Forms.SendKeys.SendWait("y")
ThisApplication.UserInterfaceManager.DoEvents
, but I'm not sure how it would work from an Add-in. You could give it a try I guess.
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Wesley Crihfield
(Not an Autodesk Employee)
Hmm... OK. Maybe we can use the old SendKeys trick to 'deal with' that prompt message, so it doesn't bother you.
The trick with using it is making sure that dialog is in focus when sent, and sending the right keys to it to simulate clicking the Yes button or using the Enter key, (or similar, whatever works for you).
In simple iLogic situations, this can usually be done using something like this:
ThisApplication.CommandManager.ControlDefinitions.Item("UpdateCopiedModeliPropertiesCmd").Execute2(False)
AppActivate(ThisApplication.Caption)
System.Windows.Forms.SendKeys.SendWait("y")
ThisApplication.UserInterfaceManager.DoEvents
, but I'm not sure how it would work from an Add-in. You could give it a try I guess.
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Wesley Crihfield
(Not an Autodesk Employee)
Another way would be if I could acces the iProperties or attributes (I save the necessary properties in the iProperties for Vault but also as attributes) of the model from within the drawing. Is there a way to acces the model from within the drawing?
Another way would be if I could acces the iProperties or attributes (I save the necessary properties in the iProperties for Vault but also as attributes) of the model from within the drawing. Is there a way to acces the model from within the drawing?
I found the solution I was looking for:
DrawingDocument drawingDocument = (DrawingDocument)Globals.invApp.ActiveDocument;
DrawingView drawingView;
Document modelDocument;
foreach (Sheet sheet in drawingDocument.Sheets)
{
sheet.Activate();
drawingView = sheet.DrawingViews[1];
modelDocument = (Document)drawingView.ReferencedDocumentDescriptor.ReferencedDocument;
'read properties from modeldocument
'write properties to drawingDocument
}
I found the solution I was looking for:
DrawingDocument drawingDocument = (DrawingDocument)Globals.invApp.ActiveDocument;
DrawingView drawingView;
Document modelDocument;
foreach (Sheet sheet in drawingDocument.Sheets)
{
sheet.Activate();
drawingView = sheet.DrawingViews[1];
modelDocument = (Document)drawingView.ReferencedDocumentDescriptor.ReferencedDocument;
'read properties from modeldocument
'write properties to drawingDocument
}
I have created form where user can fill properties in single screen and linked it with drawing document.
Also, same properties value is updated in linked reference document either part document or Assembly document.
I have created form where user can fill properties in single screen and linked it with drawing document.
Also, same properties value is updated in linked reference document either part document or Assembly document.
Would love to see the rest of your VBA code that copies model iProperties and writes them to the drawing iProperties.
Would love to see the rest of your VBA code that copies model iProperties and writes them to the drawing iProperties.
Hi @pete.dehaan. Here is a link to a post I created a couple years ago which shows how to copy just the custom iProperties from a drawing's referenced model document to the drawing document. It contains 3 different code examples (2 iLogic rule codes, and 1 VBA macro code). Maybe this will help you accomplish your task. Lots of folks are moving away from using VBA with Inventor though, because of security risks, which is why Autodesk stopped including the VBA Editor in any new Inventor installations a couple years ago.
Copy All Custom iProperties From Model To Drawing
Wesley Crihfield
(Not an Autodesk Employee)
Hi @pete.dehaan. Here is a link to a post I created a couple years ago which shows how to copy just the custom iProperties from a drawing's referenced model document to the drawing document. It contains 3 different code examples (2 iLogic rule codes, and 1 VBA macro code). Maybe this will help you accomplish your task. Lots of folks are moving away from using VBA with Inventor though, because of security risks, which is why Autodesk stopped including the VBA Editor in any new Inventor installations a couple years ago.
Copy All Custom iProperties From Model To Drawing
Wesley Crihfield
(Not an Autodesk Employee)
Thanks for the reply, I am looking for the default iProperties such as "Stock Number" and "Cost Center" instead of custom iProperties.
I use iLogic for anything new, but re-writing an older VBA macro as iLogic isn't something I can do right now, assuming I can just patch what exists.
Thanks for the reply, I am looking for the default iProperties such as "Stock Number" and "Cost Center" instead of custom iProperties.
I use iLogic for anything new, but re-writing an older VBA macro as iLogic isn't something I can do right now, assuming I can just patch what exists.
My code is not in VBA, but C#. It is similar, but there are some differences.
What is your process? What is it that you're looking for. My code is pretty extensive, so it is not that easy to post it on here. Only snippets.
My code is not in VBA, but C#. It is similar, but there are some differences.
What is your process? What is it that you're looking for. My code is pretty extensive, so it is not that easy to post it on here. Only snippets.
Can't find what you're looking for? Ask the community or share your knowledge.