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 iProperties from model to drawing

17 REPLIES 17
SOLVED
Reply
Message 1 of 18
gert-leonvanlier
3232 Views, 17 Replies

Copy iProperties from model to drawing

gert-leonvanlier
Collaborator
Collaborator

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.

0 Likes

Copy iProperties from model to drawing

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.

Labels (4)
17 REPLIES 17
Message 2 of 18

WCrihfield
Mentor
Mentor

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

EESignature

(Not an Autodesk Employee)

0 Likes

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

EESignature

(Not an Autodesk Employee)

Message 3 of 18

bradeneuropeArthur
Mentor
Mentor
Accepted solution

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 !

Message 4 of 18

gert-leonvanlier
Collaborator
Collaborator

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?

0 Likes

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?

Message 5 of 18

bradeneuropeArthur
Mentor
Mentor
Accepted solution
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 !

Message 6 of 18

WCrihfield
Mentor
Mentor

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

EESignature

(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

EESignature

(Not an Autodesk Employee)

Message 7 of 18

gert-leonvanlier
Collaborator
Collaborator

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.

0 Likes

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.

Message 8 of 18

gert-leonvanlier
Collaborator
Collaborator

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?

 

Inventor_2eGMiCwgHN.png

 

0 Likes

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?

 

Inventor_2eGMiCwgHN.png

 

Message 9 of 18

WCrihfield
Mentor
Mentor

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

EESignature

(Not an Autodesk Employee)

0 Likes

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

EESignature

(Not an Autodesk Employee)

Message 10 of 18

gert-leonvanlier
Collaborator
Collaborator

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.

0 Likes

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.

Message 11 of 18

WCrihfield
Mentor
Mentor

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

EESignature

(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

EESignature

(Not an Autodesk Employee)

Message 12 of 18

gert-leonvanlier
Collaborator
Collaborator

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?

0 Likes

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?

Message 13 of 18

gert-leonvanlier
Collaborator
Collaborator

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
}

 

 

0 Likes

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
}

 

 

Message 14 of 18

jatin.devaiya
Explorer
Explorer

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.

 

23E9BFC8-4B70-4456-801D-5415CDFD7776.jpeg

0 Likes

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.

 

23E9BFC8-4B70-4456-801D-5415CDFD7776.jpeg

Message 15 of 18

pete.dehaan
Participant
Participant

Would love to see the rest of your VBA code that copies model iProperties and writes them to the drawing iProperties.

0 Likes

Would love to see the rest of your VBA code that copies model iProperties and writes them to the drawing iProperties.

Message 16 of 18
WCrihfield
in reply to: pete.dehaan

WCrihfield
Mentor
Mentor

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

EESignature

(Not an Autodesk Employee)

0 Likes

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

EESignature

(Not an Autodesk Employee)

Message 17 of 18

pete.dehaan
Participant
Participant

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.

0 Likes

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.

Message 18 of 18

gert-leonvanlier
Collaborator
Collaborator

@pete.dehaan 

 

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.

0 Likes

@pete.dehaan 

 

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.

Post to forums  

Autodesk Design & Make Report